From 1d25d2c941f5ffdc6e0824724db9a34960dc5450 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Thu, 11 Jul 2013 16:01:38 +0200 Subject: [PATCH 1/1] Fixing Canvas.getDocumentElement Handling text nodes properly --- modules/documentCanvas/canvas/canvas.js | 2 +- modules/documentCanvas/canvas/canvas.test3.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/modules/documentCanvas/canvas/canvas.js b/modules/documentCanvas/canvas/canvas.js index ad294b8..c4bfc09 100644 --- a/modules/documentCanvas/canvas/canvas.js +++ b/modules/documentCanvas/canvas/canvas.js @@ -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); } }, diff --git a/modules/documentCanvas/canvas/canvas.test3.js b/modules/documentCanvas/canvas/canvas.test3.js index 0d8e87a..9aab247 100644 --- a/modules/documentCanvas/canvas/canvas.test3.js +++ b/modules/documentCanvas/canvas/canvas.test3.js @@ -107,6 +107,22 @@ describe('Canvas', function() { expect(section.getWlxmlClass()).to.be.undefined; }); }); + + it('returns DocumentNodeElement instance from HTMLElement', function() { + var c = canvas.fromXML('
'), + 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('
Alice
'), + 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])); + }); }); -- 2.20.1