mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Additional ArrayContainer helper methods
This commit is contained in:
parent
c1c56929e9
commit
ad81118430
@ -46,12 +46,52 @@ class ArrayContainer extends Container {
|
||||
child.container = null;
|
||||
}
|
||||
|
||||
prependChild(newChild) {
|
||||
ok(newChild, 'Invalid child');
|
||||
this.array.unshift(newChild);
|
||||
newChild.container = this;
|
||||
}
|
||||
|
||||
appendChild(newChild) {
|
||||
ok(newChild, 'Invalid child');
|
||||
this.array.push(newChild);
|
||||
newChild.container = this;
|
||||
}
|
||||
|
||||
insertChildBefore(newChild, referenceNode) {
|
||||
ok(newChild, 'Invalid child');
|
||||
ok(referenceNode, 'Invalid reference child');
|
||||
|
||||
var array = this.array;
|
||||
var len = array.length;
|
||||
for (var i=0; i<len; i++) {
|
||||
var curChild = array[i];
|
||||
if (curChild === referenceNode) {
|
||||
array.splice(i, 0, newChild);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error('Reference node not found');
|
||||
}
|
||||
|
||||
insertChildAfter(newChild, referenceNode) {
|
||||
ok(newChild, 'Invalid child');
|
||||
ok(referenceNode, 'Invalid reference child');
|
||||
|
||||
var array = this.array;
|
||||
var len = array.length;
|
||||
for (var i=0; i<len; i++) {
|
||||
var curChild = array[i];
|
||||
if (curChild === referenceNode) {
|
||||
array.splice(i+1, 0, newChild);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error('Reference node not found');
|
||||
}
|
||||
|
||||
forEachNextSibling(node, callback, thisObj) {
|
||||
if (node.container !== this) {
|
||||
throw new Error('Node does not belong to container: ' + node);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user