Skip to content

Commit e132d9b

Browse files
committed
Un-focus search box and scroll when SPACE, DOWN, or PAGE DOWN are pressed
1 parent 61a22a3 commit e132d9b

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

html/js/main.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,14 @@ function setup_search_box() {
1515
sel.removeClass('two-row');
1616
}
1717

18-
/* Focus search box on page load, but remove it when user scrolled a bit
19-
... because some use "Space" key to scroll through the page, but
20-
... if our search box stays focused, they get jolted back to the
21-
... top of the page
18+
/* Focus search box on page load, but remove focus if the user appears
19+
to be trying to scroll the page with keyboard, rather than typing
20+
a search query
2221
*/
23-
$('#query').focus();
24-
$(window).on('scroll.search', function(){
25-
if ( $(window).scrollTop() > 200 ) {
26-
$('#query').blur();
27-
$(window).off('scroll.search');
28-
}
22+
$('#query').focus().keydown( function(e){
23+
var el = $(this);
24+
if ( e.which == 32 && el.val().length ) { return true; }
25+
if ( e.which == 32 || e.which == 34 || e.which == 40 ) { el.blur() ; }
26+
// key codes: 32: space; 34: pagedown; 40: down arrow
2927
});
3028
}

0 commit comments

Comments
 (0)