From 9e002baeb5e2770411e46b9dfd91e1bb26d4d668 Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Thu, 12 Mar 2015 00:33:53 +0200 Subject: client: use some more VK constants --- src/client/robot.js | 7 ++++--- src/client/view/node_info.js | 6 +++--- src/client/view/search.js | 6 +++--- src/client/view/svg_input.js | 8 ++++---- src/client/view/textanalyser_input.js | 5 +++-- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/client/robot.js b/src/client/robot.js index 700e41b6..cfe13482 100644 --- a/src/client/robot.js +++ b/src/client/robot.js @@ -1,4 +1,5 @@ -define(['jquery'], function($) { +define(['jquery', 'consts'], +function($, consts) { var sentence=""; /*sentence+=" #Rhizibot is showing you a #tutorial|"; @@ -47,8 +48,8 @@ var robot = function (element, sentence) { } } else { var e = jQuery.Event("keypress"); - e.which = 13; - e.keyCode = 13; + e.which = consts.VK_ENTER; + e.keyCode = consts.VK_ENTER; $("#textanalyser").trigger(e); window.setTimeout( r.next_event, 650/r.speed ); } diff --git a/src/client/view/node_info.js b/src/client/view/node_info.js index d2b23e72..ef853a94 100644 --- a/src/client/view/node_info.js +++ b/src/client/view/node_info.js @@ -1,5 +1,5 @@ -define(['jquery', 'jquery-ui', 'util', 'view/helpers', 'view/internal', 'model/diff', 'model/types'], -function($, _unused_jquery_ui, util, view_helpers, internal, model_diff, model_types) { +define(['jquery', 'jquery-ui', 'util', 'consts', 'view/helpers', 'view/internal', 'model/diff', 'model/types'], +function($, _unused_jquery_ui, util, consts, view_helpers, internal, model_diff, model_types) { var d = null, msg_node = $('.info-card-message'), @@ -113,7 +113,7 @@ function setup_click_handlers() } setup_done = true; form_element.on('keydown', function (e) { - if (e.which == 13 && e.target !== delete_button[0]) { + if (e.which == consts.VK_ENTER && e.target !== delete_button[0]) { e.preventDefault(); } }); diff --git a/src/client/view/search.js b/src/client/view/search.js index e74877a2..39b84dd6 100644 --- a/src/client/view/search.js +++ b/src/client/view/search.js @@ -1,5 +1,5 @@ -define(['view/completer', 'textanalysis', 'rz_core', 'view/selection'], -function( completer, textanalysis, rz_core, selection) +define(['consts', 'view/completer', 'textanalysis', 'rz_core', 'view/selection'], +function(consts, completer, textanalysis, rz_core, selection) { var search, search_completer; @@ -21,7 +21,7 @@ function init() { search.asEventStream('input') .merge(search.asEventStream('keydown').filter( function(e) { - if (e.which == 13 && !search_completer.handleEnter()) { + if (e.which == consts.VK_ENTER && !search_completer.handleEnter()) { e.preventDefault(); return false; } diff --git a/src/client/view/svg_input.js b/src/client/view/svg_input.js index db9e190e..1810d814 100644 --- a/src/client/view/svg_input.js +++ b/src/client/view/svg_input.js @@ -1,5 +1,5 @@ -define(['jquery', 'Bacon_wrapper', 'model/diff', 'rz_bus', 'consts'], -function($, Bacon, model_diff, rz_bus, consts) +define(['jquery', 'Bacon_wrapper', 'consts', 'model/diff', 'rz_bus', 'consts'], +function($, Bacon, consts, model_diff, rz_bus, consts) { var svg_input_fo_node_y = '-.70em', svg_input_fo_height = '30px'; @@ -65,10 +65,10 @@ var svgInput = function(vis, graph) { console.log('unexpected editname_on_keypress this should be the svg-input element'); } - if (e.which == 13 || e.which == 27) { + if (e.which == consts.VK_ENTER || e.which == consts.VK_ESCAPE) { ret = false; d = jelement.data().d; - if (e.which == 13 && newname != d.name) { + if (e.which == consts.VK_ENTER && newname != d.name) { if (d.hasOwnProperty('__src')) { graph.update_link(d, {name: newname}); } else { diff --git a/src/client/view/textanalyser_input.js b/src/client/view/textanalyser_input.js index 113489aa..9defdef3 100644 --- a/src/client/view/textanalyser_input.js +++ b/src/client/view/textanalyser_input.js @@ -7,7 +7,8 @@ var value = util.value; // Constants var nbsp = String.fromCharCode(160), VK_UP = consts.VK_UP, - VK_DOWN = consts.VK_DOWN; + VK_DOWN = consts.VK_DOWN, + VK_ENTER = consts.VK_ENTER; function textanalyser_input(spec) { var selectionStart = function () { @@ -107,7 +108,7 @@ function textanalyser_input(spec) { util.assert(1 === element.length); - var enters = element.asEventStream('keydown').filter(key(13)) + var enters = element.asEventStream('keydown').filter(key(VK_ENTER)) .map(function (e) { var text; e.preventDefault(); -- cgit v1.3.1