Debian Codegraph @

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

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