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

85.71% Statements 18/21
100% Branches 2/2
75% Functions 3/4
85.71% Lines 18/21

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                                1x   2x         1x       1x   1x   1x   1x   1x 2x 2x     1x 6x 6x 6x 3x   6x     1x               1x  
/*!
 * VisualEditor DataModel CheckListItemNode class.
 *
 * @copyright 2011-2020 VisualEditor Team and others; see http://ve.mit-license.org
 */
 
/**
 * DataModel list item node.
 *
 * @class
 * @extends ve.dm.BranchNode
 *
 * @constructor
 * @param {Object} [element] Reference to element in linear model
 * @param {ve.dm.Node[]} [children]
 */
ve.dm.CheckListItemNode = function VeDmCheckListItemNode() {
	// Parent constructor
	ve.dm.CheckListItemNode.super.apply( this, arguments );
};
 
/* Inheritance */
 
OO.inheritClass( ve.dm.CheckListItemNode, ve.dm.BranchNode );
 
/* Static Properties */
 
ve.dm.CheckListItemNode.static.name = 'checkListItem';
 
ve.dm.CheckListItemNode.static.parentNodeTypes = [ 'checkList' ];
 
ve.dm.CheckListItemNode.static.matchTagNames = [ 'li' ];
 
ve.dm.CheckListItemNode.static.matchRdfaTypes = [ 've:checkList' ];
 
ve.dm.CheckListItemNode.static.toDataElement = function ( domElements ) {
	var checked = domElements[ 0 ].hasAttribute( 'checked' );
	return { type: this.name, attributes: { checked: checked } };
};
 
ve.dm.CheckListItemNode.static.toDomElements = function ( dataElement, doc ) {
	var listItem = doc.createElement( 'li' );
	listItem.setAttribute( 'rel', 've:checkList' );
	if ( dataElement.attributes.checked ) {
		listItem.setAttribute( 'checked', 'checked' );
	}
	return [ listItem ];
};
 
ve.dm.CheckListItemNode.static.cloneElement = function () {
	var clone = ve.dm.CheckListItemNode.super.static.cloneElement.apply( this, arguments );
	clone.attributes.checked = false;
	return clone;
};
 
/* Registration */
 
ve.dm.modelRegistry.register( ve.dm.CheckListItemNode );