From: Aleksander Ɓukasz Date: Fri, 5 Jul 2013 14:35:26 +0000 (+0200) Subject: accessing parents X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/35abf5d5c78b517329e313b1158f8b980940acd6 accessing parents --- 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];