Additional Node helper methods for inserting siblings and children

This commit is contained in:
Patrick Steele-Idem 2016-02-04 16:20:48 -07:00
parent ad81118430
commit d28ea9ba33

View File

@ -64,6 +64,16 @@ class Node {
ok(replaced, 'Invalid state. Child does not belong to the container');
}
insertSiblingBefore(newNode) {
ok(this.container, 'Node does not belong to a container: ' + this);
this.container.insertChildAfter(newNode, this);
}
insertSiblingAfter(newNode) {
ok(this.container, 'Node does not belong to a container: ' + this);
this.container.insertChildAfter(newNode, this);
}
/**
* Converts the provided `array` into a `ArrayContainer`. If the provided `array` is already an instance of a `Container` then it is simply returned.
* @param {[type]} array [description]
@ -77,11 +87,21 @@ class Node {
return new ArrayContainer(this, array);
}
prependChild(node) {
ok(this.body, 'Node does not support child nodes: ' + this);
this.body.prependChild(node);
}
appendChild(node) {
ok(this.body, 'Node does not support child nodes: ' + this);
this.body.appendChild(node);
}
insertBefore(newNode, referenceNode) {
ok(this.body, 'Node does not support child nodes: ' + this);
this.body.insertBefore(newNode, referenceNode);
}
forEachChild(callback, thisObj) {
if (this.body) {
this.body.forEach(callback, thisObj);