Debian Codegraph @

extensions/VisualEditor/modules/ve-mw/ui/elements/ve.ui.MWPreviewElement.js

raw symbols SCIP
1 /*!
2 * VisualEditor UserInterface MWPreviewElement class.
3 *
4 * @copyright See AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
6 */
7
8 /**
9 * Creates an ve.ui.MWPreviewElement object.
10 *
11 * @class
12 * @extends ve.ui.PreviewElement
13 *
14 * @constructor
15 * @param {ve.dm.Node} [model]
16 * @param {Object} [config]
17 * @param {boolean} [config.useView=false] Use the view HTML, and don't bother generating model HTML, which
18 * is a bit slower
19 */
20 ve.ui.MWPreviewElement = function VeUiMwPreviewElement() {
21 // Parent constructor
22 ve.ui.MWPreviewElement.super.apply( this, arguments );
23
24 // Initialize
25 this.$element.addClass( 've-ui-mwPreviewElement mw-body-content mw-parser-output' );
26 };
27
28 /* Inheritance */
29
30 OO.inheritClass( ve.ui.MWPreviewElement, ve.ui.PreviewElement );
31
32 /* Method */
33
34 /**
35 * @inheritdoc
36 */
37 ve.ui.MWPreviewElement.prototype.beforeAppend = function ( element ) {
38 // Parent method
39 ve.ui.MWPreviewElement.super.prototype.beforeAppend.apply( this, arguments );
40
41 // Remove any TemplateStyles stylesheets already present on the page, to avoid
42 // very slow repaints (T330781)
43 Array.prototype.forEach.call( element.querySelectorAll( 'style[data-mw-deduplicate]' ), ( style ) => {
44 const key = style.getAttribute( 'data-mw-deduplicate' );
45
46 const duplicate = element.querySelector( 'style[data-mw-deduplicate="' + key + '"]' );
47 if ( duplicate ) {
48 style.parentNode.removeChild( style );
49 }
50 } );
51 };
52
53 /**
54 * @inheritdoc
55 */
56 ve.ui.MWPreviewElement.prototype.setModel = function ( model ) {
57 // Parent method
58 ve.ui.MWPreviewElement.super.prototype.setModel.call( this, model );
59
60 // The following classes are used here:
61 // * mw-content-ltr
62 // * mw-content-rtl
63 this.$element.addClass( 'mw-content-' + this.model.getDocument().getDir() );
64 };
65
66 /**
67 * @inheritdoc
68 */
69 ve.ui.MWPreviewElement.prototype.replaceWithModelDom = function () {
70 // Parent method
71 ve.ui.MWPreviewElement.super.prototype.replaceWithModelDom.apply( this, arguments );
72
73 ve.init.platform.linkCache.styleParsoidElements(
74 this.$element,
75 // The DM node should be attached, but check just in case.
76 this.model.getDocument() && this.model.getDocument().getHtmlDocument()
77 );
78 };