Fixing Canvas.getDocumentElement
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 11 Jul 2013 14:01:38 +0000 (16:01 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 11 Jul 2013 14:01:38 +0000 (16:01 +0200)
Handling text nodes properly

modules/documentCanvas/canvas/canvas.js
modules/documentCanvas/canvas/canvas.test3.js

index ad294b8..c4bfc09 100644 (file)
@@ -116,7 +116,7 @@ $.extend(Canvas.prototype, {
         return wrapperElement;
     },
     getDocumentElement: function(from) {
-        if(from instanceof HTMLElement) {
+        if(from instanceof HTMLElement || from instanceof Text) {
            return documentElement.wrap(from, this);
         }
     },
index 0d8e87a..9aab247 100644 (file)
@@ -107,6 +107,22 @@ describe('Canvas', function() {
                 expect(section.getWlxmlClass()).to.be.undefined;
             });
         });
+
+        it('returns DocumentNodeElement instance from HTMLElement', function() {
+            var c = canvas.fromXML('<section></section>'),
+                htmlElement = c.doc().dom().get(0),
+                element = c.getDocumentElement(htmlElement);
+            expect(element).to.be.instanceOf(documentElement.DocumentNodeElement);
+            expect(element.sameNode(c.doc()));
+        });
+        
+        it('returns DocumentTextElement instance from Text Node', function() {
+            var c = canvas.fromXML('<section>Alice</section>'),
+                textNode = c.doc().children(0)[0].dom().get(0),
+                element = c.getDocumentElement(textNode);
+            expect(element).to.be.instanceOf(documentElement.DocumentTextElement);
+            expect(element.sameNode(c.doc().children()[0]));
+        });
     });