Debian Codegraph @

extensions/VisualEditor/lib/ve/src/ce/nodes/ve.ce.CommentNode.js

raw symbols SCIP
1 /*!
2 * VisualEditor ContentEditable CommentNode class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * ContentEditable comment node.
9 *
10 * @class
11 * @extends ve.ce.LeafNode
12 * @mixes ve.ce.FocusableNode
13 *
14 * @constructor
15 * @param {ve.dm.CommentNode} model Model to observe
16 * @param {Object} [config] Configuration options
17 */
18 ve.ce.CommentNode = function VeCeCommentNode( model, config ) {
19 // Parent constructor
20 ve.ce.CommentNode.super.call( this, model, config );
21
22 // Mixin constructors
23 ve.ce.FocusableNode.call( this, this.$element, config );
24
25 // Events
26 this.model.connect( this, { attributeChange: 'onAttributeChange' } );
27
28 // DOM changes
29 this.$element.addClass( 've-ce-commentNode' );
30 };
31
32 /* Inheritance */
33
34 OO.inheritClass( ve.ce.CommentNode, ve.ce.LeafNode );
35 OO.mixinClass( ve.ce.CommentNode, ve.ce.FocusableNode );
36
37 /* Static Properties */
38
39 ve.ce.CommentNode.static.name = 'comment';
40
41 ve.ce.CommentNode.static.primaryCommandName = 'comment';
42
43 ve.ce.CommentNode.static.iconWhenInvisible = 'speechBubbleNotice';
44
45 /* Static Methods */
46
47 /**
48 * @inheritdoc
49 */
50 ve.ce.CommentNode.static.getDescription = function ( model ) {
51 return model.getAttribute( 'text' );
52 };
53
54 /**
55 * Update the rendering of the 'text' attribute
56 * when it changes in the model.
57 *
58 * @param {string} key Attribute key
59 * @param {string} from Old value
60 * @param {string} to New value
61 */
62 ve.ce.CommentNode.prototype.onAttributeChange = function ( key ) {
63 if ( key === 'text' ) {
64 this.updateInvisibleIconLabel();
65 }
66 };
67
68 /* Method */
69
70 // eslint-disable-next-line jsdoc/require-returns
71 /**
72 * @see ve.ce.FocusableNode
73 */
74 ve.ce.CommentNode.prototype.hasRendering = function () {
75 // Comment nodes never have a rendering, don't bother with expensive DOM inspection
76 return false;
77 };
78
79 /* Registration */
80
81 ve.ce.nodeFactory.register( ve.ce.CommentNode );