aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJörn Friedrich Dreyer <jfd@butonic.de>2015-01-06 15:18:41 +0100
committerJörn Friedrich Dreyer <jfd@butonic.de>2015-01-06 15:18:41 +0100
commit04e2f59f5d3bc8d3e2a5e0756f1f2f47735e1ec3 (patch)
tree34389f23567ddab3693cbf1cb800b7d348864350
parent357fbd88bead4aecb5a4f24d5d1087cf96da730f (diff)
downloadnextcloud-server-04e2f59f5d3bc8d3e2a5e0756f1f2f47735e1ec3.tar.gz
nextcloud-server-04e2f59f5d3bc8d3e2a5e0756f1f2f47735e1ec3.zip
use cancelable timeout, on scroll only fetch next page if last query had any results
-rw-r--r--search/js/search.js46
1 files changed, 25 insertions, 21 deletions
diff --git a/search/js/search.js b/search/js/search.js
index c595ae25092..318858ebd71 100644
--- a/search/js/search.js
+++ b/search/js/search.js
@@ -84,7 +84,8 @@
var lastInApps = [];
var lastPage = 0;
var lastSize = 30;
- var lastResults = {};
+ var lastResults = [];
+ var timeoutID = null;
this.getLastQuery = function() {
return lastQuery;
@@ -94,8 +95,8 @@
* Do a search query and display the results
* @param {string} query the search query
*/
- this.search = _.debounce(function(query, inApps, page, size) {
- if(query) {
+ this.search = function(query, inApps, page, size) {
+ if (query) {
OC.addStyle('search','results');
if (typeof page !== 'number') {
page = 1;
@@ -115,26 +116,29 @@
if ($searchResults && query === lastQuery && page === lastPage && size === lastSize) {
return;
}
- lastQuery = query;
- lastInApps = inApps;
- lastPage = page;
- lastSize = size;
+ window.clearTimeout(timeoutID);
+ timeoutID = window.setTimeout(function() {
+ lastQuery = query;
+ lastInApps = inApps;
+ lastPage = page;
+ lastSize = size;
- //show spinner
- $searchResults.removeClass('hidden');
- $status.html(t('core', 'Searching other places')+'<img class="spinner" alt="search in progress" src="'+OC.webroot+'/core/img/loading.gif" />');
+ //show spinner
+ $searchResults.removeClass('hidden');
+ $status.html(t('core', 'Searching other places')+'<img class="spinner" alt="search in progress" src="'+OC.webroot+'/core/img/loading.gif" />');
- // do the actual search query
- $.getJSON(OC.generateUrl('search/ajax/search.php'), {query:query, inApps:inApps, page:page, size:size }, function(results) {
- lastResults = results;
- if (page === 1) {
- showResults(results);
- } else {
- addResults(results);
- }
- });
+ // do the actual search query
+ $.getJSON(OC.generateUrl('search/ajax/search.php'), {query:query, inApps:inApps, page:page, size:size }, function(results) {
+ lastResults = results;
+ if (page === 1) {
+ showResults(results);
+ } else {
+ addResults(results);
+ }
+ });
+ }, 500);
}
- }, 500);
+ };
//TODO should be a core method, see https://github.com/owncloud/core/issues/12557
function getCurrentApp() {
@@ -243,7 +247,7 @@
* This appends/renders the next page of entries when reaching the bottom.
*/
function onScroll(e) {
- if ($searchResults && lastQuery !== false) {
+ if ($searchResults && lastQuery !== false && lastResults.length > 0) {
var resultsBottom = $searchResults.offset().top + $searchResults.height();
var containerBottom = $searchResults.offsetParent().offset().top + $searchResults.offsetParent().height();
if ( resultsBottom < containerBottom * 1.2 ) {