diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2020-06-08 18:24:49 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2020-06-08 19:39:31 +0200 |
commit | 75d85549c6d2a5284593e20c21d61fc5d6200bca (patch) | |
tree | b5077e272f238b47af9530f9b2fac2e69839d063 /src/ws/node.js | |
parent | 195bf2f6a7d7268a88338ae8fd3a30fdb5196300 (diff) |
Add 'insert before id' to create and move commands.
Diffstat (limited to 'src/ws/node.js')
-rw-r--r-- | src/ws/node.js | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/ws/node.js b/src/ws/node.js index e2af81e..e9d68b6 100644 --- a/src/ws/node.js +++ b/src/ws/node.js @@ -72,15 +72,32 @@ Node.prototype.findNode = function(id, subscribeid) return null; }; -Node.prototype.addChild = function(node) +Node.prototype.addChild = function(node, insertBeforeId) { if(node.parent != null) { node.parent.removeChild(node); } - this.children.push(node); + node.parent = this; - this.element.appendChild(node.element); + + inserted = false; + for(i = 0; i < this.children.length; ++i) + { + if(this.children[i].id == insertBeforeId) + { + this.children.splice(i - 1, 0, node); + this.element.insertBefore(node.element, this.element.childNodes[i + 2]); + inserted = true; + break; + } + } + + if(inserted == false) + { + this.children.push(node); + this.element.appendChild(node.element); + } }; Node.prototype.removeChild = function(node) |