From 24ac4f5092661ce053f33d460306bf81d6a3dc8a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Thu, 10 Oct 2013 16:29:26 +0200 Subject: [PATCH 1/1] Refactoring --- .../modules/documentCanvas/canvas/canvas.js | 19 +------------------ .../modules/documentCanvas/canvas/utils.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/editor/modules/documentCanvas/canvas/canvas.js b/src/editor/modules/documentCanvas/canvas/canvas.js index bf68ede..8b94782 100644 --- a/src/editor/modules/documentCanvas/canvas/canvas.js +++ b/src/editor/modules/documentCanvas/canvas/canvas.js @@ -32,26 +32,9 @@ $.extend(Canvas.prototype, { var canvas = this; - var findCanvasElement = function(node) { - if(node.nodeType === Node.ELEMENT_NODE) { - return node.getData('canvasElement'); - } - if(node.nodeType === Node.TEXT_NODE) { - var parent = node.parent(), - toret; - - parent.children().forEach(function(child) { - if(child.data('wlxmlNode').sameNode(node)) - toret = child; - }); - if(toret) - return toret; - } - } - if(this.wlxmlDocument !== wlxmlDocument) { wlxmlDocument.on('change', function(event) { - var canvasNode = findCanvasElement(event.meta.node); + var canvasNode = utils.findCanvasElement(event.meta.node); if(event.type === 'nodeAttrChange' && event.meta.attr === 'class') { canvasNode.setWlxmlClass(event.meta.newVal); } diff --git a/src/editor/modules/documentCanvas/canvas/utils.js b/src/editor/modules/documentCanvas/canvas/utils.js index 0eb19d0..87911cf 100644 --- a/src/editor/modules/documentCanvas/canvas/utils.js +++ b/src/editor/modules/documentCanvas/canvas/utils.js @@ -19,8 +19,26 @@ var nearestInDocumentOrder = function(selector, direction, element) { return null; } +var findCanvasElement = function(node) { + if(node.nodeType === Node.ELEMENT_NODE) { + return node.getData('canvasElement'); + } + if(node.nodeType === Node.TEXT_NODE) { + var parent = node.parent(), + toret; + + parent.children().forEach(function(child) { + if(child.data('wlxmlNode').sameNode(node)) + toret = child; + }); + if(toret) + return toret; + } +}; + return { nearestInDocumentOrder: nearestInDocumentOrder, + findCanvasElement: findCanvasElement, unicode: { ZWS: '\u200B' } -- 2.20.1