smartxml: changing TextNode text emits nodeTextChange event
[fnpeditor.git] / src / smartxml / smartxml.js
index f4aa9fe..6e00a7d 100644 (file)
@@ -209,12 +209,24 @@ $.extend(TextNode.prototype, DocumentNode.prototype, {
         return this.nativeNode.data;
     },
 
+    setText: function(text) {
+        this.nativeNode.data = text;
+        this.triggerTextChangeEvent();
+    },
+
     appendText: function(text) {
         this.nativeNode.data = this.nativeNode.data + text;
+        this.triggerTextChangeEvent();
     },
 
     prependText: function(text) {
         this.nativeNode.data = text + this.nativeNode.data;
+        this.triggerTextChangeEvent();
+    },
+
+    triggerTextChangeEvent: function() {
+        var event = new events.ChangeEvent('nodeTextChange', {node: this});
+        this.document.trigger('change', event);
     }
 });
 
@@ -242,10 +254,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() {