mirror of
https://github.com/searxng/searxng
synced 2024-01-01 19:24:07 +01:00
[mod] infinite_scroll as preference
* oscar theme: code from searx/plugins/infinite_scroll.py * simple theme: new implementation Co-authored-by: Markus Heiser <markus.heiser@darmarIT.de>
This commit is contained in:
parent
36aee70c24
commit
56e34947a6
23 changed files with 314 additions and 121 deletions
|
|
@ -19,6 +19,7 @@ window.searxng = (function(d) {
|
|||
|
||||
return {
|
||||
autocompleter: script.getAttribute('data-autocompleter') === 'true',
|
||||
infinite_scroll: script.getAttribute('data-infinite-scroll') === 'true',
|
||||
method: script.getAttribute('data-method'),
|
||||
translations: JSON.parse(script.getAttribute('data-translations'))
|
||||
};
|
||||
|
|
|
|||
50
searx/static/themes/oscar/src/js/infinite_scroll.js
Normal file
50
searx/static/themes/oscar/src/js/infinite_scroll.js
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
* @license
|
||||
* (C) Copyright Contributors to the SearXNG project.
|
||||
* (C) Copyright Contributors to the searx project (2014 - 2021).
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
$(document).ready(function() {
|
||||
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: $('#search_form').prop('action'),
|
||||
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();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (searxng.infinite_scroll) {
|
||||
var win = $(window);
|
||||
$("html").addClass('infinite_scroll');
|
||||
if(!hasScrollbar()) {
|
||||
loadNextPage();
|
||||
}
|
||||
win.on('scroll', function() {
|
||||
if ($(document).height() - win.height() - win.scrollTop() < 150) {
|
||||
loadNextPage();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue