smartxml: tests refactoring
[fnpeditor.git] / src / smartxml / smartxml.js
index cb90e74..9a3ba26 100644 (file)
@@ -107,6 +107,7 @@ $.extend(ElementNode.prototype, DocumentNode.prototype, {
         });
         node.setData(this.getData());
 
+        this._$.replaceWith(node._$);
         this._setNativeNode(node._$[0]);
         this.triggerChangeEvent('nodeTagChange', {oldTagName: oldTagName, newTagName: this.getTagName()});
     },
@@ -214,16 +215,9 @@ var parseXML = function(xml) {
 };
 
 var Document = function(xml) {
-    var $document = $(parseXML(xml));
-
-    var doc = this;
-    Object.defineProperty(this, 'root', {get: function() {
-        return doc.createElementNode($document[0]);
-    }});
-    Object.defineProperty(this, 'dom', {get: function() {
-        return $document[0];
-    }});
+    this.loadXML(xml);
 };
+
 $.extend(Document.prototype, Backbone.Events, {
     ElementNodeFactory: ElementNode,
     TextNodeFactory: TextNode,
@@ -239,6 +233,20 @@ $.extend(Document.prototype, Backbone.Events, {
         return new this.TextNodeFactory(nativeNode, this);
     },
 
+    loadXML: function(xml) {
+        var $document = $(parseXML(xml));
+
+        var doc = this;
+        Object.defineProperty(this, 'root', {get: function() {
+            return doc.createElementNode($document[0]);
+        }, configurable: true});
+        Object.defineProperty(this, 'dom', {get: function() {
+            return $document[0];
+        }, configurable: true});
+        
+        this.trigger('contentSet');
+    },
+
     toXML: function() {
         return this.root.toXML();
     }