diff --git src/js/_enqueues/wp/updates.js src/js/_enqueues/wp/updates.js
index 3371e84d27..1879268d52 100644
|
|
|
139 | 139 | */ |
140 | 140 | wp.updates.searchTerm = ''; |
141 | 141 | |
| 142 | /** |
| 143 | * Minimum number of characters before an ajax search is fired. |
| 144 | * |
| 145 | * @since 5.4.0 |
| 146 | * |
| 147 | * @type {number} |
| 148 | */ |
| 149 | wp.updates.searchMinCharacters = 2; |
| 150 | |
142 | 151 | /** |
143 | 152 | * Whether filesystem credentials need to be requested from the user. |
144 | 153 | * |
… |
… |
|
2502 | 2511 | $pluginInstallSearch.attr( 'aria-describedby', 'live-search-desc' ); |
2503 | 2512 | } |
2504 | 2513 | |
| 2514 | // Track the previous search string length. |
| 2515 | var previousSearchStringLength = 0; |
| 2516 | |
2505 | 2517 | /** |
2506 | 2518 | * Handles changes to the plugin search box on the new-plugin page, |
2507 | 2519 | * searching the repository dynamically. |
… |
… |
|
2509 | 2521 | * @since 4.6.0 |
2510 | 2522 | */ |
2511 | 2523 | $pluginInstallSearch.on( 'keyup input', _.debounce( function( event, eventtype ) { |
2512 | | var $searchTab = $( '.plugin-install-search' ), data, searchLocation; |
| 2524 | var $searchTab = $( '.plugin-install-search' ), data, searchLocation, |
| 2525 | searchStringLength = $pluginInstallSearch.val().length; |
2513 | 2526 | |
2514 | 2527 | data = { |
2515 | 2528 | _ajax_nonce: wp.updates.ajaxNonce, |
… |
… |
|
2520 | 2533 | }; |
2521 | 2534 | searchLocation = location.href.split( '?' )[ 0 ] + '?' + $.param( _.omit( data, [ '_ajax_nonce', 'pagenow' ] ) ); |
2522 | 2535 | |
| 2536 | // Set the autocomplete attribute, turning off autocomplete 1 character before ajax search kicks in. |
| 2537 | if ( 0 === searchStringLength || searchStringLength < wp.updates.searchMinCharacters ) { |
| 2538 | $pluginInstallSearch.attr( 'autocomplete', 'on' ); |
| 2539 | } else { |
| 2540 | $pluginInstallSearch.attr( 'autocomplete', 'off' ); |
| 2541 | } |
| 2542 | |
| 2543 | // Only search when user has typed a a minimum number of characters (default 2). |
| 2544 | if ( |
| 2545 | 0 !== searchStringLength && |
| 2546 | searchStringLength < wp.updates.searchMinCharacters && |
| 2547 | previousSearchStringLength < wp.updates.searchMinCharacters |
| 2548 | ) { |
| 2549 | return; |
| 2550 | } |
| 2551 | previousSearchStringLength = searchStringLength; |
| 2552 | |
2523 | 2553 | // Clear on escape. |
2524 | 2554 | if ( 'keyup' === event.type && 27 === event.which ) { |
2525 | 2555 | event.target.value = ''; |
… |
… |
|
2579 | 2609 | |
2580 | 2610 | if ( $pluginSearch.length ) { |
2581 | 2611 | $pluginSearch.attr( 'aria-describedby', 'live-search-desc' ); |
| 2612 | |
2582 | 2613 | } |
2583 | 2614 | |
2584 | 2615 | /** |
… |
… |
|
2594 | 2625 | pagenow: pagenow, |
2595 | 2626 | plugin_status: 'all' |
2596 | 2627 | }, |
2597 | | queryArgs; |
| 2628 | queryArgs, |
| 2629 | searchStringLength = $pluginSearch.val().length; |
| 2630 | |
| 2631 | // Set the autocomplete attribute, turning off autocomplete 1 character before ajax search kicks in. |
| 2632 | if ( 0 === searchStringLength || searchStringLength < wp.updates.searchMinCharacters - 1 ) { |
| 2633 | $pluginSearch.attr( 'autocomplete', 'on' ); |
| 2634 | } else { |
| 2635 | $pluginSearch.attr( 'autocomplete', 'off' ); |
| 2636 | } |
| 2637 | |
| 2638 | // Only search when user has typed a a minimum number of characters (default 2). |
| 2639 | if ( |
| 2640 | 0 !== searchStringLength && |
| 2641 | searchStringLength < wp.updates.searchMinCharacters && |
| 2642 | previousSearchStringLength < wp.updates.searchMinCharacters |
| 2643 | ) { |
| 2644 | return; |
| 2645 | } |
| 2646 | previousSearchStringLength = searchStringLength; |
2598 | 2647 | |
2599 | 2648 | // Clear on escape. |
2600 | 2649 | if ( 'keyup' === event.type && 27 === event.which ) { |