Browse Source

Merge pull request #658 from davidar/scroll

[enh] infinite scroll
Adam Tauber 8 years ago
parent
commit
827aba4599

+ 2
- 0
searx/plugins/__init__.py View File

@@ -21,6 +21,7 @@ logger = logger.getChild('plugins')
21 21
 
22 22
 from searx.plugins import (doai_rewrite,
23 23
                            https_rewrite,
24
+                           infinite_scroll,
24 25
                            open_results_on_new_tab,
25 26
                            self_info,
26 27
                            search_on_category_select,
@@ -76,6 +77,7 @@ class PluginStore():
76 77
 plugins = PluginStore()
77 78
 plugins.register(doai_rewrite)
78 79
 plugins.register(https_rewrite)
80
+plugins.register(infinite_scroll)
79 81
 plugins.register(open_results_on_new_tab)
80 82
 plugins.register(self_info)
81 83
 plugins.register(search_on_category_select)

+ 8
- 0
searx/plugins/infinite_scroll.py View File

@@ -0,0 +1,8 @@
1
+from flask_babel import gettext
2
+
3
+name = gettext('Infinite scroll')
4
+description = gettext('Automatically load next page when scrolling to bottom of current page')
5
+default_on = False
6
+
7
+js_dependencies = ('plugins/js/infinite_scroll.js',)
8
+css_dependencies = ('plugins/css/infinite_scroll.css',)

+ 16
- 0
searx/static/plugins/css/infinite_scroll.css View File

@@ -0,0 +1,16 @@
1
+@keyframes rotate-forever {
2
+    0%   { transform: rotate(0deg) }
3
+    100% { transform: rotate(360deg) }
4
+}
5
+.loading-spinner {
6
+    animation-duration: 0.75s;
7
+    animation-iteration-count: infinite;
8
+    animation-name: rotate-forever;
9
+    animation-timing-function: linear;
10
+    height: 30px;
11
+    width: 30px;
12
+    border: 8px solid #666;
13
+    border-right-color: transparent;
14
+    border-radius: 50% !important;
15
+    margin: 0 auto;
16
+}

+ 18
- 0
searx/static/plugins/js/infinite_scroll.js View File

@@ -0,0 +1,18 @@
1
+$(document).ready(function() {
2
+    var win = $(window);
3
+    win.scroll(function() {
4
+        if ($(document).height() - win.height() == win.scrollTop()) {
5
+            var formData = $('#pagination form:last').serialize();
6
+            if (formData) {
7
+                $('#pagination').html('<div class="loading-spinner"></div>');
8
+                $.post('/', formData, function (data) {
9
+                    var body = $(data);
10
+                    $('#pagination').remove();
11
+                    $('#main_results').append('<hr/>');
12
+                    $('#main_results').append(body.find('.result'));
13
+                    $('#main_results').append(body.find('#pagination'));
14
+                });
15
+            }
16
+        }
17
+    });
18
+});