X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/b58b8f498d9b5e70aec099829b97af2c4d72da10..c8ea3d532e8a081a32838b09cfe268a5b2fa7302:/modules/documentCanvas/documentCanvas.js diff --git a/modules/documentCanvas/documentCanvas.js b/modules/documentCanvas/documentCanvas.js index ac978f2..55c8d7e 100644 --- a/modules/documentCanvas/documentCanvas.js +++ b/modules/documentCanvas/documentCanvas.js @@ -3,7 +3,8 @@ define([ 'libs/underscore-min', './transformations', -'libs/text!./template.html'], function(_, transformations, template) { +'./wlxmlNode', +'libs/text!./template.html'], function(_, transformations, wlxmlNode, template) { @@ -20,11 +21,18 @@ return function(sandbox) { sandbox.publish('contentChanged'); }); - this.node.on('mouseover', '[wlxml-tag]', function(e) { sandbox.publish('nodeHovered', $(e.target)); }); - this.node.on('mouseout', '[wlxml-tag]', function(e) { sandbox.publish('nodeBlured', $(e.target)); }); + this.node.on('mouseover', '[wlxml-tag]', function(e) { + e.stopPropagation(); + sandbox.publish('nodeHovered', new wlxmlNode.Node($(e.target))); + }); + this.node.on('mouseout', '[wlxml-tag]', function(e) { + e.stopPropagation(); + sandbox.publish('nodeBlured', new wlxmlNode.Node($(e.target))); + }); this.node.on('click', '[wlxml-tag]', function(e) { + e.stopPropagation(); console.log('clicked node type: '+e.target.nodeType); - view._markSelected($(e.target)); + view._markSelected(new wlxmlNode.Node($(e.target))); }); this.node.on('keyup', '#rng-module-documentCanvas-contentWrapper', function(e) { @@ -33,7 +41,7 @@ return function(sandbox) { anchor = anchor.parent(); if(!anchor.is('[wlxml-tag]')) return; - view._markSelected(anchor); + view._markSelected(new wlxmlNode.Node(anchor)); }); this.node.on('keydown', '#rng-module-documentCanvas-contentWrapper', function(e) { @@ -157,9 +165,10 @@ return function(sandbox) { _markSelected: function(node) { this.dimNode(node); - this.node.find('.rng-current').removeClass('rng-current'); - node.addClass('rng-current'); + this.node.find('.rng-module-documentCanvas-currentNode').removeClass('rng-module-documentCanvas-currentNode'); + + this.getNodeElement(node).addClass('rng-module-documentCanvas-currentNode'); this.currentNode = node; sandbox.publish('nodeSelected', node); @@ -168,44 +177,31 @@ return function(sandbox) { selectNode: function(node) { view._markSelected(node); var range = document.createRange(); - range.selectNodeContents(node[0]); + range.selectNodeContents(this.getNodeElement(node)[0]); range.collapse(false); var selection = document.getSelection(); selection.removeAllRanges() selection.addRange(range); }, - selectNodeById: function(id) { - var node = this.node.find('#'+id); - if(node) - this.selectNode(node); - }, highlightNode: function(node) { + node = this.getNodeElement(node); if(!this.gridToggled) { - node.addClass('rng-hover'); + node.addClass('rng-common-hoveredNode'); var label = node.attr('wlxml-tag'); if(node.attr('wlxml-class')) label += ' / ' + node.attr('wlxml-class'); - var tag = $('
').addClass('rng-visualEditor-nodeHoverTag').text(label); + var tag = $('
').addClass('rng-module-documentCanvas-hoveredNodeTag').text(label); node.append(tag); } }, dimNode: function(node) { + node = this.getNodeElement(node); if(!this.gridToggled) { - node.removeClass('rng-hover'); - node.find('.rng-visualEditor-nodeHoverTag').remove(); + node.removeClass('rng-common-hoveredNode'); + node.find('.rng-module-documentCanvas-hoveredNodeTag').remove(); } }, - highlightNodeById: function(id) { - var node = this.node.find('#'+id); - if(node) - this.highlightNode(node); - }, - dimNodeById: function(id) { - var node = this.node.find('#'+id); - if(node) - this.dimNode(node); - }, selectFirstNode: function() { var firstNodeWithText = this.node.find('[wlxml-tag]').filter(function() { return $(this).clone().children().remove().end().text().trim() !== ''; @@ -216,11 +212,14 @@ return function(sandbox) { else { node = this.node.find('[wlxml-class|="p"]') } - this.selectNode(node); + this.selectNode(new wlxmlNode.Node(node)); }, toggleGrid: function(toggle) { - this.node.find('[wlxml-tag]').toggleClass('rng-hover', toggle); + this.node.find('[wlxml-tag]').toggleClass('rng-common-hoveredNode', toggle); this.gridToggled = toggle; + }, + getNodeElement: function(wlxmlNode) { + return this.node.find('#'+wlxmlNode.id); } }; @@ -240,14 +239,14 @@ return function(sandbox) { if(view.currentNode) view.currentNode.attr('wlxml-'+attr, value); }, - highlightNode: function(id) { - view.highlightNodeById(id); + highlightNode: function(wlxmlNode) { + view.highlightNode(wlxmlNode); }, - dimNode: function(id) { - view.dimNodeById(id); + dimNode: function(wlxmlNode) { + view.dimNode(wlxmlNode); }, - selectNode: function(id) { - view.selectNodeById(id); + selectNode: function(wlxmlNode) { + view.selectNode(wlxmlNode); }, toggleGrid: function(toggle) { view.toggleGrid(toggle);