accessing parents
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Fri, 5 Jul 2013 14:35:26 +0000 (16:35 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Fri, 5 Jul 2013 14:35:26 +0000 (16:35 +0200)
modules/documentCanvas/canvas/canvas.test3.js
modules/documentCanvas/canvas/documentElement.js

index b041bac..b6cc42e 100644 (file)
@@ -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('<section>Alice</section>'),
                     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('<section><div></div></section>'),
+                        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('<section>Alice</section>'),
+                        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('<section>Alice <span>has</span> a cat</section>'),
index 2225e0c..cd94759 100644 (file)
@@ -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];