2015-11-23 22:28:57 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface MWPreviewElement class.
|
|
|
|
*
|
2023-12-01 16:06:11 +00:00
|
|
|
* @copyright See AUTHORS.txt
|
2015-11-23 22:28:57 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an ve.ui.MWPreviewElement object.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.ui.PreviewElement
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {ve.dm.Node} [model]
|
|
|
|
* @param {Object} [config]
|
2021-09-11 08:05:31 +00:00
|
|
|
* @cfg {boolean} [useView=false] Use the view HTML, and don't bother generating model HTML, which
|
|
|
|
* is a bit slower
|
2015-11-23 22:28:57 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWPreviewElement = function VeUiMwPreviewElement() {
|
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWPreviewElement.super.apply( this, arguments );
|
|
|
|
|
|
|
|
// Initialize
|
2017-11-10 14:59:01 +00:00
|
|
|
this.$element.addClass( 've-ui-mwPreviewElement mw-body-content mw-parser-output' );
|
2015-11-23 22:28:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWPreviewElement, ve.ui.PreviewElement );
|
2017-03-24 18:52:12 +00:00
|
|
|
|
|
|
|
/* Method */
|
|
|
|
|
2023-02-28 18:56:38 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWPreviewElement.prototype.beforeAppend = function ( element ) {
|
|
|
|
// Parent method
|
|
|
|
ve.ui.MWPreviewElement.super.prototype.beforeAppend.apply( this, arguments );
|
|
|
|
|
|
|
|
// Remove any TemplateStyles stylesheets already present on the page, to avoid
|
|
|
|
// very slow repaints (T330781)
|
2024-04-30 16:44:25 +00:00
|
|
|
Array.prototype.forEach.call( element.querySelectorAll( 'style[data-mw-deduplicate]' ), ( style ) => {
|
2024-05-21 14:22:56 +00:00
|
|
|
const key = style.getAttribute( 'data-mw-deduplicate' );
|
2023-02-28 18:56:38 +00:00
|
|
|
|
2024-05-21 14:22:56 +00:00
|
|
|
const duplicate = element.querySelector( 'style[data-mw-deduplicate="' + key + '"]' );
|
2023-02-28 18:56:38 +00:00
|
|
|
if ( duplicate ) {
|
|
|
|
style.parentNode.removeChild( style );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2018-05-11 13:50:58 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWPreviewElement.prototype.setModel = function ( model ) {
|
|
|
|
// Parent method
|
|
|
|
ve.ui.MWPreviewElement.super.prototype.setModel.call( this, model );
|
|
|
|
|
2020-04-09 13:33:54 +00:00
|
|
|
// The following classes are used here:
|
|
|
|
// * mw-content-ltr
|
|
|
|
// * mw-content-rtl
|
2018-05-11 13:50:58 +00:00
|
|
|
this.$element.addClass( 'mw-content-' + this.model.getDocument().getDir() );
|
|
|
|
};
|
|
|
|
|
2017-03-24 18:52:12 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWPreviewElement.prototype.replaceWithModelDom = function () {
|
|
|
|
// Parent method
|
|
|
|
ve.ui.MWPreviewElement.super.prototype.replaceWithModelDom.apply( this, arguments );
|
|
|
|
|
2017-03-30 16:37:54 +00:00
|
|
|
ve.init.platform.linkCache.styleParsoidElements(
|
|
|
|
this.$element,
|
|
|
|
// The DM node should be attached, but check just in case.
|
|
|
|
this.model.getDocument() && this.model.getDocument().getHtmlDocument()
|
|
|
|
);
|
2017-03-24 18:52:12 +00:00
|
|
|
};
|