Skip to content

Commit

Permalink
Fix fetching additional search results on scrolling down
Browse files Browse the repository at this point in the history
Signed-off-by: René Bühlmann <rene@buehlmann.net>
  • Loading branch information
rbuehlma committed Aug 23, 2019
1 parent 12fd910 commit f0391e1
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions core/search/js/searchprovider.js
Expand Up @@ -260,8 +260,8 @@
var result = $searchResults.find('tr.result')[currentResult];
if (result) {
var $result = $(result);
var currentOffset = $('#app-content').scrollTop();
$('#app-content').animate(
var currentOffset = $(window).scrollTop();
$(window).animate(
{
// Scrolling to the top of the new result
scrollTop:
Expand Down Expand Up @@ -302,26 +302,25 @@
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) {
self.search(lastQuery, lastInApps, lastPage + 1);
if ($(window).scrollTop() + $(window).height() > $searchResults.height() - 300) {
self.search(lastQuery, lastInApps, lastPage + 1);
}
placeStatus();
}
}

$('#app-content').on('scroll', _.bind(onScroll, this));
$(window).on('scroll', _.bind(onScroll, this)); // For desktop browser
$("body").on('scroll', _.bind(onScroll, this)); // For mobile browser

/**
* scrolls the search results to the top
*/
function scrollToResults() {
setTimeout(function() {
if (isStatusOffScreen()) {
var newScrollTop = $('#app-content').prop('scrollHeight') - $searchResults.height();
var newScrollTop = $(window).prop('scrollHeight') - $searchResults.height();
console.log('scrolling to ' + newScrollTop);
$('#app-content').animate(
$(window).animate(
{
scrollTop: newScrollTop
},
Expand Down

0 comments on commit f0391e1

Please sign in to comment.