From 35abf5d5c78b517329e313b1158f8b980940acd6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Fri, 5 Jul 2013 16:35:26 +0200 Subject: [PATCH] accessing parents --- modules/documentCanvas/canvas/canvas.test3.js | 16 ++++++++++++++++ modules/documentCanvas/canvas/documentElement.js | 3 +++ 2 files changed, 19 insertions(+) diff --git a/modules/documentCanvas/canvas/canvas.test3.js b/modules/documentCanvas/canvas/canvas.test3.js index b041bac..b6cc42e 100644 --- a/modules/documentCanvas/canvas/canvas.test3.js +++ b/modules/documentCanvas/canvas/canvas.test3.js @@ -57,12 +57,28 @@ describe('Canvas', function() { expect(children[0]).to.be.instanceOf(documentElement.DocumentNodeElement); expect(children[1]).to.be.instanceOf(documentElement.DocumentNodeElement); }); + it('reports text nodes', function() { var c = canvas.fromXML('
Alice
'), children = c.doc().children(); expect(children.length).to.equal(1); expect(children[0]).to.be.instanceOf(documentElement.DocumentTextElement); }); + + describe('accessing parents', function() { + it('returns DocumentNodeElement representing parent in wlxml document as DocumentNodeElement parent', function() { + var c = canvas.fromXML('
'), + div = c.doc().children()[0]; + expect(div.parent().sameNode(c.doc())).to.be.true; + }); + it('returns DocumentNodeElement representing parent in wlxml document as DocumentTextElement parent', function() { + var c = canvas.fromXML('
Alice
'), + text = c.doc().children()[0]; + expect(text.parent().sameNode(c.doc())).to.be.true; + }); + }); + + describe('free text handling', function() { it('sees free text', function() { var c = canvas.fromXML('
Alice has a cat
'), diff --git a/modules/documentCanvas/canvas/documentElement.js b/modules/documentCanvas/canvas/documentElement.js index 2225e0c..cd94759 100644 --- a/modules/documentCanvas/canvas/documentElement.js +++ b/modules/documentCanvas/canvas/documentElement.js @@ -32,6 +32,9 @@ $.extend(DocumentElement.prototype, { }); return toret; }, + parent: function() { + return documentElementFromHTMLElement(this.$element.parent()[0]); + }, sameNode: function(other) { return other && (typeof other === typeof this) && other.$element[0] === this.$element[0]; -- 2.20.1