From ed98b7046fe7f1e484bf9d58d3981054f4b06563 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Mon, 18 Nov 2013 15:58:19 +0100 Subject: [PATCH] smartxml: DocumentElement.parents --- src/smartxml/smartxml.js | 9 +++++++++ src/smartxml/smartxml.test.js | 9 +++++++++ 2 files changed, 18 insertions(+) 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]); + }); }); }); -- 2.20.1