From 75d85549c6d2a5284593e20c21d61fc5d6200bca Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Mon, 8 Jun 2020 18:24:49 +0200 Subject: Add 'insert before id' to create and move commands. --- src/ws/node.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'src/ws/node.js') 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) -- cgit v1.2.3