From 34ca0e947bbf0afdc520c025daabbe1221d69628 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Sat, 13 Jul 2013 15:59:19 +0200 Subject: [PATCH] Root DocumentElement has no parent --- modules/documentCanvas/canvas/canvas.test3.js | 7 +++++++ modules/documentCanvas/canvas/documentElement.js | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/documentCanvas/canvas/canvas.test3.js b/modules/documentCanvas/canvas/canvas.test3.js index 6e120dd..bd47bf7 100644 --- a/modules/documentCanvas/canvas/canvas.test3.js +++ b/modules/documentCanvas/canvas/canvas.test3.js @@ -71,6 +71,13 @@ describe('Canvas', function() { expect(c.doc().getWlxmlTag()).to.equal('section'); }); + describe('root element', function() { + it('has no parent', function() { + var c = canvas.fromXML('
'); + expect(c.doc().parent()).to.be.null; + }); + }); + describe('DocumentTextElement', function() { it('can have its content set', function() { var c = canvas.fromXML('
Alice
'), diff --git a/modules/documentCanvas/canvas/documentElement.js b/modules/documentCanvas/canvas/documentElement.js index 8a50d23..0e2cb3d 100644 --- a/modules/documentCanvas/canvas/documentElement.js +++ b/modules/documentCanvas/canvas/documentElement.js @@ -19,7 +19,10 @@ $.extend(DocumentElement.prototype, { return this.$element; }, parent: function() { - return documentElementFromHTMLElement(this.$element.parent()[0], this.canvas); + var parents = this.$element.parents('[wlxml-tag]'); + if(parents.length) + return documentElementFromHTMLElement(parents[0], this.canvas); + return null; }, sameNode: function(other) { -- 2.20.1