From: Aleksander Ɓukasz Date: Sat, 13 Jul 2013 13:59:19 +0000 (+0200) Subject: Root DocumentElement has no parent X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/34ca0e947bbf0afdc520c025daabbe1221d69628?ds=inline Root DocumentElement has no parent --- 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) {