X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/3b0a39df2e007f33b027b665f0f42604aecfc8b9..58425daa1aa7e717e92eaec170262de31ed47bc0:/src/smartxml/smartxml.js diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index 53eefed..2e507db 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -29,7 +29,7 @@ $.extend(DocumentNode.prototype, { detach: function() { this._$.detach(); }, sameNode: function(otherNode) { - return this.nativeNode === otherNode.nativeNode; + return otherNode && this.nativeNode === otherNode.nativeNode; }, parent: function() { @@ -41,10 +41,13 @@ $.extend(DocumentNode.prototype, { }, wrapWith: function(node) { + node = node instanceof ElementNode ? node : this.document.createElementNode(node); + if(this.parent()) { this.before(node); } node.append(this); + return node; }, triggerChangeEvent: function(type, metaData) { @@ -211,14 +214,22 @@ $.extend(TextNode.prototype, DocumentNode.prototype, { 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); } }); @@ -237,7 +248,7 @@ $.extend(Document.prototype, Backbone.Events, { createElementNode: function(from) { if(!(from instanceof HTMLElement)) { - from = $('<' + from.tagName + '>'); + from = $('<' + from.tagName + '>')[0]; } return new this.ElementNodeFactory(from, this); },