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 | |
parent | 195bf2f6a7d7268a88338ae8fd3a30fdb5196300 (diff) |
Add 'insert before id' to create and move commands.
Diffstat (limited to 'src/ws')
-rw-r--r-- | src/ws/handler.js | 6 | ||||
-rw-r--r-- | src/ws/node.js | 23 | ||||
-rw-r--r-- | src/ws/proto.js | 6 | ||||
-rw-r--r-- | src/ws/view.js | 2 |
4 files changed, 29 insertions, 8 deletions
diff --git a/src/ws/handler.js b/src/ws/handler.js index c0321a9..27eb76e 100644 --- a/src/ws/handler.js +++ b/src/ws/handler.js @@ -38,12 +38,13 @@ function moveEventHandler(e) var subscribeid = e.detail.subscribeid; var id = e.detail.id; var parentid = e.detail.parentid; + var insertBeforeId = e.detail.insertBeforeId; var node = findNode(id, subscribeid); var new_parent = findNode(parentid, subscribeid); if(node != null && new_parent != null) { - new_parent.addChild(node); + new_parent.addChild(node, insertBeforeId); } } @@ -53,6 +54,7 @@ function createEventHandler(e) var subscribeid = e.detail.subscribeid; var id = e.detail.id; var parentid = e.detail.parentid; + var insertBeforeId = e.detail.insertBeforeId; var node = new Node(id, subscribeid); node.create(); @@ -68,7 +70,7 @@ function createEventHandler(e) var parent = findNode(parentid, subscribeid); if(parent != null) { - parent.addChild(node); + parent.addChild(node, insertBeforeId); } } 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) diff --git a/src/ws/proto.js b/src/ws/proto.js index 035408f..5eadd70 100644 --- a/src/ws/proto.js +++ b/src/ws/proto.js @@ -129,6 +129,7 @@ try subscribeid: subscribeid, id: id, parentid: msg[3], + insertBeforeId: msg[4], }, bubbles: true, cancelable: true @@ -143,6 +144,7 @@ try subscribeid: subscribeid, id: id, parentid: msg[3], + insertBeforeId: msg[4], }, bubbles: true, cancelable: true @@ -237,7 +239,7 @@ function update(id, name, value) transmit("update "+id+" "+name+" "+value); } -function move(id, parent) +function move(id, parent, before) { - transmit("move "+id+" "+parent); + transmit("move "+id+" "+parent+" "+before); } diff --git a/src/ws/view.js b/src/ws/view.js index e96ec70..4e2d837 100644 --- a/src/ws/view.js +++ b/src/ws/view.js @@ -73,7 +73,7 @@ function drop(target, e) var id = e.dataTransfer.getData('id'); update(idFromStr(id), "dragged", "false"); - move(idFromStr(id), idFromStr(target.id)); + move(idFromStr(id), idFromStr(target.id), -1); } function subscribeMe(target, e) |