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

86.96% Statements 20/23
75% Branches 6/8
83.33% Functions 5/6
86.96% Lines 20/23

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 76 77 78 79 80 81 82 83                                1x   864x         1x       1x   1x   1x       1x   1x             1x 3x     1x 203x 203x     1x 65x 65x     1x                               1x   1250x         1x  
/*!
 * VisualEditor DataModel ListNode class.
 *
 * @copyright 2011-2020 VisualEditor Team and others; see http://ve.mit-license.org
 */
 
/**
 * DataModel list node.
 *
 * @class
 * @extends ve.dm.BranchNode
 *
 * @constructor
 * @param {Object} [element] Reference to element in linear model
 * @param {ve.dm.Node[]} [children]
 */
ve.dm.ListNode = function VeDmListNode() {
	// Parent constructor
	ve.dm.ListNode.super.apply( this, arguments );
};
 
/* Inheritance */
 
OO.inheritClass( ve.dm.ListNode, ve.dm.BranchNode );
 
/* Static Properties */
 
ve.dm.ListNode.static.name = 'list';
 
ve.dm.ListNode.static.childNodeTypes = [ 'listItem' ];
 
ve.dm.ListNode.static.defaultAttributes = {
	style: 'bullet'
};
 
ve.dm.ListNode.static.matchTagNames = [ 'ul', 'ol' ];
 
ve.dm.ListNode.static.isDiffedAsList = true;
 
/**
 * Creates a list item element
 *
 * @return {Object} Element data
 */
ve.dm.ListNode.static.createItem = function () {
	return { type: 'listItem' };
};
 
ve.dm.ListNode.static.toDataElement = function ( domElements ) {
	var style = domElements[ 0 ].nodeName.toLowerCase() === 'ol' ? 'number' : 'bullet';
	return { type: this.name, attributes: { style: style } };
};
 
ve.dm.ListNode.static.toDomElements = function ( dataElement, doc ) {
	var tag = dataElement.attributes && dataElement.attributes.style === 'number' ? 'ol' : 'ul';
	return [ doc.createElement( tag ) ];
};
 
ve.dm.ListNode.static.describeChange = function ( key, change ) {
	if ( key === 'style' ) {
		return ve.htmlMsg( 'visualeditor-changedesc-no-key',
			// The following messages are used here:
			// * visualeditor-listbutton-bullet-tooltip
			// * visualeditor-listbutton-number-tooltip
			this.wrapText( 'del', ve.msg( 'visualeditor-listbutton-' + change.from + '-tooltip' ) ),
			this.wrapText( 'ins', ve.msg( 'visualeditor-listbutton-' + change.to + '-tooltip' ) )
		);
	}
	// Parent method
	return ve.dm.ListNode.parent.static.describeChange.apply( this, arguments );
};
 
/* Methods */
 
ve.dm.ListNode.prototype.canHaveSlugAfter = function () {
	// A paragraph can be added after a list by pressing enter in an empty list item
	return false;
};
 
/* Registration */
 
ve.dm.modelRegistry.register( ve.dm.ListNode );