diff options
author | Adam Tauber <asciimoo@gmail.com> | 2020-03-23 13:05:19 +0100 |
---|---|---|
committer | Adam Tauber <asciimoo@gmail.com> | 2020-03-23 13:05:19 +0100 |
commit | 65cae857354a5268253e40556153e994fa747e3d (patch) | |
tree | 93c661d9f1b68423276147f19303ea1b38f4e2d4 /searx/static/plugins | |
parent | 2621c24cc7992a7c6968d5ce389364c3bf4cc7e2 (diff) | |
download | searxng-65cae857354a5268253e40556153e994fa747e3d.tar.gz searxng-65cae857354a5268253e40556153e994fa747e3d.zip |
[fix] load new page with infinite scroll if there is no scrollbar - fixes #759
Diffstat (limited to 'searx/static/plugins')
-rw-r--r-- | searx/static/plugins/js/infinite_scroll.js | 50 |
1 files changed, 33 insertions, 17 deletions
diff --git a/searx/static/plugins/js/infinite_scroll.js b/searx/static/plugins/js/infinite_scroll.js index db84a6908..9930880e3 100644 --- a/searx/static/plugins/js/infinite_scroll.js +++ b/searx/static/plugins/js/infinite_scroll.js @@ -1,24 +1,40 @@ +function hasScrollbar() { + var root = document.compatMode=='BackCompat'? document.body : document.documentElement; + return root.scrollHeight>root.clientHeight; +} + +function loadNextPage() { + var formData = $('#pagination form:last').serialize(); + if (formData) { + $('#pagination').html('<div class="loading-spinner"></div>'); + $.ajax({ + type: "POST", + url: './', + data: formData, + dataType: 'html', + success: function(data) { + var body = $(data); + $('#pagination').remove(); + $('#main_results').append('<hr/>'); + $('#main_results').append(body.find('.result')); + $('#main_results').append(body.find('#pagination')); + if(!hasScrollbar()) { + loadNextPage(); + } + } + }); + } +} + $(document).ready(function() { var win = $(window); + if(!hasScrollbar()) { + loadNextPage(); + } win.scroll(function() { + $("#pagination button").css("visibility", "hidden"); if ($(document).height() - win.height() - win.scrollTop() < 150) { - var formData = $('#pagination form:last').serialize(); - if (formData) { - $('#pagination').html('<div class="loading-spinner"></div>'); - $.ajax({ - type: "POST", - url: './', - data: formData, - dataType: 'html', - success: function(data) { - var body = $(data); - $('#pagination').remove(); - $('#main_results').append('<hr/>'); - $('#main_results').append(body.find('.result')); - $('#main_results').append(body.find('#pagination')); - } - }); - } + loadNextPage(); } }); }); |