|
|
@@ -65,6 +65,18 @@ export default class Element extends Node {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ cloneNode( deep ) {
|
|
|
+ const childrenClone = [];
|
|
|
+
|
|
|
+ if ( deep ) {
|
|
|
+ for ( child of this.getChildren() ) {
|
|
|
+ childrenClone.push( child.cloneNode( deep ) );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return new this( this.name, this._attrs, childrenClone );
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* {@link core.treeView.Element#insert Insert} a child node or a list of child nodes at the end of this node and sets
|
|
|
* the parent of these nodes to this element.
|
|
|
@@ -196,17 +208,49 @@ export default class Element extends Node {
|
|
|
* Removes number of child nodes starting at the given index and set the parent of these nodes to `null`.
|
|
|
*
|
|
|
* @param {Number} index Number of the first node to remove.
|
|
|
- * @param {Number} number Number of nodes to remove.
|
|
|
+ * @param {Number} [number] Number of nodes to remove.
|
|
|
* @returns {Array.<core.treeView.Node>} The array of removed nodes.
|
|
|
* @fires core.treeView.Node#change
|
|
|
*/
|
|
|
removeChildren( index, number ) {
|
|
|
this._fireChange( 'CHILDREN', this );
|
|
|
|
|
|
+ if ( !number ) {
|
|
|
+ number = 1;
|
|
|
+ }
|
|
|
+
|
|
|
for ( let i = index; i < index + number; i++ ) {
|
|
|
this._children[ i ].parent = null;
|
|
|
}
|
|
|
|
|
|
return this._children.splice( index, number );
|
|
|
}
|
|
|
+
|
|
|
+ same( otherNode ) {
|
|
|
+ if ( !otherNode instanceof Element ) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( this.name != otherNode.name ) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ const thisNodeAttrKeys = this.getAttributeKeys();
|
|
|
+ const otherNodeAttrKeys = this.getAttributeKeys();
|
|
|
+ let count = 0;
|
|
|
+
|
|
|
+ for ( key of thisNodeAttrKeys ) {
|
|
|
+ if ( this.getAttribute( key ) !== otherNode.getAttribute( key ) ) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( count != utils.count( otherNodeAttrKeys ) ) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|