Make WordPress Core

Ticket #38211: 38211.4.diff

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

    diff --git src/js/_enqueues/wp/updates.js src/js/_enqueues/wp/updates.js
    index ee5bf3cc58..593cac908c 100644
     
    6767         */
    6868        wp.updates.searchTerm = '';
    6969
     70        /**
     71         * Minimum number of characters before an ajax search is fired.
     72         *
     73         * @since 5.4.0
     74         *
     75         * @type {number}
     76         */
     77        wp.updates.searchMinCharacters = 2;
     78
    7079        /**
    7180         * Whether filesystem credentials need to be requested from the user.
    7281         *
     
    21692178                        $pluginInstallSearch.attr( 'aria-describedby', 'live-search-desc' );
    21702179                }
    21712180
     2181                // Track the previous search string length.
     2182                var previousSearchStringLength = 0;
     2183
    21722184                /**
    21732185                 * Handles changes to the plugin search box on the new-plugin page,
    21742186                 * searching the repository dynamically.
     
    21762188                 * @since 4.6.0
    21772189                 */
    21782190                $pluginInstallSearch.on( 'keyup input', _.debounce( function( event, eventtype ) {
    2179                         var $searchTab = $( '.plugin-install-search' ), data, searchLocation;
     2191                        var $searchTab = $( '.plugin-install-search' ), data, searchLocation,
     2192                                searchStringLength = $pluginInstallSearch.val().length;
    21802193
    21812194                        data = {
    21822195                                _ajax_nonce: wp.updates.ajaxNonce,
     
    21872200                        };
    21882201                        searchLocation = location.href.split( '?' )[ 0 ] + '?' + $.param( _.omit( data, [ '_ajax_nonce', 'pagenow' ] ) );
    21892202
     2203                        // Set the autocomplete attribute, turning off autocomplete 1 character before ajax search kicks in.
     2204                        if ( 0 === searchStringLength || searchStringLength < wp.updates.searchMinCharacters ) {
     2205                                $pluginInstallSearch.attr( 'autocomplete', 'on' );
     2206                        } else {
     2207                                $pluginInstallSearch.attr( 'autocomplete', 'off' );
     2208                        }
     2209
     2210                        // Only search when user has typed a a minimum number of characters (default 2).
     2211                        if (
     2212                                0 !== searchStringLength &&
     2213                                searchStringLength < wp.updates.searchMinCharacters &&
     2214                                previousSearchStringLength < wp.updates.searchMinCharacters
     2215                        ) {
     2216                                return;
     2217                        }
     2218                        previousSearchStringLength = searchStringLength;
     2219
    21902220                        // Clear on escape.
    21912221                        if ( 'keyup' === event.type && 27 === event.which ) {
    21922222                                event.target.value = '';
     
    22402270
    22412271                if ( $pluginSearch.length ) {
    22422272                        $pluginSearch.attr( 'aria-describedby', 'live-search-desc' );
     2273
    22432274                }
    22442275
    22452276                /**
     
    22552286                                pagenow:       pagenow,
    22562287                                plugin_status: 'all'
    22572288                        },
    2258                         queryArgs;
     2289                        queryArgs,
     2290                        searchStringLength = $pluginSearch.val().length;
     2291
     2292                        // Set the autocomplete attribute, turning off autocomplete 1 character before ajax search kicks in.
     2293                        if ( 0 === searchStringLength || searchStringLength < wp.updates.searchMinCharacters - 1 ) {
     2294                                $pluginSearch.attr( 'autocomplete', 'on' );
     2295                        } else {
     2296                                $pluginSearch.attr( 'autocomplete', 'off' );
     2297                        }
     2298
     2299                        // Only search when user has typed a a minimum number of characters (default 2).
     2300                        if (
     2301                                0 !== searchStringLength &&
     2302                                searchStringLength < wp.updates.searchMinCharacters &&
     2303                                previousSearchStringLength < wp.updates.searchMinCharacters
     2304                        ) {
     2305                                return;
     2306                        }
     2307                        previousSearchStringLength = searchStringLength;
    22592308
    22602309                        // Clear on escape.
    22612310                        if ( 'keyup' === event.type && 27 === event.which ) {