Debian Codegraph @

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

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