wlxmlListener: handle nodeAdded, nodeRemoved, nodeDetached events
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Mon, 18 Nov 2013 08:43:17 +0000 (09:43 +0100)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Mon, 2 Dec 2013 13:50:52 +0000 (14:50 +0100)
src/editor/modules/documentCanvas/canvas/wlxmlListener.js

index ecf4900..35bc45f 100644 (file)
@@ -39,6 +39,28 @@ var handlers = {
     nodeTagChange: function(event) {
         var canvasNode = utils.findCanvasElement(event.meta.node);
         canvasNode.setWlxmlTag(event.meta.newTagName);
     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();
     }
 };
 
     }
 };