File tree Expand file tree Collapse file tree 1 file changed +8
-10
lines changed Expand file tree Collapse file tree 1 file changed +8
-10
lines changed Original file line number Diff line number Diff line change @@ -15,16 +15,14 @@ function setup_search_box() {
15
15
sel . removeClass ( 'two-row' ) ;
16
16
}
17
17
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
22
21
*/
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
29
27
} ) ;
30
28
}
You can’t perform that action at this time.
0 commit comments