From: Aleksander Ɓukasz Date: Thu, 11 Jul 2013 14:01:38 +0000 (+0200) Subject: Fixing Canvas.getDocumentElement X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/1d25d2c941f5ffdc6e0824724db9a34960dc5450?ds=inline Fixing Canvas.getDocumentElement Handling text nodes properly --- 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])); + }); });