Browse Source

Ajax loading + Tweaks of CSS

Cqoicebordel 10 years ago
parent
commit
e181041f11

+ 1
- 1
searx/static/themes/pix-art/css/style.css
File diff suppressed because it is too large
View File


BIN
searx/static/themes/pix-art/img/searx-pixel-small.png View File


BIN
searx/static/themes/pix-art/img/spinner.gif View File


+ 94
- 0
searx/static/themes/pix-art/js/searx.js View File

@@ -47,3 +47,97 @@ if(searx.autocompleter) {
47 47
 
48 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 View File

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

+ 18
- 7
searx/static/themes/pix-art/less/style.less View File

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

+ 6
- 0
searx/templates/pix-art/base.html View File

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

+ 1
- 8
searx/templates/pix-art/result_templates/default.html View File

@@ -2,12 +2,5 @@
2 2
 	<canvas id="canvas-{{ pageno }}-{{ index }}" class="icon" width="16" height="16"></canvas>
3 3
 </a>
4 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 6
 </script>

+ 14
- 26
searx/templates/pix-art/results.html View File

@@ -1,44 +1,32 @@
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 7
 {% extends "pix-art/base.html" %}
2 8
 {% block title %}{{ q }} - {% endblock %}
3 9
 {% block meta %}{% endblock %}
4 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 12
 <div class="preferences_container right"><a href="{{ url_for('preferences') }}" id="preferences"><span>preferences</span></a></div>
6 13
 <div class="small search center">
7 14
     {% include 'pix-art/search.html' %}
8 15
 </div>
16
+<script type="text/javascript">
17
+    favicons[{{ pageno }}] = [];
18
+</script>
9 19
 <div id="results">
20
+    <span id="results_list">
10 21
     {% for result in results %}
11 22
         {% set index = loop.index %}
12 23
         {% include 'pix-art/result_templates/default.html' %}
13 24
     {% endfor %}
14
-
15
-    {% if paging %}
25
+    </span>
16 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 27
         <br />
28
+        <input type="button" onclick="load_more('{{ q }}', {{ pageno+1 }})" id="load_more" value="{{ _('Load more...') }}" />
41 29
     </div>
42
-    {% endif %}
43 30
 </div>
44 31
 {% endblock %}
32
+{% endif %}

+ 1
- 1
searx/templates/pix-art/search.html View File

@@ -1,7 +1,7 @@
1 1
 <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" id="search_form">
2 2
     <div id="search_wrapper">
3 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 5
         {% for category in categories %}
6 6
         <input type="hidden" name="category_{{ category }}" value="1"/>
7 7
         {% endfor %}