X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/58425daa1aa7e717e92eaec170262de31ed47bc0..6a5fbef4db2934efd05c251124bd2b62180fe549:/src/smartxml/smartxml.js diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index 2e507db..a396d3e 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -36,8 +36,16 @@ $.extend(DocumentNode.prototype, { return this.nativeNode.parentNode ? this.document.createElementNode(this.nativeNode.parentNode) : null; }, + after: function(node) { + node = node instanceof ElementNode ? node : this.document.createElementNode(node); + this._$.after(node.nativeNode); + return node; + }, + before: function(node) { + node = node instanceof ElementNode ? node : this.document.createElementNode(node); this._$.before(node.nativeNode); + return node; }, wrapWith: function(node) { @@ -59,8 +67,9 @@ $.extend(DocumentNode.prototype, { var ElementNode = function(nativeNode, document) { DocumentNode.call(this, nativeNode, document); }; +ElementNode.prototype = Object.create(DocumentNode.prototype); -$.extend(ElementNode.prototype, DocumentNode.prototype, { +$.extend(ElementNode.prototype, { nodeType: Node.ELEMENT_NODE, setData: function(key, value) { @@ -204,8 +213,9 @@ $.extend(ElementNode.prototype, DocumentNode.prototype, { var TextNode = function(nativeNode, document) { DocumentNode.call(this, nativeNode, document); }; +TextNode.prototype = Object.create(DocumentNode.prototype); -$.extend(TextNode.prototype, DocumentNode.prototype, { +$.extend(TextNode.prototype, { nodeType: Node.TEXT_NODE, getText: function() { @@ -248,7 +258,11 @@ $.extend(Document.prototype, Backbone.Events, { createElementNode: function(from) { if(!(from instanceof HTMLElement)) { - from = $('<' + from.tagName + '>')[0]; + if(from.text) { + from = document.createTextNode(from.text); + } else { + from = $('<' + from.tagName + '>')[0]; + } } return new this.ElementNodeFactory(from, this); },