fix problem with delete
[fnpeditor.git] / src / editor / modules / documentCanvas / canvas / documentElement.js
index adeaafe..a1965cd 100644 (file)
@@ -95,6 +95,7 @@ $.extend(DocumentElement.prototype, {
 var DocumentNodeElement = function(wlxmlNode, canvas) {
     DocumentElement.call(this, wlxmlNode, canvas);
     this.containers = [];
 var DocumentNodeElement = function(wlxmlNode, canvas) {
     DocumentElement.call(this, wlxmlNode, canvas);
     this.containers = [];
+    this.elementsRegister = canvas.createElementsRegister();
     this.contextMenuActions = [];
     this.init(this.dom);
 };
     this.contextMenuActions = [];
     this.init(this.dom);
 };
@@ -105,7 +106,7 @@ var manipulate = function(e, params, action) {
     if(params instanceof DocumentElement) {
         element = params;
     } else {
     if(params instanceof DocumentElement) {
         element = params;
     } else {
-        element = e.canvas.createElement(params);
+        element = e.createElement(params);
     }
     if(element.dom) {
         e.dom[action](element.dom);
     }
     if(element.dom) {
         e.dom[action](element.dom);
@@ -147,6 +148,10 @@ $.extend(DocumentNodeElement.prototype, {
             this.containers.splice(idx, 1);
         }
     },
             this.containers.splice(idx, 1);
         }
     },
+    createElement: function(wlxmlNode) {
+        var parent = this.wlxmlNode.parent() ? utils.getElementForNode(this.wlxmlNode.parent()) : null;
+        return this.canvas.createElement(wlxmlNode, this.elementsRegister, !parent) || parent.createElement(wlxmlNode);
+    },
     addToContextMenu: function(actionFqName) {
         this.contextMenuActions.push(this.canvas.createAction(actionFqName));
     },
     addToContextMenu: function(actionFqName) {
         this.contextMenuActions.push(this.canvas.createAction(actionFqName));
     },
@@ -236,6 +241,9 @@ $.extend(DocumentNodeElement.prototype, {
         // })
         this.dom.css('display', what);
         this._container().css('display', what);
         // })
         this.dom.css('display', what);
         this._container().css('display', what);
+    },
+    children: function() {
+        return [];
     }
 });
 
     }
 });
 
@@ -297,7 +305,7 @@ $.extend(DocumentTextElement.prototype, {
         if(params instanceof DocumentNodeElement) {
             element = params;
         } else {
         if(params instanceof DocumentNodeElement) {
             element = params;
         } else {
-            element = this.canvas.createElement(params);
+            element = this.parent().createElement(params);
         }
         if(element.dom) {
             this.dom.wrap('<div>');
         }
         if(element.dom) {
             this.dom.wrap('<div>');
@@ -315,7 +323,7 @@ $.extend(DocumentTextElement.prototype, {
         if(params instanceof DocumentNodeElement) {
             element = params;
         } else {
         if(params instanceof DocumentNodeElement) {
             element = params;
         } else {
-            element = this.canvas.createElement(params);
+            element = this.createElement(params);
         }
         if(element.dom) {
             this.dom.wrap('<div>');
         }
         if(element.dom) {
             this.dom.wrap('<div>');