From e923d179bfd4a70dc7df8e128063ed2a3284fc4f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Tue, 11 Jun 2013 11:02:08 +0200 Subject: [PATCH] Refactoring --- modules/documentCanvas/documentCanvas.js | 43 ++++++++++++------------ 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/modules/documentCanvas/documentCanvas.js b/modules/documentCanvas/documentCanvas.js index 1b919ee..05fbcdd 100644 --- a/modules/documentCanvas/documentCanvas.js +++ b/modules/documentCanvas/documentCanvas.js @@ -162,42 +162,43 @@ return function(sandbox) { getBody: function() { return this.node.find('#rng-module-documentCanvas-content').html(); }, - selectNode: function(node, options) { + selectNode: function(wlxmlNode, options) { options = options || {}; - this.dimNode(node); + var nodeElement = this.getNodeElement(wlxmlNode) - this.node.find('.rng-module-documentCanvas-currentNode').removeClass('rng-module-documentCanvas-currentNode'); - this.getNodeElement(node).addClass('rng-module-documentCanvas-currentNode'); - this.currentNode = node; + this.dimNode(wlxmlNode); - if(options.doFocus) { + this.node.find('.rng-module-documentCanvas-currentNode').removeClass('rng-module-documentCanvas-currentNode'); + nodeElement.addClass('rng-module-documentCanvas-currentNode'); + + if(options.moveCarret) { var range = document.createRange(); - range.selectNodeContents(this.getNodeElement(node)[0]); + range.selectNodeContents(nodeElement[0]); range.collapse(false); - var selection = document.getSelection(); selection.removeAllRanges() selection.addRange(range); } - sandbox.publish('nodeSelected', node); + this.currentNode = wlxmlNode; + sandbox.publish('nodeSelected', wlxmlNode); }, - highlightNode: function(node) { - node = this.getNodeElement(node); + highlightNode: function(wlxmlNode) { + var nodeElement = this.getNodeElement(wlxmlNode); if(!this.gridToggled) { - node.addClass('rng-common-hoveredNode'); - var label = node.attr('wlxml-tag'); - if(node.attr('wlxml-class')) - label += ' / ' + node.attr('wlxml-class'); + nodeElement.addClass('rng-common-hoveredNode'); + var label = nodeElement.attr('wlxml-tag'); + if(nodeElement.attr('wlxml-class')) + label += ' / ' + nodeElement.attr('wlxml-class'); var tag = $('
').addClass('rng-module-documentCanvas-hoveredNodeTag').text(label); - node.append(tag); + nodeElement.append(tag); } }, - dimNode: function(node) { - node = this.getNodeElement(node); + dimNode: function(wlxmlNode) { + var nodeElement = this.getNodeElement(wlxmlNode); if(!this.gridToggled) { - node.removeClass('rng-common-hoveredNode'); - node.find('.rng-module-documentCanvas-hoveredNodeTag').remove(); + nodeElement.removeClass('rng-common-hoveredNode'); + nodeElement.find('.rng-module-documentCanvas-hoveredNodeTag').remove(); } }, selectFirstNode: function() { @@ -244,7 +245,7 @@ return function(sandbox) { view.dimNode(wlxmlNode); }, selectNode: function(wlxmlNode) { - view.selectNode(wlxmlNode, {doFocus: true}); + view.selectNode(wlxmlNode, {moveCarret: true}); }, toggleGrid: function(toggle) { view.toggleGrid(toggle); -- 2.20.1