Wrapping text/element node with element node
[fnpeditor.git] / src / smartxml / smartxml.js
index b7fc3f1..43e3041 100644 (file)
@@ -29,7 +29,21 @@ $.extend(DocumentNode.prototype, {
 
     sameNode: function(otherNode) {
         return this.nativeNode === otherNode.nativeNode;
-    }
+    },
+
+    parent: function() {
+        return this.nativeNode.parentNode ? new ElementNode(this.nativeNode.parentNode) : null;
+    },
+
+    before: function(node) {
+        this._$.before(node.nativeNode);
+    },
+
+    wrapWith: function(node) {
+        if(this.parent())
+            this.before(node);
+        node.append(this);
+    },
 });
 
 var ElementNode = function(nativeNode) {
@@ -58,16 +72,16 @@ $.extend(ElementNode.prototype, DocumentNode.prototype, {
         return this._$.contents().index(node._$);
     },
 
-    parent: function() {
-        return new ElementNode(this._$.parent());
+    getAttr: function(name) {
+        return this._$.attr(name);
     },
 
-    append: function(documentNode) {
-        this._$.append(documentNode.nativeNode);
+    setAttr: function(name, value) {
+        this._$.attr(name, value);
     },
 
-    before: function(node) {
-        this._$.before(node.nativeNode);
+    append: function(documentNode) {
+        this._$.append(documentNode.nativeNode);
     },
 
     unwrapContent: function() {