Make WordPress Core

Ticket #38211: 38211.5.diff

File 38211.5.diff, 3.1 KB (added by adamsilverstein, 3 years ago)
  • src/js/_enqueues/wp/updates.js

    diff --git src/js/_enqueues/wp/updates.js src/js/_enqueues/wp/updates.js
    index 3371e84d27..1879268d52 100644
     
    139139         */
    140140        wp.updates.searchTerm = '';
    141141
     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
    142151        /**
    143152         * Whether filesystem credentials need to be requested from the user.
    144153         *
     
    25022511                        $pluginInstallSearch.attr( 'aria-describedby', 'live-search-desc' );
    25032512                }
    25042513
     2514                // Track the previous search string length.
     2515                var previousSearchStringLength = 0;
     2516
    25052517                /**
    25062518                 * Handles changes to the plugin search box on the new-plugin page,
    25072519                 * searching the repository dynamically.
     
    25092521                 * @since 4.6.0
    25102522                 */
    25112523                $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;
    25132526
    25142527                        data = {
    25152528                                _ajax_nonce: wp.updates.ajaxNonce,
     
    25202533                        };
    25212534                        searchLocation = location.href.split( '?' )[ 0 ] + '?' + $.param( _.omit( data, [ '_ajax_nonce', 'pagenow' ] ) );
    25222535
     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
    25232553                        // Clear on escape.
    25242554                        if ( 'keyup' === event.type && 27 === event.which ) {
    25252555                                event.target.value = '';
     
    25792609
    25802610                if ( $pluginSearch.length ) {
    25812611                        $pluginSearch.attr( 'aria-describedby', 'live-search-desc' );
     2612
    25822613                }
    25832614
    25842615                /**
     
    25942625                                pagenow:       pagenow,
    25952626                                plugin_status: 'all'
    25962627                        },
    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;
    25982647
    25992648                        // Clear on escape.
    26002649                        if ( 'keyup' === event.type && 27 === event.which ) {