DocumentTextNode.after
[fnpeditor.git] / modules / documentCanvas / canvas / documentElement.js
index 13ed6a6..6fea275 100644 (file)
@@ -70,9 +70,14 @@ DocumentNodeElement.prototype = new DocumentElement();
 DocumentTextElement.prototype = new DocumentElement();
 
 var manipulate = function(e, params, action) {
-    var newElement = DocumentNodeElement.createDOM(params);
-    e.$element[action](newElement);
-    return documentElementFromHTMLElement(newElement);
+    var dom;
+    if(params instanceof DocumentElement) {
+        dom = params.dom()
+    } else {
+        dom = DocumentNodeElement.createDOM(params);
+    }
+    e.$element[action](dom);
+    return documentElementFromHTMLElement(dom);
 };
 
 $.extend(DocumentNodeElement.prototype, {
@@ -106,6 +111,20 @@ $.extend(DocumentTextElement.prototype, {
     },
     getText: function() {
         return this.$element.text();
+    },
+    after: function(params) {
+        if(params.text || params instanceof DocumentTextElement)
+            return false;
+        var dom;
+        if(params instanceof DocumentNodeElement) {
+            dom = params.dom();
+        } else {
+            dom = DocumentNodeElement.createDOM(params);
+        }
+        this.$element.wrap('<div>');
+        this.$element.parent().after(dom[0]);
+        this.$element.unwrap();
+        return documentElementFromHTMLElement(dom[0]);
     }
 });