mediawiki-extensions-Visual.../modules/ve2/ve.BranchNode.js
Trevor Parscal c2d4a2d928 Added basic ve.ce nodes
* Also removed beforeSplice and afterSplice in favor of just plain splice which is the same as afterSplice used to be - beforeSplice was never used and it was making things more complex looking than needed

Change-Id: Icbbc57eac73a2a206ba35409ab57b3d1a49ab1a5
2012-04-30 16:58:41 -07:00

37 lines
944 B
JavaScript

/**
* Mixin for branch nodes.
*
* 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 );
};