X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/70fd8f6118a3e8bf298dd9c48c310f3309b780c3..06f085a7b35932bcf2c83b3279d5adc687de908c:/modules/visualEditor.js diff --git a/modules/visualEditor.js b/modules/visualEditor.js index 08085de..38f3302 100644 --- a/modules/visualEditor.js +++ b/modules/visualEditor.js @@ -4,14 +4,30 @@ rng.modules.visualEditor = function(sandbox) { var view = { node: $(sandbox.getTemplate('main')()), setup: function() { - var node = this.node; - node.find('#rng-visualEditor-content').on('keyup', function() { + var view = this; + + this.node.find('#rng-visualEditor-content').on('keyup', function() { isDirty = true; }); - node.find('#rng-visualEditor-meta').on('keyup', function() { + this.node.find('#rng-visualEditor-meta').on('keyup', function() { isDirty = true; }); + + this.node.on('mouseover', '.rng', function(e) { $(e.target).addClass('rng-hover')}); + this.node.on('mouseout', '.rng', function(e) { $(e.target).removeClass('rng-hover')}); + this.node.on('click', '.rng', function(e) { + view._markSelected($(e.target)); + }); + + this.node.on('keyup', function(e) { + var anchor = $(window.getSelection().anchorNode); + if(anchor[0].nodeType === Node.TEXT_NODE) + anchor = anchor.parent(); + if(!anchor.hasClass('rng')) + return; + view._markSelected(anchor); + }); }, getMetaData: function() { var toret = {}; @@ -36,7 +52,11 @@ rng.modules.visualEditor = function(sandbox) { }, getBody: function() { return this.node.find('#rng-visualEditor-content').html(); - } + }, + _markSelected: function(node) { + this.node.find('.rng').removeClass('rng-current'); + node.addClass('rng-current'); + } }; view.setup();