mediawiki-extensions-Visual.../modules/ve2/ve.BranchNode.js
Trevor Parscal a774b3dbf6 Added test for getOffset map
And fixed ve.dm.DocumentFragment constructor to generate a correct offset map which creates references to branch nodes only

Change-Id: If9e515be0c63d272bfed9bf4da625a48edd36f48
2012-04-27 17:16:29 -07:00

41 lines
1 KiB
JavaScript

/**
* Mixin for branch node functionality
*
* Branch nodes are immutable, which is why there are no methods for adding or removing children.
* DataModel classes will add this functionality, and other subclasses will implement behavior that
* mimcs changes made to data model nodes.
*
* @class
* @abstract
* @constructor
* @param {ve.Node[]} children Array of children to add
*/
ve.BranchNode = function( children ) {
this.children = ve.isArray( children ) ? children : [];
};
/**
* Gets a list of child nodes.
*
* @method
* @returns {ve.Node[]} List of child nodes
*/
ve.BranchNode.prototype.getChildren = function() {
return this.children;
};
/**
* Gets the index of a given child node.
*
* @method
* @param {ve.dm.Node} node Child node to find index of
* @returns {Integer} Index of child node or -1 if node was not found
*/
ve.BranchNode.prototype.indexOf = function( node ) {
return ve.inArray( node, this.children );
};
ve.BranchNode.prototype.canHaveChildren = function() {
return true;
};