From: Aleksander Ɓukasz Date: Thu, 6 Mar 2014 11:06:53 +0000 (+0100) Subject: refactoring X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/8358d608397b9531d9d0b72c7b21ab78d078f066?ds=inline;hp=eb2569dfea00204192e8a69aa4599bd2ab46c51e refactoring --- diff --git a/src/editor/modules/documentCanvas/canvas/canvas.js b/src/editor/modules/documentCanvas/canvas/canvas.js index 44d3e6d..937d580 100644 --- a/src/editor/modules/documentCanvas/canvas/canvas.js +++ b/src/editor/modules/documentCanvas/canvas/canvas.js @@ -71,6 +71,11 @@ $.extend(Canvas.prototype, { this.reloadRoot(); }, + createElement: function(wlxmlNode) { + var Factory = wlxmlNode.nodeType === Node.TEXT_NODE ? documentElement.DocumentTextElement : documentElement.DocumentNodeElement; + return Factory.create(wlxmlNode, this); + }, + reloadRoot: function() { var canvasDOM = this.generateCanvasDOM(this.wlxmlDocument.root); //var canvasDOM = this.wlxmlDocument.root.getData('canvasElement') ? this.wlxmlDocument.root.getData('canvasElement').dom() : this.generateCanvasDOM(this.wlxmlDocument.root); diff --git a/src/editor/modules/documentCanvas/canvas/documentElement.js b/src/editor/modules/documentCanvas/canvas/documentElement.js index dbe6c48..0f49863 100644 --- a/src/editor/modules/documentCanvas/canvas/documentElement.js +++ b/src/editor/modules/documentCanvas/canvas/documentElement.js @@ -19,15 +19,7 @@ var DocumentElement = function(htmlElement, canvas) { }; -var elementTypeFromWlxmlNode = function(wlxmlNode) { - return wlxmlNode.nodeType === Node.TEXT_NODE ? DocumentTextElement : DocumentNodeElement; -}; - $.extend(DocumentElement, { - create: function(node, canvas) { - return elementTypeFromWlxmlNode(node).create(node, canvas); - }, - fromHTMLElement: function(htmlElement, canvas) { var $element = $(htmlElement); if(htmlElement.nodeType === Node.ELEMENT_NODE && $element.attr('document-node-element') !== undefined) { @@ -167,7 +159,7 @@ $.extend(DocumentNodeElement, { element.setWlxml({tag: wlxmlNode.getTagName(), klass: wlxmlNode.getClass()}); wlxmlNode.contents().forEach(function(node) { - container.append(DocumentElement.create(node, canvas).dom()); + container.append(canvas.createElement(node).dom()); }.bind(this)); return element; @@ -179,7 +171,7 @@ var manipulate = function(e, params, action) { if(params instanceof DocumentElement) { element = params; } else { - element = DocumentElement.create(params); + element = e.canvas.createElement(params); } var target = (action === 'append' || action === 'prepend') ? e._container() : e.dom(); target[action](element.dom()); @@ -380,7 +372,7 @@ $.extend(DocumentTextElement.prototype, { if(params instanceof DocumentNodeElement) { element = params; } else { - element = DocumentElement.create(params, this.canvas); + element = this.canvas.createElement(params); } this.dom().wrap('
'); this.dom().parent().after(element.dom()); @@ -395,7 +387,7 @@ $.extend(DocumentTextElement.prototype, { if(params instanceof DocumentNodeElement) { element = params; } else { - element = DocumentNodeElement.create(params, this.canvas); + element = this.canvas.createElement(params, this.canvas); } this.dom().wrap('
'); this.dom().parent().before(element.dom());