Skip to content

Commit

Permalink
Merge pull request #34613 from owncloud/stable10-adding-delay-to-search
Browse files Browse the repository at this point in the history
[stable10] Backport: Added delay in search
  • Loading branch information
phil-davis authored Feb 26, 2019
2 parents eedbdf5 + fe99df2 commit a357e4d
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions core/search/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
var lastSize = 30;
var lastResults = [];
var timeoutID = null;
/* For delaying search*/
var timeout = null;

this.getLastQuery = function() {
return lastQuery;
Expand Down Expand Up @@ -319,18 +321,24 @@
renderCurrent();
}
} else {
var query = $searchBox.val();
if (lastQuery !== query) {
currentResult = -1;
if (query.length > 2) {
self.search(query);
} else {
self.hideResults();
}
if(self.hasFilter(getCurrentApp())) {
self.getFilter(getCurrentApp())(query);
/**
* Search begins 500 millisoconds after the user stops typing
*/
clearTimeout(timeout);
timeout = setTimeout(function () {
var query = $searchBox.val();
if (lastQuery !== query) {
currentResult = -1;
if (query.length > 2) {
self.search(query);
} else {
self.hideResults();
}
if(self.hasFilter(getCurrentApp())) {
self.getFilter(getCurrentApp())(query);
}
}
}
}, 500);
}
});
$(document).keyup(function(event) {
Expand Down

0 comments on commit a357e4d

Please sign in to comment.