Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retain search term on input blur unless it is empty #66

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions controls/box/box.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
color: hsl(110, 80%, 45%) !important;
}

.box.focus .ssl {
.box.searching .ssl {
display: none;
}

Expand All @@ -37,7 +37,7 @@
font-size: 1.2em;
}

.box.focus .search {
.box.searching .search {
display: block;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -127,6 +127,6 @@
}

.box .input:hover .glass,
.box.focus .input .glass {
.box.searching .input .glass {
display: none;
}
24 changes: 18 additions & 6 deletions controls/box/box_c.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ 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(); */
var blur_handler; /* blur_handler(); */

var that = {}

Expand All @@ -73,18 +75,21 @@ 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();
});
}

// ### 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();
if (!inputValue || inputValue === last_url) {
my.box_el.removeClass('searching');
my.socket.emit('input', null);
}
}

// ### input_keydown_handler
Expand All @@ -93,11 +98,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(last_url).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
});
Expand All @@ -115,6 +120,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();
};
Expand All @@ -140,6 +146,7 @@ var box_c = function(spec, my) {
}
else if(state.url) {
my.value = state.url.href;
last_url = my.value;
}
else {
my.value = '';
Expand Down Expand Up @@ -191,6 +198,10 @@ var box_c = function(spec, my) {
my.input_el.focus();
};

blur_handler = function() {
my.input_el.blur();
};

/**************************************************************************/
/* PUBLIC METHODS */
/**************************************************************************/
Expand All @@ -202,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);
Expand Down
1 change: 1 addition & 0 deletions controls/strip/strip_c.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
};

Expand Down
13 changes: 12 additions & 1 deletion lib/box.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(); */
Expand All @@ -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 = {};

Expand Down Expand Up @@ -332,7 +334,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. */
Expand Down Expand Up @@ -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 */
/****************************************************************************/
Expand Down Expand Up @@ -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_();
},
Expand Down
15 changes: 12 additions & 3 deletions lib/strip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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); */
Expand Down Expand Up @@ -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 */
/****************************************************************************/
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -473,7 +482,7 @@ var strip = function(spec, my) {
},
function(cb_) {
async.parallel([
my.keyboard_shortcuts.init,
my.keyboard_shortcuts.init
], cb_);
},
function(cb_) {
Expand All @@ -482,7 +491,7 @@ var strip = function(spec, my) {
url: 'http://localhost:' + my.http_port + '/strip',
dimension: 45
}, cb_);
},
}
], cb_);
};

Expand All @@ -494,7 +503,7 @@ var strip = function(spec, my) {
// ```
kill = function(cb_) {
breach.module('core').call('controls_unset', {
type: 'TOP',
type: 'TOP'
}, cb_);
};

Expand Down