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

100% Statements 27/27
71.42% Branches 5/7
100% Functions 5/5
100% Lines 26/26

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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98                                1x   452x     452x         1x                 1x   1x   1x   1x   1x       1x 191x         191x 191x     1x 50x         50x 50x               1x 486x 42x   486x 486x 700x                       1x 34x         1x  
/*!
 * VisualEditor DataModel TableSelectionNode class.
 *
 * @copyright See AUTHORS.txt
 */
 
/**
 * DataModel table section node.
 *
 * @class
 * @extends ve.dm.BranchNode
 *
 * @constructor
 * @param {Object} [element] Reference to element in linear model
 * @param {ve.dm.Node[]} [children]
 */
ve.dm.TableSectionNode = function VeDmTableSectionNode() {
	// Parent constructor
	ve.dm.TableSectionNode.super.apply( this, arguments );
 
	// Events
	this.connect( this, { splice: 'onSplice' } );
};
 
/* Inheritance */
 
OO.inheritClass( ve.dm.TableSectionNode, ve.dm.BranchNode );
 
/**
 * @event cellAttributeChange
 * @param {ve.dm.TableCellableNode} cell
 */
 
/* Static Properties */
 
ve.dm.TableSectionNode.static.name = 'tableSection';
 
ve.dm.TableSectionNode.static.childNodeTypes = [ 'tableRow' ];
 
ve.dm.TableSectionNode.static.parentNodeTypes = [ 'table' ];
 
ve.dm.TableSectionNode.static.defaultAttributes = { style: 'body' };
 
ve.dm.TableSectionNode.static.matchTagNames = [ 'thead', 'tbody', 'tfoot' ];
 
/* Static Methods */
 
ve.dm.TableSectionNode.static.toDataElement = function ( domElements ) {
	var styles = {
			thead: 'header',
			tbody: 'body',
			tfoot: 'footer'
		},
		style = styles[ domElements[ 0 ].nodeName.toLowerCase() ] || 'body';
	return { type: this.name, attributes: { style: style } };
};
 
ve.dm.TableSectionNode.static.toDomElements = function ( dataElement, doc ) {
	var tags = {
			header: 'thead',
			body: 'tbody',
			footer: 'tfoot'
		},
		tag = tags[ dataElement.attributes && dataElement.attributes.style || 'body' ];
	return [ doc.createElement( tag ) ];
};
 
/* Methods */
 
/**
 * Handle splicing of child nodes
 */
ve.dm.TableSectionNode.prototype.onSplice = function () {
	if ( this.getRoot() ) {
		this.getParent().getMatrix().invalidate();
	}
	var nodes = Array.prototype.slice.call( arguments, 2 );
	for ( var i = 0; i < nodes.length; i++ ) {
		nodes[ i ].connect( this, {
			cellAttributeChange: 'onCellAttributeChange'
		} );
	}
};
 
/**
 * Handle cell attribute changes
 *
 * @param {ve.dm.TableCellableNode} cell
 * @fires cellAttributeChange
 */
ve.dm.TableSectionNode.prototype.onCellAttributeChange = function ( cell ) {
	this.emit( 'cellAttributeChange', cell );
};
 
/* Registration */
 
ve.dm.modelRegistry.register( ve.dm.TableSectionNode );