WordPress.org

Making WordPress.org

Changeset 1326


Ignore:
Timestamp:
02/25/2015 08:42:52 PM (5 years ago)
Author:
coffee2code
Message:

developer.wordpress.org: Give focus to search input after revealing search bar. Fixes #882

File:
1 edited

Legend:

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

    r990 r1326  
    11( function( $ ) {
    2     // Toggle search
    3     $( '#inner-search .search-section' ).toggle();
    42
     3    function toggle_search_bar() {
     4        // The search input field.
     5        var search_input = $( '#inner-search .search-section .search-field' );
     6
     7        // Toggle display.
     8        $( '#inner-search .search-section' ).toggle();
     9
     10        // Give input field focus if it is now visible, remove focus otherwise.
     11        if ( search_input.is(':visible') ) {
     12            search_input.focus();
     13        } else {
     14            search_input.blur();
     15        }
     16    }
     17
     18    // Toggle search bar on page load (it's shown by default).
     19    toggle_search_bar();
     20
     21    // Toggle search bar when icon is clicked.
    522    $( '#inner-search #inner-search-icon' ).on( 'click', function() {
    6         $( '#inner-search .search-section' ).toggle();
     23        toggle_search_bar();
    724    });
     25
    826} )( jQuery );
Note: See TracChangeset for help on using the changeset viewer.