X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/e72654c4d22af93a05a8af98ab58cc44b152c6e7..06ff71dcb6c913a66280ebf812481224ee461f8c:/src/smartxml/smartxml.js?ds=sidebyside diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index b150cde..05583c5 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -91,13 +91,12 @@ $.extend(DocumentNode.prototype, { }), wrapWith: function(node) { - node = node instanceof ElementNode ? node : this.document.createElementNode(node); - + var insertion = this.getNodeInsertion(node); if(this.parent()) { - this.before(node); + this.before(insertion.ofNode); } - node.append(this); - return node; + insertion.ofNode.append(this); + return insertion.ofNode; }, /** @@ -136,6 +135,9 @@ $.extend(DocumentNode.prototype, { }, getIndex: function() { + if(this.isRoot()) { + return 0; + } return this.parent().indexOf(this); } }); @@ -255,6 +257,7 @@ $.extend(ElementNode.prototype, { myContents = this.contents(), myIdx = parent.indexOf(this); + if(myContents.length === 0) { return this.detach(); }