Dividing DocumentTextElement with DocumentNodeElement
[fnpeditor.git] / modules / documentCanvas / canvas / documentElement.js
index 9ddf190..c6c9f22 100644 (file)
@@ -292,7 +292,7 @@ $.extend(DocumentNodeElement.prototype, {
             this.dom().removeAttr('wlxml-class');
     },
     is: function(what) {
-        if(what === 'list' && _.contains(['list-items', 'list-items-enum'], this.dom().attr('wlxml-class')))
+        if(what === 'list' && _.contains(['list.items', 'list.items.enum'], this.getWlxmlClass()))
             return true;
         return false;
     },
@@ -456,6 +456,22 @@ $.extend(DocumentTextElement.prototype, {
 
         return {first: parentElement, second: newElement};
     },
+    divide: function(params) {
+        var myText = this.getText();
+        
+        if(params.offset <= 0 || params.offset >= myText.length)
+            return;
+
+        var lhsText = myText.substr(0, params.offset),
+            rhsText = myText.substr(params.offset),
+            newElement = DocumentNodeElement.create({tag: params.tag, klass: params.klass}, this.canvas),
+            rhsTextElement = DocumentTextElement.create({text: rhsText});
+
+        this.setText(lhsText);
+        this.after(newElement);
+        newElement.after(rhsTextElement);
+        return newElement;
+    }
 });
 
 return {