From: Aleksander Ɓukasz Date: Thu, 10 Oct 2013 14:29:26 +0000 (+0200) Subject: Refactoring X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/24ac4f5092661ce053f33d460306bf81d6a3dc8a?hp=5713cbab555401cab4cb69012bf1d5ec47153982 Refactoring --- 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' }