Getting rid of old wlxmlTag attribute of DocumentElement
[fnpeditor.git] / modules / documentCanvas / canvas / documentElement.js
index 89e98a2..d0adbc0 100644 (file)
@@ -12,8 +12,6 @@ var DocumentElement = function(htmlElement, canvas) {
         return;
     this.canvas = canvas;
     this.$element = $(htmlElement);
-
-    this.wlxmlTag = this.$element.attr('wlxml-tag');
 }
 
 $.extend(DocumentElement.prototype, {
@@ -186,12 +184,12 @@ $.extend(DocumentTextElement.prototype, {
         return documentElementFromHTMLElement(dom[0]);
     },
     wrapWithNodeElement: function(wlxmlNode) {
-        if(wlxmlNode.start && wlxmlNode.end) {
+        if(typeof wlxmlNode.start === 'number' && typeof wlxmlNode.end === 'number') {
             return this.canvas.wrapText({
                 inside: this.parent(),
                 textNodeIdx: this.parent().childIndex(this),
-                offsetStart: wlxmlNode.start,
-                offsetEnd: wlxmlNode.end,
+                offsetStart: Math.min(wlxmlNode.start, wlxmlNode.end),
+                offsetEnd: Math.max(wlxmlNode.start, wlxmlNode.end),
                 _with: {tag: wlxmlNode.tag, klass: wlxmlNode.klass}
             });
         } else {
@@ -225,9 +223,9 @@ $.extend(DocumentTextElement.prototype, {
         if(prefix.length > 0)
             this.setText(prefix);
         else
-            this.remove();
+            this.detach();
         
-        var newElement = DocumentNodeElement.create({tag: parentElement.wlxmlTag, klass: parentElement.wlxmlClass}, myCanvas);
+        var newElement = DocumentNodeElement.create({tag: parentElement.getWlxmlTag(), klass: parentElement.getWlxmlClass()}, myCanvas);
         parentElement.after(newElement);
 
         if(suffix.length > 0)