From ecf245195f18fa05ff987a10f8e26d53ba8f36ed Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Sat, 13 Jul 2013 19:35:01 +0200 Subject: [PATCH 1/1] Refactoring --- .../documentCanvas/canvas/documentElement.js | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/modules/documentCanvas/canvas/documentElement.js b/modules/documentCanvas/canvas/documentElement.js index 82a85c7..bef9fdd 100644 --- a/modules/documentCanvas/canvas/documentElement.js +++ b/modules/documentCanvas/canvas/documentElement.js @@ -59,7 +59,7 @@ var manipulate = function(e, params, action) { if(params instanceof DocumentElement) { dom = params.dom() } else { - dom = DocumentNodeElement.createDOM(params); + dom = DocumentElement.createDOM(params); } e.dom()[action](dom); return documentElementFromHTMLElement(dom); @@ -132,18 +132,21 @@ $.extend(DocumentNodeElement.prototype, { } }); +DocumentElement.createDOM = function(params) { + var ElementType = params.text !== undefined ? DocumentTextElement : DocumentNodeElement; + return ElementType.createDOM(params); +}; + DocumentNodeElement.createDOM = function(params) { - var dom; - if(params.text) { - dom = $(document.createTextNode(params.text)); - } else { - dom = $('
').attr('wlxml-tag', params.tag); - if(params.klass) - dom.attr('wlxml-class', params.klass); - } + var dom = $('
').attr('wlxml-tag', params.tag); + if(params.klass) + dom.attr('wlxml-class', params.klass); return dom; }; +DocumentTextElement.createDOM = function(params) { + return $(document.createTextNode(params.text)); +}; DocumentNodeElement.create = function(params, canvas) { return documentElementFromHTMLElement(DocumentNodeElement.createDOM(params)[0]); -- 2.20.1