summaryrefslogtreecommitdiff
path: root/searx/static/plugins
diff options
context:
space:
mode:
authorAdam Tauber <asciimoo@gmail.com>2020-03-23 13:05:19 +0100
committerAdam Tauber <asciimoo@gmail.com>2020-03-23 13:05:19 +0100
commit65cae857354a5268253e40556153e994fa747e3d (patch)
tree93c661d9f1b68423276147f19303ea1b38f4e2d4 /searx/static/plugins
parent2621c24cc7992a7c6968d5ce389364c3bf4cc7e2 (diff)
downloadsearxng-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.js50
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();
}
});
});