瀏覽代碼

Ajax loading + Tweaks of CSS

Cqoicebordel 10 年之前
父節點
當前提交
e181041f11

+ 1
- 1
searx/static/themes/pix-art/css/style.css
文件差異過大導致無法顯示
查看文件


二進制
searx/static/themes/pix-art/img/searx-pixel-small.png 查看文件


二進制
searx/static/themes/pix-art/img/spinner.gif 查看文件


+ 94
- 0
searx/static/themes/pix-art/js/searx.js 查看文件

47
 
47
 
48
 })(window, document);
48
 })(window, document);
49
 
49
 
50
+var xmlHttp
51
+
52
+function GetXmlHttpObject(){
53
+
54
+    var xmlHttp = null;
55
+
56
+    try {
57
+        // Firefox, Opera 8.0+, Safari
58
+        xmlHttp = new XMLHttpRequest();
59
+    }
60
+    catch (e) {
61
+        // Internet Explorer
62
+        try {
63
+            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
64
+        }
65
+        catch (e){
66
+            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
67
+        }
68
+    }
69
+    return xmlHttp;
70
+}
71
+
72
+var timer;
73
+
74
+// Calculate the rating
75
+function load_more(query,page){
76
+
77
+    xmlHttp = GetXmlHttpObject();
78
+    clearTimeout(timer);
79
+
80
+    if(xmlHttp == null){
81
+        alert ("Your browser does not support AJAX!");
82
+        return;
83
+    }
84
+
85
+    favicons[page] = [];
86
+
87
+    xmlHttp.onreadystatechange = function(){
88
+        
89
+        var loader = document.getElementById('load_more');
90
+
91
+        if (xmlHttp.readyState == 4){
92
+            
93
+            //loader.style.display = 'none';
94
+            var res = xmlHttp.responseText;
95
+
96
+            //loader.style.display = 'block';
97
+            //loader.innerHTML = '<div class="voted">Vote pris en compte</div>';
98
+            clearTimeout(timer);
99
+            timer = setTimeout(function(){},6000);
100
+
101
+            var results = document.getElementById('results_list');
102
+            //results_list.innerHTML += res;
103
+            var newNode = document.createElement('span');      
104
+            newNode.innerHTML = res;
105
+            results_list.appendChild(newNode);
106
+
107
+            var scripts = newNode.getElementsByTagName('script');
108
+            for (var ix = 0; ix < scripts.length; ix++) {
109
+                eval(scripts[ix].text);
110
+            }
111
+
112
+            load_images(page);
113
+            document.getElementById("load_more").onclick = function() { load_more(query, (page+1)); }
114
+            loader.removeAttribute("disabled");
115
+            
116
+        } else {
117
+            //loader.innerHTML = '<img src="images/rating_loading.gif" alt="loading" />'; 
118
+            loader.disabled = 'disabled';
119
+        }
120
+    }
121
+    var url = "/";
122
+    var params = "q="+query+"&pageno="+page+"&category_general=1&category_files=1&category_images=1&category_it=1&category_map=1&category_music=1&category_news=1&category_social+media=1&category_videos=1";
123
+    xmlHttp.open("POST",url,true);
124
+    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
125
+    xmlHttp.setRequestHeader("Content-length", params.length);
126
+    xmlHttp.setRequestHeader("Connection", "close");
127
+    xmlHttp.send(params);
128
+}
129
+
130
+function load_images(page){
131
+    var arrayLength = favicons[page].length;
132
+    for (var i = 1; i < arrayLength+1; i++) {
133
+        var img = new Image();
134
+        img.setAttribute("i",i)
135
+        img.onload = function () {
136
+            var id = 'canvas-'+page+'-'+this.getAttribute("i");
137
+            var can = document.getElementById(id);
138
+            var ctx = can.getContext("2d");
139
+            ctx.drawImage(this, 0, 0, 16, 16);
140
+        };
141
+        img.src = favicons[page][i];
142
+    }
143
+}

+ 3
- 3
searx/static/themes/pix-art/less/search.less 查看文件

35
 
35
 
36
 #search_submit {
36
 #search_submit {
37
 	position: absolute;
37
 	position: absolute;
38
-	top: 13px;
39
-	right: 1px;
38
+	top: 15px;
39
+	right: 5px;
40
 	padding: 0;
40
 	padding: 0;
41
 	border: 0;
41
 	border: 0;
42
 	background: url('../img/search-icon-pixel.png') no-repeat;
42
 	background: url('../img/search-icon-pixel.png') no-repeat;
43
 	background-size: 24px 24px;
43
 	background-size: 24px 24px;
44
 	opacity: 0.8;
44
 	opacity: 0.8;
45
 	width: 24px;
45
 	width: 24px;
46
-	height: 30px;
46
+	height: 24px;
47
 	font-size: 0;
47
 	font-size: 0;
48
 }
48
 }
49
 
49
 

+ 18
- 7
searx/static/themes/pix-art/less/style.less 查看文件

46
 
46
 
47
 @import "search.less";
47
 @import "search.less";
48
 
48
 
49
-// Autocompleter
50
-
51
-
52
 .row {
49
 .row {
53
 	max-width: 800px;
50
 	max-width: 800px;
54
 	margin: 20px auto;
51
 	margin: 20px auto;
116
 	}
113
 	}
117
 }
114
 }
118
 
115
 
119
-input[type="submit"] {
120
-	padding: 2px 6px;
116
+input[type="button"] {
117
+	padding: 4px 12px;
121
 	margin: 2px 4px;
118
 	margin: 2px 4px;
122
 	display: inline-block;
119
 	display: inline-block;
123
 	background: @color-download-button-background;
120
 	background: @color-download-button-background;
127
 	cursor: pointer;
124
 	cursor: pointer;
128
 }
125
 }
129
 
126
 
127
+input[type="button"]:disabled {
128
+	cursor: progress;
129
+}
130
+
130
 input[type="checkbox"] {
131
 input[type="checkbox"] {
131
 	visibility: hidden;
132
 	visibility: hidden;
132
 }
133
 }
136
 	border: 1px solid @color-settings-fieldset;
137
 	border: 1px solid @color-settings-fieldset;
137
 }
138
 }
138
 
139
 
140
+#logo {
141
+	position: absolute;
142
+	top: 13px;
143
+	left: 10px;
144
+}
145
+
139
 #categories {
146
 #categories {
140
 	margin: 0 10px;
147
 	margin: 0 10px;
141
 	.user-select;
148
 	.user-select;
299
 
306
 
300
 #pagination {
307
 #pagination {
301
 	clear: both;
308
 	clear: both;
302
-
309
+	text-align: center;
303
         br {
310
         br {
304
         	clear: both;
311
         	clear: both;
305
         }
312
         }
346
         div.title {
353
         div.title {
347
 
354
 
348
         	h1 {
355
         	h1 {
349
-                        font-size: 1em;
356
+                font-size: 1em;
350
         	}
357
         	}
351
         }
358
         }
352
 
359
 
398
 	#search_url {
405
 	#search_url {
399
 		display: none;
406
 		display: none;
400
 	}
407
 	}
408
+
409
+	#logo {
410
+		display: none;
411
+	}
401
 }
412
 }
402
 
413
 
403
 .favicon {
414
 .favicon {

+ 6
- 0
searx/templates/pix-art/base.html 查看文件

14
         {% block meta %}{% endblock %}
14
         {% block meta %}{% endblock %}
15
         {% block head %}
15
         {% block head %}
16
         {% endblock %}
16
         {% endblock %}
17
+        <script type="text/javascript">
18
+        var favicons = [[]];
19
+        </script>
17
     </head>
20
     </head>
18
     <body>
21
     <body>
19
         <div id="container">
22
         <div id="container">
23
                     searx = {};
26
                     searx = {};
24
             </script>
27
             </script>
25
             <script src="{{ url_for('static', filename='js/searx.js') }}" ></script>
28
             <script src="{{ url_for('static', filename='js/searx.js') }}" ></script>
29
+            <script type="text/javascript">
30
+            load_images(1);
31
+            </script>
26
         </div>
32
         </div>
27
     </body>
33
     </body>
28
 </html>
34
 </html>

+ 1
- 8
searx/templates/pix-art/result_templates/default.html 查看文件

2
 	<canvas id="canvas-{{ pageno }}-{{ index }}" class="icon" width="16" height="16"></canvas>
2
 	<canvas id="canvas-{{ pageno }}-{{ index }}" class="icon" width="16" height="16"></canvas>
3
 </a>
3
 </a>
4
 <script type="text/javascript">
4
 <script type="text/javascript">
5
-var img{{ pageno }}_{{ index }} = new Image();
6
-img{{ pageno }}_{{ index }}.src = 'http://{{ result.url | extract_domain }}/favicon.ico';
7
-
8
-img{{ pageno }}_{{ index }}.onload = function () { 
9
-    var can{{ pageno }}_{{ index }} = document.getElementById('canvas-{{ pageno }}-{{ index }}');
10
-    var ctx = can{{ pageno }}_{{ index }}.getContext("2d");
11
-    ctx.drawImage(img{{ pageno }}_{{ index }}, 0, 0, 16, 16);
12
-};
5
+favicons[{{ pageno }}][{{ index }}] = 'http://{{ result.url | extract_domain }}/favicon.ico';
13
 </script>
6
 </script>

+ 14
- 26
searx/templates/pix-art/results.html 查看文件

1
+{% if pageno > 1 %}
2
+    {% for result in results %}
3
+        {% set index = loop.index %}
4
+        {% include 'pix-art/result_templates/default.html' %}
5
+    {% endfor %}
6
+{% else %}
1
 {% extends "pix-art/base.html" %}
7
 {% extends "pix-art/base.html" %}
2
 {% block title %}{{ q }} - {% endblock %}
8
 {% block title %}{{ q }} - {% endblock %}
3
 {% block meta %}{% endblock %}
9
 {% block meta %}{% endblock %}
4
 {% block content %}
10
 {% block content %}
11
+<div id="logo"><a href="./"><img src="{{ url_for('static', filename='img/searx-pixel-small.png') }}" alt="Searx Logo"/></a></div>
5
 <div class="preferences_container right"><a href="{{ url_for('preferences') }}" id="preferences"><span>preferences</span></a></div>
12
 <div class="preferences_container right"><a href="{{ url_for('preferences') }}" id="preferences"><span>preferences</span></a></div>
6
 <div class="small search center">
13
 <div class="small search center">
7
     {% include 'pix-art/search.html' %}
14
     {% include 'pix-art/search.html' %}
8
 </div>
15
 </div>
16
+<script type="text/javascript">
17
+    favicons[{{ pageno }}] = [];
18
+</script>
9
 <div id="results">
19
 <div id="results">
20
+    <span id="results_list">
10
     {% for result in results %}
21
     {% for result in results %}
11
         {% set index = loop.index %}
22
         {% set index = loop.index %}
12
         {% include 'pix-art/result_templates/default.html' %}
23
         {% include 'pix-art/result_templates/default.html' %}
13
     {% endfor %}
24
     {% endfor %}
14
-
15
-    {% if paging %}
25
+    </span>
16
     <div id="pagination">
26
     <div id="pagination">
17
-        {% if pageno > 1 %}
18
-            <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
19
-                <div class="{% if rtl %}right{% else %}left{% endif %}">
20
-                <input type="hidden" name="q" value="{{ q }}" />
21
-                {% for category in selected_categories %}
22
-                <input type="hidden" name="category_{{ category }}" value="1"/>
23
-                {% endfor %}
24
-                <input type="hidden" name="pageno" value="{{ pageno-1 }}" />
25
-                <input type="submit" value="<< {{ _('previous page') }}" />
26
-                </div>
27
-            </form>
28
-        {% endif %}
29
-        <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
30
-            <div class="{% if rtl %}left{% else %}right{% endif %}">
31
-                {% for category in selected_categories %}
32
-                <input type="hidden" name="category_{{ category }}" value="1"/>
33
-                {% endfor %}
34
-                <input type="hidden" name="q" value="{{ q }}" />
35
-                <input type="hidden" name="pageno" value="{{ pageno+1 }}" />
36
-                <input type="submit" value="{{ _('next page') }} >>" />
37
-            </div>
38
-        </form>
39
-
40
         <br />
27
         <br />
28
+        <input type="button" onclick="load_more('{{ q }}', {{ pageno+1 }})" id="load_more" value="{{ _('Load more...') }}" />
41
     </div>
29
     </div>
42
-    {% endif %}
43
 </div>
30
 </div>
44
 {% endblock %}
31
 {% endblock %}
32
+{% endif %}

+ 1
- 1
searx/templates/pix-art/search.html 查看文件

1
 <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" id="search_form">
1
 <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" id="search_form">
2
     <div id="search_wrapper">
2
     <div id="search_wrapper">
3
         <input type="text" placeholder="{{ _('Search for...') }}" id="q" class="q" name="q" tabindex="1" size="100" {% if q %}value="{{ q }}"{% endif %}/>
3
         <input type="text" placeholder="{{ _('Search for...') }}" id="q" class="q" name="q" tabindex="1" size="100" {% if q %}value="{{ q }}"{% endif %}/>
4
-        <input type="submit" value="search" id="search_submit" />
4
+        <input type="submit" value="" id="search_submit" />
5
         {% for category in categories %}
5
         {% for category in categories %}
6
         <input type="hidden" name="category_{{ category }}" value="1"/>
6
         <input type="hidden" name="category_{{ category }}" value="1"/>
7
         {% endfor %}
7
         {% endfor %}