X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/fadd66e0cc7a22d06a1d8f4ab08871fec8dafcdf..59b807cd7a781fad54e66f1e59b09369d91d53b4:/src/smartxml/smartxml.js?ds=inline diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index 40f3aad..e484070 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -100,6 +100,22 @@ $.extend(DocumentNode.prototype, { return node; }, + /** + * Removes parent of a node if node has no siblings. + */ + unwrap: function() { + if(this.isRoot()) { + return; + } + var parent = this.parent(), + grandParent; + if(parent.contents().length === 1) { + grandParent = parent.parent(); + parent.unwrapContent(); + return grandParent; + } + }, + triggerChangeEvent: function(type, metaData) { var event = new events.ChangeEvent(type, $.extend({node: this}, metaData || {})); if(type === 'nodeDetached' || this.document.containsNode(event.meta.node)) { @@ -120,6 +136,9 @@ $.extend(DocumentNode.prototype, { }, getIndex: function() { + if(this.isRoot()) { + return 0; + } return this.parent().indexOf(this); } }); @@ -239,6 +258,7 @@ $.extend(ElementNode.prototype, { myContents = this.contents(), myIdx = parent.indexOf(this); + if(myContents.length === 0) { return this.detach(); } @@ -275,22 +295,6 @@ $.extend(ElementNode.prototype, { }; }, - /** - * Removes parent of a node if node has no siblings. - */ - unwrap: function() { - if(this.isRoot()) { - return; - } - var parent = this.parent(), - grandParent; - if(parent.contents().length === 1) { - grandParent = parent.parent(); - parent.unwrapContent(); - return grandParent; - } - }, - wrapText: function(params) { return this.document._wrapText(_.extend({inside: this}, params)); },