Refactoring
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Tue, 11 Jun 2013 08:51:59 +0000 (10:51 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Tue, 11 Jun 2013 08:51:59 +0000 (10:51 +0200)
modules/documentCanvas/documentCanvas.js

index 55c8d7e..1b919ee 100644 (file)
@@ -32,7 +32,7 @@ return function(sandbox) {
             this.node.on('click', '[wlxml-tag]', function(e) {\r
                 e.stopPropagation();\r
                 console.log('clicked node type: '+e.target.nodeType);\r
-                view._markSelected(new wlxmlNode.Node($(e.target)));\r
+                view.selectNode(new wlxmlNode.Node($(e.target)));\r
             });\r
 \r
             this.node.on('keyup', '#rng-module-documentCanvas-contentWrapper', function(e) {\r
@@ -41,7 +41,7 @@ return function(sandbox) {
                     anchor = anchor.parent();\r
                 if(!anchor.is('[wlxml-tag]'))\r
                     return;\r
-                view._markSelected(new wlxmlNode.Node(anchor));\r
+                view.selectNode(new wlxmlNode.Node(anchor));\r
             });\r
             \r
             this.node.on('keydown', '#rng-module-documentCanvas-contentWrapper', function(e) {\r
@@ -162,27 +162,25 @@ return function(sandbox) {
         getBody: function() {\r
             return this.node.find('#rng-module-documentCanvas-content').html();\r
         }, \r
-        _markSelected: function(node) {\r
+        selectNode: function(node, options) {\r
+            options = options || {};\r
             this.dimNode(node);\r
             \r
-            \r
             this.node.find('.rng-module-documentCanvas-currentNode').removeClass('rng-module-documentCanvas-currentNode');\r
-            \r
             this.getNodeElement(node).addClass('rng-module-documentCanvas-currentNode');\r
-\r
             this.currentNode = node;\r
-            sandbox.publish('nodeSelected', node);\r
             \r
-        },\r
-        selectNode: function(node) {\r
-            view._markSelected(node);\r
-            var range = document.createRange();\r
-            range.selectNodeContents(this.getNodeElement(node)[0]);\r
-            range.collapse(false);\r
+            if(options.doFocus) {\r
+                var range = document.createRange();\r
+                range.selectNodeContents(this.getNodeElement(node)[0]);\r
+                range.collapse(false);\r
 \r
-            var selection = document.getSelection();\r
-            selection.removeAllRanges()\r
-            selection.addRange(range);\r
+                var selection = document.getSelection();\r
+                selection.removeAllRanges()\r
+                selection.addRange(range);\r
+            }\r
+            \r
+            sandbox.publish('nodeSelected', node);\r
         },\r
         highlightNode: function(node) {\r
             node = this.getNodeElement(node);\r
@@ -246,7 +244,7 @@ return function(sandbox) {
             view.dimNode(wlxmlNode);\r
         },\r
         selectNode: function(wlxmlNode) {\r
-            view.selectNode(wlxmlNode);\r
+            view.selectNode(wlxmlNode, {doFocus: true});\r
         },\r
         toggleGrid: function(toggle) {\r
             view.toggleGrid(toggle);\r