Debian Codegraph @

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

raw symbols SCIP
1 /*!
2 * VisualEditor DataModel HeadingNode class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * DataModel heading node.
9 *
10 * @class
11 * @extends ve.dm.ContentBranchNode
12 *
13 * @constructor
14 * @param {Object} [element] Reference to element in linear model
15 * @param {ve.dm.Node[]} [children]
16 */
17 ve.dm.HeadingNode = function VeDmHeadingNode() {
18 // Parent constructor
19 ve.dm.HeadingNode.super.apply( this, arguments );
20 };
21
22 /* Inheritance */
23
24 OO.inheritClass( ve.dm.HeadingNode, ve.dm.ContentBranchNode );
25
26 /* Methods */
27
28 ve.dm.HeadingNode.prototype.compareForMerging = function ( otherNode ) {
29 return ve.dm.HeadingNode.super.prototype.compareForMerging.apply( this, arguments ) &&
30 this.getAttribute( 'level' ) === otherNode.getAttribute( 'level' );
31 };
32
33 /* Static Properties */
34
35 ve.dm.HeadingNode.static.name = 'heading';
36
37 ve.dm.HeadingNode.static.defaultAttributes = {
38 level: 1
39 };
40
41 ve.dm.HeadingNode.static.matchTagNames = [ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' ];
42
43 ve.dm.HeadingNode.static.toDataElement = function ( domElements ) {
44 const levels = {
45 h1: 1,
46 h2: 2,
47 h3: 3,
48 h4: 4,
49 h5: 5,
50 h6: 6
51 },
52 level = levels[ domElements[ 0 ].nodeName.toLowerCase() ];
53 return { type: this.name, attributes: { level: level } };
54 };
55
56 ve.dm.HeadingNode.static.toDomElements = function ( dataElement, doc ) {
57 const level = dataElement.attributes && dataElement.attributes.level || 1;
58 return [ doc.createElement( 'h' + level ) ];
59 };
60
61 ve.dm.HeadingNode.static.describeChange = function ( key, change ) {
62 if ( key === 'level' ) {
63 return ve.htmlMsg( 'visualeditor-changedesc-no-key',
64 // The following messages are used here:
65 // * visualeditor-formatdropdown-format-heading1
66 // * visualeditor-formatdropdown-format-heading2
67 // * visualeditor-formatdropdown-format-heading3
68 // * visualeditor-formatdropdown-format-heading4
69 // * visualeditor-formatdropdown-format-heading5
70 // * visualeditor-formatdropdown-format-heading6
71 this.wrapText( 'del', ve.msg( 'visualeditor-formatdropdown-format-heading' + change.from ) ),
72 this.wrapText( 'ins', ve.msg( 'visualeditor-formatdropdown-format-heading' + change.to ) )
73 );
74 }
75 // Parent method
76 return ve.dm.HeadingNode.super.static.describeChange.apply( this, arguments );
77 };
78
79 /* Registration */
80
81 ve.dm.modelRegistry.register( ve.dm.HeadingNode );