All files / src/dm/nodes ve.dm.HeadingNode.js

83.33% Statements 15/18
40% Branches 2/5
75% Functions 3/4
83.33% Lines 15/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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