From: Aleksander Ɓukasz Date: Mon, 18 Nov 2013 08:43:17 +0000 (+0100) Subject: wlxmlListener: handle nodeAdded, nodeRemoved, nodeDetached events X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/db3139e6d432413b4bc06c68c5a75c3bc8e4c8dd?hp=7fbd869e69b05b5d9c9050aaf636b6660b6ace7c wlxmlListener: handle nodeAdded, nodeRemoved, nodeDetached events --- diff --git a/src/editor/modules/documentCanvas/canvas/wlxmlListener.js b/src/editor/modules/documentCanvas/canvas/wlxmlListener.js index ecf4900..35bc45f 100644 --- a/src/editor/modules/documentCanvas/canvas/wlxmlListener.js +++ b/src/editor/modules/documentCanvas/canvas/wlxmlListener.js @@ -39,6 +39,28 @@ var handlers = { nodeTagChange: function(event) { var canvasNode = utils.findCanvasElement(event.meta.node); canvasNode.setWlxmlTag(event.meta.newTagName); + }, + nodeAdded: function(event) { + var parentElement = utils.findCanvasElement(event.meta.node.parent()), + nodeIndex = event.meta.node.getIndex(), + referenceElement, referenceAction; + + if(nodeIndex === 0) { + referenceElement = parentElement; + referenceAction = 'prepend'; + } else { + referenceElement = parentElement.children()[nodeIndex-1]; + referenceAction = 'after'; + } + + referenceElement[referenceAction](event.meta.node); + }, + nodeMoved: function(event) { + return handlers.nodeAdded(event); + }, + nodeDetached: function(event) { + var canvasNode = utils.findCanvasElementInParent(event.meta.node, event.meta.parent); + canvasNode.detach(); } };