WordPress.org

Making WordPress.org

Changeset 1329


Ignore:
Timestamp:
02/25/2015 09:08:03 PM (7 years ago)
Author:
coffee2code
Message:

developer.wordpress.org: Add keyboard shortcuts to toggle display of search bar.

  • 's' key toggles display of search bar unless focus is on editable element
  • 'esc' key hides search bar when focus is within search bar

Fixes #885.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/js/search.js

    r1326 r1329  
    2424    });
    2525
     26    // Register keypress events for shortcuts.
     27    $( 'body' ).keypress( function(e) {
     28
     29        var keypress = String.fromCharCode( e.which ).toLowerCase();
     30
     31        switch ( keypress ) {
     32            case 's': // Toggle display of search bar (unless currently focused on editable form element)
     33                if ( e.target.nodeName == 'INPUT' || e.target.nodeName == 'TEXTAREA' || e.target.isContentEditable ) {
     34                    return;
     35                }
     36
     37                e.preventDefault();
     38                toggle_search_bar();
     39                break;
     40        }
     41
     42    });
     43
     44    // Register keydown event for search bar so 'escape' hides search bar.
     45    $( '#inner-search .search-section' ).keydown( function(e) {
     46        if ( 27 == e.which ) {
     47            toggle_search_bar();
     48        }
     49    });
     50
    2651} )( jQuery );
Note: See TracChangeset for help on using the changeset viewer.