From 93f232d83daaa0ce1f55b3604a7b85ed93ed9b7b Mon Sep 17 00:00:00 2001 From: Jonathan Reisdorf Date: Thu, 2 Oct 2014 12:05:08 +0200 Subject: [PATCH 1/3] retain search term on input blur unless it is empty --- controls/box/box.css | 8 ++++---- controls/box/box_c.js | 15 +++++++++------ lib/box.js | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/controls/box/box.css b/controls/box/box.css index e4a6e48..075d077 100644 --- a/controls/box/box.css +++ b/controls/box/box.css @@ -21,7 +21,7 @@ color: hsl(110, 80%, 45%) !important; } -.box.focus .ssl { +.box.searching .ssl { display: none; } @@ -37,7 +37,7 @@ font-size: 1.2em; } -.box.focus .search { +.box.searching .search { display: block; } @@ -95,7 +95,7 @@ opacity: 0; } -.box.focus .input form input, +.box.searching .input form input, .box .input:hover form input { opacity: 1; font-weight: bold; @@ -127,6 +127,6 @@ } .box .input:hover .glass, -.box.focus .input .glass { +.box.searching .input .glass { display: none; } diff --git a/controls/box/box_c.js b/controls/box/box_c.js index 28ede94..479b3e1 100644 --- a/controls/box/box_c.js +++ b/controls/box/box_c.js @@ -73,7 +73,7 @@ var box_c = function(spec, my) { // // Handler called on input focusin input_focusin_handler = function() { - my.box_el.addClass('focus'); + my.box_el.addClass('searching'); setTimeout(function() { my.input_el.select(); }); @@ -81,10 +81,13 @@ var box_c = function(spec, my) { // ### input_focusout_handler // - // Handler called on input focusin + // Handler called on input focusout input_focusout_handler = function() { - my.box_el.removeClass('focus'); - my.socket.emit('input', null); + var inputValue = my.box_el.find('input').val(); + my.box_el[inputValue ? 'addClass' : 'removeClass']('searching'); + if (!inputValue) { + my.socket.emit('input', null); + } } // ### input_keydown_handler @@ -93,11 +96,11 @@ var box_c = function(spec, my) { input_keydown_handler = function(evt) { if(evt.which === 27) { my.socket.emit('clear'); - my.box_el.find('input').blur(); + my.box_el.find('input').val('').blur(); } if(my.mode === my.MODE_FIND_IN_PAGE && my.input_el.is(':focus')) { if(evt.which === 13 && (evt.ctrlKey || evt.metaKey)) { - my.socket.emit('submit', { + my.socket.emit('submit', { input: my.input_el.val(), is_ctrl: true }); diff --git a/lib/box.js b/lib/box.js index ef1ef0c..af2b867 100644 --- a/lib/box.js +++ b/lib/box.js @@ -332,7 +332,7 @@ var box = function(spec, my) { my.sockets.forEach(function(s) { s.emit('focus'); }); - my.input = '' + my.input = ''; socket_push(); /* Emit input value on change for tabs filtering or anything else. */ From adaffb5af80b37489d9350fdbc0c569fba5fb18d Mon Sep 17 00:00:00 2001 From: Jonathan Reisdorf Date: Thu, 2 Oct 2014 13:18:21 +0200 Subject: [PATCH 2/3] fix --- controls/box/box_c.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/controls/box/box_c.js b/controls/box/box_c.js index 479b3e1..c714393 100644 --- a/controls/box/box_c.js +++ b/controls/box/box_c.js @@ -49,6 +49,7 @@ var box_c = function(spec, my) { var form_submit_handler; /* form_submit_hanlder(); */ var state_handler; /* state_handler(state); */ + var last_url; /* string */ var select_all_handler; /* select_all_handler(); */ var focus_handler; /* focus_handler(); */ @@ -84,8 +85,8 @@ var box_c = function(spec, my) { // Handler called on input focusout input_focusout_handler = function() { var inputValue = my.box_el.find('input').val(); - my.box_el[inputValue ? 'addClass' : 'removeClass']('searching'); - if (!inputValue) { + if (!inputValue || inputValue === last_url) { + my.box_el.removeClass('searching'); my.socket.emit('input', null); } } @@ -96,7 +97,7 @@ var box_c = function(spec, my) { input_keydown_handler = function(evt) { if(evt.which === 27) { my.socket.emit('clear'); - my.box_el.find('input').val('').blur(); + my.box_el.find('input').val(last_url).blur(); } if(my.mode === my.MODE_FIND_IN_PAGE && my.input_el.is(':focus')) { if(evt.which === 13 && (evt.ctrlKey || evt.metaKey)) { @@ -118,6 +119,7 @@ var box_c = function(spec, my) { input: my.input_el.val(), is_ctrl: false }); + my.box_el.removeClass('searching').find('input').blur(); evt.preventDefault(); evt.stopPropagation(); }; @@ -143,6 +145,7 @@ var box_c = function(spec, my) { } else if(state.url) { my.value = state.url.href; + last_url = my.value; } else { my.value = ''; From dd688871ef04c4915528c96074b8d56c80f06833 Mon Sep 17 00:00:00 2001 From: Jonathan Reisdorf Date: Thu, 2 Oct 2014 18:59:53 +0200 Subject: [PATCH 3/3] search term now also cleared when changing tab --- controls/box/box_c.js | 6 ++++++ controls/strip/strip_c.js | 1 + lib/box.js | 11 +++++++++++ lib/strip.js | 15 ++++++++++++--- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/controls/box/box_c.js b/controls/box/box_c.js index c714393..ce9388e 100644 --- a/controls/box/box_c.js +++ b/controls/box/box_c.js @@ -52,6 +52,7 @@ var box_c = function(spec, my) { var last_url; /* string */ var select_all_handler; /* select_all_handler(); */ var focus_handler; /* focus_handler(); */ + var blur_handler; /* blur_handler(); */ var that = {} @@ -197,6 +198,10 @@ var box_c = function(spec, my) { my.input_el.focus(); }; + blur_handler = function() { + my.input_el.blur(); + }; + /**************************************************************************/ /* PUBLIC METHODS */ /**************************************************************************/ @@ -208,6 +213,7 @@ var box_c = function(spec, my) { my.socket.on('state', state_handler); my.socket.on('select_all', select_all_handler); my.socket.on('focus', focus_handler); + my.socket.on('blur', blur_handler); my.socket.emit('handshake', '_box'); my.input_el.keyup(input_change_handler); diff --git a/controls/strip/strip_c.js b/controls/strip/strip_c.js index ad57108..52d268f 100644 --- a/controls/strip/strip_c.js +++ b/controls/strip/strip_c.js @@ -410,6 +410,7 @@ var strip_c = function(spec, my) { select_tab = function(tab_id) { if(tab_id !== my.active) { my.socket.emit('select', tab_id); + my.socket.emit('box_reset'); } }; diff --git a/lib/box.js b/lib/box.js index af2b867..83468b9 100644 --- a/lib/box.js +++ b/lib/box.js @@ -52,6 +52,7 @@ var box = function(spec, my) { var core_state_handler; /* core_state_handler(evt); */ var socket_submit; /* socket_submit(name); */ + var socket_input; /* socket_input(value); */ var stack_state_handler; /* stack_state_handler(evt); */ var shortcut_find_in_page; /* shortcut_find_in_page(); */ @@ -63,6 +64,7 @@ var box = function(spec, my) { var exposed_get_listen_url; /* exposed_get_listen_url(src, args, cb_); */ var exposed_focus; /* exposed_focus(src, args, cb_); */ var exposed_select_all; /* exposed_select_all(src, args, cb_); */ + var exposed_box_reset; /* exposed_box_reset(); */ var that = {}; @@ -378,6 +380,14 @@ var box = function(spec, my) { }); }; + exposed_box_reset = function() { + my.input = null; + socket_push(); + my.sockets.forEach(function(s) { + s.emit('blur'); + }); + }; + /****************************************************************************/ /* PUBLIC METHODS */ /****************************************************************************/ @@ -420,6 +430,7 @@ var box = function(spec, my) { breach.expose('box_find_in_page', exposed_find_in_page); breach.expose('box_focus', exposed_focus); breach.expose('box_select_all', exposed_select_all); + breach.expose('box_reset', exposed_box_reset); return cb_(); }, diff --git a/lib/strip.js b/lib/strip.js index 9548f81..b2fbeca 100644 --- a/lib/strip.js +++ b/lib/strip.js @@ -60,6 +60,8 @@ var strip = function(spec, my) { var box_load_url_handler; /* box_load_url_handler(evt); */ var box_input_handler; /* box_input_handler(evt); */ + var box_reset_handler; /* box_reset_handler(); */ + var core_module_update_ready; /* core_module_update_ready(evt); */ var core_breach_update_ready; /* core_breach_update_ready(evt); */ var core_module_state_change; /* core_module_state_change(evt); */ @@ -226,6 +228,12 @@ var strip = function(spec, my) { } }; + box_reset_handler = function() { + my.filter = null; + breach.module('mod_strip').call('box_reset'); + socket_push(); + } + /****************************************************************************/ /* CORE EVENT HANDLERS */ /****************************************************************************/ @@ -417,6 +425,7 @@ var strip = function(spec, my) { socket.on('forward', socket_forward); socket.on('new', socket_new); socket.on('update', socket_update); + socket.on('box_reset', box_reset_handler); my.tabs_state = common._.tabs.state(); socket_push(); @@ -473,7 +482,7 @@ var strip = function(spec, my) { }, function(cb_) { async.parallel([ - my.keyboard_shortcuts.init, + my.keyboard_shortcuts.init ], cb_); }, function(cb_) { @@ -482,7 +491,7 @@ var strip = function(spec, my) { url: 'http://localhost:' + my.http_port + '/strip', dimension: 45 }, cb_); - }, + } ], cb_); }; @@ -494,7 +503,7 @@ var strip = function(spec, my) { // ``` kill = function(cb_) { breach.module('core').call('controls_unset', { - type: 'TOP', + type: 'TOP' }, cb_); };