mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Additional Node helper methods for inserting siblings and children
This commit is contained in:
parent
ad81118430
commit
d28ea9ba33
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user