Plugins: Improve Ajax search of installed plugins.

Removes the highlight from the current filter when performing an Ajax search and adds it back when clearing the search input.

Fixes #37657.

git-svn-id: https://develop.svn.wordpress.org/trunk@39099 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Pascal Birchler 2016-11-02 22:46:25 +00:00
parent 9bb355dccd
commit 21dc2530eb
1 changed files with 15 additions and 5 deletions

View File

@ -2245,10 +2245,12 @@
*/
$pluginSearch.on( 'keyup input', _.debounce( function( event ) {
var data = {
_ajax_nonce: wp.updates.ajaxNonce,
s: event.target.value,
pagenow: pagenow
};
_ajax_nonce: wp.updates.ajaxNonce,
s: event.target.value,
pagenow: pagenow,
plugin_status: 'all'
},
queryArgs;
// Clear on escape.
if ( 'keyup' === event.type && 27 === event.which ) {
@ -2261,8 +2263,14 @@
wp.updates.searchTerm = data.s;
}
queryArgs = _.object( _.compact( _.map( location.search.slice( 1 ).split( '&' ), function( item ) {
if ( item ) return item.split( '=' );
} ) ) );
data.plugin_status = queryArgs.plugin_status || 'all';
if ( window.history && window.history.replaceState ) {
window.history.replaceState( null, '', location.href.split( '?' )[ 0 ] + '?s=' + data.s );
window.history.replaceState( null, '', location.href.split( '?' )[ 0 ] + '?s=' + data.s + '&plugin_status=' + data.plugin_status );
}
if ( 'undefined' !== typeof wp.updates.searchRequest ) {
@ -2271,6 +2279,7 @@
$bulkActionForm.empty();
$( 'body' ).addClass( 'loading-content' );
$( '.subsubsub .current' ).removeClass( 'current' );
wp.updates.searchRequest = wp.ajax.post( 'search-plugins', data ).done( function( response ) {
@ -2280,6 +2289,7 @@
if ( ! data.s.length ) {
$oldSubTitle.remove();
$( '.subsubsub .' + data.plugin_status + ' a' ).addClass( 'current' );
} else if ( $oldSubTitle.length ) {
$oldSubTitle.replaceWith( $subTitle );
} else {