diff --git src/js/_enqueues/wp/updates.js src/js/_enqueues/wp/updates.js
index ee5bf3cc58..593cac908c 100644
|
|
|
67 | 67 | */ |
68 | 68 | wp.updates.searchTerm = ''; |
69 | 69 | |
| 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 | |
70 | 79 | /** |
71 | 80 | * Whether filesystem credentials need to be requested from the user. |
72 | 81 | * |
… |
… |
|
2169 | 2178 | $pluginInstallSearch.attr( 'aria-describedby', 'live-search-desc' ); |
2170 | 2179 | } |
2171 | 2180 | |
| 2181 | // Track the previous search string length. |
| 2182 | var previousSearchStringLength = 0; |
| 2183 | |
2172 | 2184 | /** |
2173 | 2185 | * Handles changes to the plugin search box on the new-plugin page, |
2174 | 2186 | * searching the repository dynamically. |
… |
… |
|
2176 | 2188 | * @since 4.6.0 |
2177 | 2189 | */ |
2178 | 2190 | $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; |
2180 | 2193 | |
2181 | 2194 | data = { |
2182 | 2195 | _ajax_nonce: wp.updates.ajaxNonce, |
… |
… |
|
2187 | 2200 | }; |
2188 | 2201 | searchLocation = location.href.split( '?' )[ 0 ] + '?' + $.param( _.omit( data, [ '_ajax_nonce', 'pagenow' ] ) ); |
2189 | 2202 | |
| 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 | |
2190 | 2220 | // Clear on escape. |
2191 | 2221 | if ( 'keyup' === event.type && 27 === event.which ) { |
2192 | 2222 | event.target.value = ''; |
… |
… |
|
2240 | 2270 | |
2241 | 2271 | if ( $pluginSearch.length ) { |
2242 | 2272 | $pluginSearch.attr( 'aria-describedby', 'live-search-desc' ); |
| 2273 | |
2243 | 2274 | } |
2244 | 2275 | |
2245 | 2276 | /** |
… |
… |
|
2255 | 2286 | pagenow: pagenow, |
2256 | 2287 | plugin_status: 'all' |
2257 | 2288 | }, |
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; |
2259 | 2308 | |
2260 | 2309 | // Clear on escape. |
2261 | 2310 | if ( 'keyup' === event.type && 27 === event.which ) { |