Root DocumentElement has no parent
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Sat, 13 Jul 2013 13:59:19 +0000 (15:59 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Sat, 13 Jul 2013 13:59:19 +0000 (15:59 +0200)
modules/documentCanvas/canvas/canvas.test3.js
modules/documentCanvas/canvas/documentElement.js

index 6e120dd..bd47bf7 100644 (file)
@@ -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('<section></section>');
+                expect(c.doc().parent()).to.be.null;
+            });
+        });
+
         describe('DocumentTextElement', function() {
             it('can have its content set', function() {
                 var c = canvas.fromXML('<section>Alice</section>'),
index 8a50d23..0e2cb3d 100644 (file)
@@ -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) {