Debian Codegraph @

extensions/VisualEditor/modules/ve-mw/ce/nodes/ve.ce.MWEntityNode.js

raw symbols SCIP
1 /*!
2 * VisualEditor ContentEditable MWEntityNode class.
3 *
4 * @copyright See AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
6 */
7
8 /**
9 * ContentEditable MediaWiki entity node.
10 *
11 * @class
12 * @extends ve.ce.LeafNode
13 * @constructor
14 * @param {ve.dm.MWEntityNode} model Model to observe
15 * @param {Object} [config] Configuration options
16 */
17 ve.ce.MWEntityNode = function VeCeMWEntityNode() {
18 // Parent constructor
19 ve.ce.MWEntityNode.super.apply( this, arguments );
20
21 // DOM changes
22 this.$element.addClass( 've-ce-mwEntityNode' );
23 // Need CE=false to prevent selection issues
24 this.$element.prop( 'contentEditable', 'false' );
25
26 // Events
27 this.model.connect( this, { update: 'onUpdate' } );
28
29 // Initialization
30 this.onUpdate();
31 };
32
33 /* Inheritance */
34
35 OO.inheritClass( ve.ce.MWEntityNode, ve.ce.LeafNode );
36
37 /* Static Properties */
38
39 ve.ce.MWEntityNode.static.name = 'mwEntity';
40
41 /* Methods */
42
43 /**
44 * Handle model update events.
45 */
46 ve.ce.MWEntityNode.prototype.onUpdate = function () {
47 const whitespaceHtmlChars = ve.visibleWhitespaceCharacters,
48 significantWhitespace = this.getModel().getParent().hasSignificantWhitespace();
49
50 let chr = this.model.getAttribute( 'character' );
51 if ( chr === '\u00a0' ) {
52 //   non-breaking space
53 this.$element
54 .addClass( 've-ce-mwEntityNode-nbsp' )
55 .attr( 'title', mw.msg( 'visualeditor-tooltip-non-breaking-space' ) );
56 } else {
57 this.$element
58 .removeClass( 've-ce-mwEntityNode-nbsp' )
59 .removeAttr( 'title' );
60 }
61
62 if ( !significantWhitespace && Object.prototype.hasOwnProperty.call( whitespaceHtmlChars, chr ) ) {
63 chr = whitespaceHtmlChars[ chr ];
64 }
65
66 this.$element.text( chr );
67 };
68
69 /* Registration */
70
71 ve.ce.nodeFactory.register( ve.ce.MWEntityNode );