smartxml: setting text on text node
[fnpeditor.git] / src / smartxml / smartxml.js
index aa04fd7..53eefed 100644 (file)
@@ -100,7 +100,8 @@ $.extend(ElementNode.prototype, DocumentNode.prototype, {
 
     setTag: function(tagName) {
         var node = this.document.createElementNode({tagName: tagName}),
-            oldTagName = this.getTagName();
+            oldTagName = this.getTagName(),
+            myContents = this._$.contents();
 
         this.getAttrs().forEach(function(attribute) {
             node.setAttr(attribute.name, attribute.value, true);
@@ -112,6 +113,7 @@ $.extend(ElementNode.prototype, DocumentNode.prototype, {
         }
         this._$.replaceWith(node._$);
         this._setNativeNode(node._$[0]);
+        this._$.append(myContents);
         this.triggerChangeEvent('nodeTagChange', {oldTagName: oldTagName, newTagName: this.getTagName()});
     },
 
@@ -187,8 +189,12 @@ $.extend(ElementNode.prototype, DocumentNode.prototype, {
 
     toXML: function() {
         var wrapper = $('<div>');
-        wrapper.append(this._$);
+        wrapper.append(this._getXMLDOMToDump());
         return wrapper.html();
+    },
+    
+    _getXMLDOMToDump: function() {
+        return this._$;
     }
 });
 
@@ -203,6 +209,10 @@ $.extend(TextNode.prototype, DocumentNode.prototype, {
         return this.nativeNode.data;
     },
 
+    setText: function(text) {
+        this.nativeNode.data = text;
+    },
+
     appendText: function(text) {
         this.nativeNode.data = this.nativeNode.data + text;
     },
@@ -236,10 +246,12 @@ $.extend(Document.prototype, Backbone.Events, {
         return new this.TextNodeFactory(nativeNode, this);
     },
 
-    loadXML: function(xml) {
+    loadXML: function(xml, options) {
+        options = options || {};
         defineDocumentProperties(this, $(parseXML(xml)));
-        
-        this.trigger('contentSet');
+        if(!options.silent) {
+            this.trigger('contentSet');
+        }
     },
 
     toXML: function() {