X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/0032858d24ed6dba11f8943072cd6db475a2dd17..72da90cac0feafb35cac9292105e24f2b5094b45:/src/smartxml/smartxml.js diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index a583848..0e05293 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -40,6 +40,26 @@ $.extend(DocumentNode.prototype, { return this.document.createDocumentNode(this._$.clone(true, true)[0]); }, + getPath: function(ancestor) { + var nodePath = [this].concat(this.parents()), + toret, idx; + ancestor = ancestor || this.document.root; + + nodePath.some(function(node, i) { + if(node.sameNode(ancestor)) { + idx = i; + return true; + } + }); + + if(idx !== 'undefined') { + nodePath = nodePath.slice(0, idx); + } + toret = nodePath.map(function(node) {return node.getIndex(); }); + toret.reverse(); + return toret; + }, + isRoot: function() { return this.document.root.sameNode(this); },