From a09318d74185278fa556af4a997e94b0d6999193 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Tue, 16 Apr 2013 17:02:32 +0200 Subject: [PATCH] Visual editor: marking nodes as selected on keyboard events --- modules/visualEditor.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/modules/visualEditor.js b/modules/visualEditor.js index ce62c6a..38f3302 100644 --- a/modules/visualEditor.js +++ b/modules/visualEditor.js @@ -4,20 +4,29 @@ 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) { - node.find('.rng').removeClass('rng-current'); - $(e.target).addClass('rng-current'); + 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() { @@ -43,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(); -- 2.20.1