Debian Codegraph @

extensions/VisualEditor/lib/ve/src/dm/nodes/ve.dm.DefinitionListItemNode.js

raw symbols SCIP
1 /*!
2 * VisualEditor DataModel DefinitionListItemNode class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * DataModel definition list item node.
9 *
10 * @class
11 * @extends ve.dm.BranchNode
12 *
13 * @constructor
14 * @param {Object} [element] Reference to element in linear model
15 * @param {ve.dm.Node[]} [children]
16 */
17 ve.dm.DefinitionListItemNode = function VeDmDefinitionListItemNode() {
18 // Parent constructor
19 ve.dm.DefinitionListItemNode.super.apply( this, arguments );
20 };
21
22 /* Inheritance */
23
24 OO.inheritClass( ve.dm.DefinitionListItemNode, ve.dm.BranchNode );
25
26 /* Static Properties */
27
28 ve.dm.DefinitionListItemNode.static.name = 'definitionListItem';
29
30 ve.dm.DefinitionListItemNode.static.parentNodeTypes = [ 'definitionList' ];
31
32 ve.dm.DefinitionListItemNode.static.defaultAttributes = {
33 style: 'term'
34 };
35
36 ve.dm.DefinitionListItemNode.static.matchTagNames = [ 'dt', 'dd' ];
37
38 ve.dm.DefinitionListItemNode.static.toDataElement = function ( domElements ) {
39 const style = domElements[ 0 ].nodeName.toLowerCase() === 'dt' ? 'term' : 'definition';
40 return { type: this.name, attributes: { style: style } };
41 };
42
43 ve.dm.DefinitionListItemNode.static.toDomElements = function ( dataElement, doc ) {
44 const tag = dataElement.attributes && dataElement.attributes.style === 'term' ? 'dt' : 'dd';
45 return [ doc.createElement( tag ) ];
46 };
47
48 // Nodes which are diffed as a list must have the same description logic as each other
49 ve.dm.DefinitionListItemNode.static.describeChanges = function () {
50 return ve.dm.ListNode.static.describeChanges.apply( this, arguments );
51 };
52
53 ve.dm.DefinitionListItemNode.static.describeChange = function () {
54 return ve.dm.ListNode.static.describeChange.apply( this, arguments );
55 };
56
57 /* Registration */
58
59 ve.dm.modelRegistry.register( ve.dm.DefinitionListItemNode );