From: Aleksander Ɓukasz Date: Mon, 18 Nov 2013 14:58:19 +0000 (+0100) Subject: smartxml: DocumentElement.parents X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/ed98b7046fe7f1e484bf9d58d3981054f4b06563?hp=198de8c828e46c2a849c56091146017a9f46f4f0 smartxml: DocumentElement.parents --- diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index 5ad3010..9a402cf 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -45,6 +45,15 @@ $.extend(DocumentNode.prototype, { return null; }, + parents: function() { + var parent = this.parent(), + parents = parent ? parent.parents() : []; + if(parent) { + parents.unshift(parent); + } + return parents; + }, + after: function(node) { var insertion = this.getNodeInsertion(node); this._$.after(insertion.ofNode.nativeNode); diff --git a/src/smartxml/smartxml.test.js b/src/smartxml/smartxml.test.js index df35a37..00c3ee9 100644 --- a/src/smartxml/smartxml.test.js +++ b/src/smartxml/smartxml.test.js @@ -496,6 +496,15 @@ describe('smartxml', function() { expect(a.parent()).to.equal(null, 'parent of a root is null'); expect(b.parent().sameNode(a)).to.be.true; }); + it('can access node parents', function() { + var doc = getDocumentFromXML(''), + a = doc.root, + b = a.contents()[0], + c = b.contents()[0]; + + var parents = c.parents(); + expect(parents).to.eql([b,a]); + }); }); });