Debian Codegraph @

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

raw symbols SCIP
1 /*!
2 * VisualEditor ContentEditable SectionNode class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * ContentEditable section node.
9 *
10 * @class
11 * @extends ve.ce.BranchNode
12 * @mixes ve.ce.ActiveNode
13 * @constructor
14 * @param {ve.dm.SectionNode} model Model to observe
15 * @param {Object} [config] Configuration options
16 */
17 ve.ce.SectionNode = function VeCeSectionNode() {
18 // Parent constructor
19 ve.ce.SectionNode.super.apply( this, arguments );
20
21 // Events
22 this.model.connect( this, { update: 'onUpdate' } );
23
24 // Mixin constructors
25 ve.ce.ActiveNode.call( this );
26
27 // DOM changes
28 this.$element.addClass( 've-ce-sectionNode' );
29 };
30
31 /* Inheritance */
32
33 OO.inheritClass( ve.ce.SectionNode, ve.ce.BranchNode );
34
35 OO.mixinClass( ve.ce.SectionNode, ve.ce.ActiveNode );
36
37 /* Static Properties */
38
39 ve.ce.SectionNode.static.name = 'section';
40
41 /* Methods */
42
43 /**
44 * Get the HTML tag name.
45 *
46 * Tag name is selected based on the model's style attribute.
47 *
48 * @return {string} HTML tag name
49 */
50 ve.ce.SectionNode.prototype.getTagName = function () {
51 const style = this.model.getAttribute( 'style' );
52
53 if ( this.model.constructor.static.matchTagNames.indexOf( style ) === -1 ) {
54 throw new Error( 'Invalid style' );
55 }
56 return style;
57 };
58
59 /**
60 * Handle model update events.
61 *
62 * If the style changed since last update the DOM wrapper will be replaced with an appropriate one.
63 */
64 ve.ce.SectionNode.prototype.onUpdate = function () {
65 this.updateTagName();
66 };
67
68 /* Registration */
69
70 ve.ce.nodeFactory.register( ve.ce.SectionNode );