X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/512fcabb2a882e26649612efb2b91f25cfc02ec3..36de4837650d53704c67a9f23a4d68b1287b03ec:/src/smartxml/smartxml.js diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index cb90e74..9a3ba26 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -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(); }