Media: debounce the media grid search, avoiding duplicate requests.

Add a debounce wrapper to the media grid search handler. The search callback is now fired after a 300 ms typing pause.

Remove redundant handlers for 'search' and 'change', preventing multiple/duplicate search callbacks.

Props certainstrings, joemcgill, Kelderic, batmoo.
Fixes #38911.


git-svn-id: https://develop.svn.wordpress.org/trunk@40060 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Adam Silverstein
2017-02-15 17:28:54 +00:00
parent dccf1535a4
commit 2e0f576156
3 changed files with 19 additions and 23 deletions

View File

@@ -7085,9 +7085,7 @@ Search = wp.media.View.extend({
events: {
'input': 'search',
'keyup': 'search',
'change': 'search',
'search': 'search'
'keyup': 'search'
},
/**
@@ -7098,13 +7096,13 @@ Search = wp.media.View.extend({
return this;
},
search: function( event ) {
search: _.debounce( function( event ) {
if ( event.target.value ) {
this.model.set( 'search', event.target.value );
} else {
this.model.unset('search');
}
}
}, 300 )
});
module.exports = Search;

View File

@@ -21,9 +21,7 @@ Search = wp.media.View.extend({
events: {
'input': 'search',
'keyup': 'search',
'change': 'search',
'search': 'search'
'keyup': 'search'
},
/**
@@ -34,13 +32,13 @@ Search = wp.media.View.extend({
return this;
},
search: function( event ) {
search: _.debounce( function( event ) {
if ( event.target.value ) {
this.model.set( 'search', event.target.value );
} else {
this.model.unset('search');
}
}
}, 300 )
});
module.exports = Search;