Refactoring
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 10 Oct 2013 14:29:26 +0000 (16:29 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Mon, 2 Dec 2013 13:50:52 +0000 (14:50 +0100)
src/editor/modules/documentCanvas/canvas/canvas.js
src/editor/modules/documentCanvas/canvas/utils.js

index bf68ede..8b94782 100644 (file)
@@ -32,26 +32,9 @@ $.extend(Canvas.prototype, {
 
         var canvas = this;
 
 
         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) {
         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);
                 }
                 if(event.type === 'nodeAttrChange' && event.meta.attr === 'class') {
                     canvasNode.setWlxmlClass(event.meta.newVal);
                 }
index 0eb19d0..87911cf 100644 (file)
@@ -19,8 +19,26 @@ var nearestInDocumentOrder = function(selector, direction, element) {
     return null;
 }
 
     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,
 return {
     nearestInDocumentOrder: nearestInDocumentOrder,
+    findCanvasElement: findCanvasElement,
     unicode: {
         ZWS: '\u200B'
     }
     unicode: {
         ZWS: '\u200B'
     }