From: Aleksander Ɓukasz Date: Sat, 13 Jul 2013 17:35:01 +0000 (+0200) Subject: Refactoring X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/ecf245195f18fa05ff987a10f8e26d53ba8f36ed?ds=inline Refactoring --- 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]);