瀏覽代碼

oscar template: implement autocompleter

Thomas Pointhuber 10 年之前
父節點
當前提交
14b0604bc0

+ 189
- 0
searx/static/oscar/css/typeahead.css 查看文件

@@ -0,0 +1,189 @@
1
+/*
2
+ * typehead.js-bootstrap3.less
3
+ * @version 0.2.3
4
+ * https://github.com/hyspace/typeahead.js-bootstrap3.less
5
+ *
6
+ * Licensed under the MIT license:
7
+ * http://www.opensource.org/licenses/MIT
8
+ */
9
+.has-warning .twitter-typeahead .tt-input,
10
+.has-warning .twitter-typeahead .tt-hint {
11
+  border-color: #8a6d3b;
12
+  -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
13
+  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
14
+}
15
+.has-warning .twitter-typeahead .tt-input:focus,
16
+.has-warning .twitter-typeahead .tt-hint:focus {
17
+  border-color: #66512c;
18
+  -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 6px #c0a16b;
19
+  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 6px #c0a16b;
20
+}
21
+.has-error .twitter-typeahead .tt-input,
22
+.has-error .twitter-typeahead .tt-hint {
23
+  border-color: #a94442;
24
+  -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
25
+  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
26
+}
27
+.has-error .twitter-typeahead .tt-input:focus,
28
+.has-error .twitter-typeahead .tt-hint:focus {
29
+  border-color: #843534;
30
+  -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 6px #ce8483;
31
+  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 6px #ce8483;
32
+}
33
+.has-success .twitter-typeahead .tt-input,
34
+.has-success .twitter-typeahead .tt-hint {
35
+  border-color: #3c763d;
36
+  -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
37
+  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
38
+}
39
+.has-success .twitter-typeahead .tt-input:focus,
40
+.has-success .twitter-typeahead .tt-hint:focus {
41
+  border-color: #2b542c;
42
+  -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 6px #67b168;
43
+  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 6px #67b168;
44
+}
45
+.input-group .twitter-typeahead:first-child .tt-input,
46
+.input-group .twitter-typeahead:first-child .tt-hint {
47
+  border-bottom-left-radius: 4px;
48
+  border-top-left-radius: 4px;
49
+}
50
+.input-group .twitter-typeahead:last-child .tt-input,
51
+.input-group .twitter-typeahead:last-child .tt-hint {
52
+  border-bottom-right-radius: 4px;
53
+  border-top-right-radius: 4px;
54
+}
55
+.input-group.input-group-sm .twitter-typeahead .tt-input,
56
+.input-group.input-group-sm .twitter-typeahead .tt-hint {
57
+  height: 30px;
58
+  padding: 5px 10px;
59
+  font-size: 12px;
60
+  line-height: 1.5;
61
+  border-radius: 3px;
62
+}
63
+select.input-group.input-group-sm .twitter-typeahead .tt-input,
64
+select.input-group.input-group-sm .twitter-typeahead .tt-hint {
65
+  height: 30px;
66
+  line-height: 30px;
67
+}
68
+textarea.input-group.input-group-sm .twitter-typeahead .tt-input,
69
+textarea.input-group.input-group-sm .twitter-typeahead .tt-hint,
70
+select[multiple].input-group.input-group-sm .twitter-typeahead .tt-input,
71
+select[multiple].input-group.input-group-sm .twitter-typeahead .tt-hint {
72
+  height: auto;
73
+}
74
+.input-group.input-group-sm .twitter-typeahead:not(:first-child):not(:last-child) .tt-input,
75
+.input-group.input-group-sm .twitter-typeahead:not(:first-child):not(:last-child) .tt-hint {
76
+  border-radius: 0;
77
+}
78
+.input-group.input-group-sm .twitter-typeahead:first-child .tt-input,
79
+.input-group.input-group-sm .twitter-typeahead:first-child .tt-hint {
80
+  border-bottom-left-radius: 3px;
81
+  border-top-left-radius: 3px;
82
+  border-bottom-right-radius: 0;
83
+  border-top-right-radius: 0;
84
+}
85
+.input-group.input-group-sm .twitter-typeahead:last-child .tt-input,
86
+.input-group.input-group-sm .twitter-typeahead:last-child .tt-hint {
87
+  border-bottom-left-radius: 0;
88
+  border-top-left-radius: 0;
89
+  border-bottom-right-radius: 3px;
90
+  border-top-right-radius: 3px;
91
+}
92
+.input-group.input-group-lg .twitter-typeahead .tt-input,
93
+.input-group.input-group-lg .twitter-typeahead .tt-hint {
94
+  height: 46px;
95
+  padding: 10px 16px;
96
+  font-size: 18px;
97
+  line-height: 1.33;
98
+  border-radius: 6px;
99
+}
100
+select.input-group.input-group-lg .twitter-typeahead .tt-input,
101
+select.input-group.input-group-lg .twitter-typeahead .tt-hint {
102
+  height: 46px;
103
+  line-height: 46px;
104
+}
105
+textarea.input-group.input-group-lg .twitter-typeahead .tt-input,
106
+textarea.input-group.input-group-lg .twitter-typeahead .tt-hint,
107
+select[multiple].input-group.input-group-lg .twitter-typeahead .tt-input,
108
+select[multiple].input-group.input-group-lg .twitter-typeahead .tt-hint {
109
+  height: auto;
110
+}
111
+.input-group.input-group-lg .twitter-typeahead:not(:first-child):not(:last-child) .tt-input,
112
+.input-group.input-group-lg .twitter-typeahead:not(:first-child):not(:last-child) .tt-hint {
113
+  border-radius: 0;
114
+}
115
+.input-group.input-group-lg .twitter-typeahead:first-child .tt-input,
116
+.input-group.input-group-lg .twitter-typeahead:first-child .tt-hint {
117
+  border-bottom-left-radius: 6px;
118
+  border-top-left-radius: 6px;
119
+  border-bottom-right-radius: 0;
120
+  border-top-right-radius: 0;
121
+}
122
+.input-group.input-group-lg .twitter-typeahead:last-child .tt-input,
123
+.input-group.input-group-lg .twitter-typeahead:last-child .tt-hint {
124
+  border-bottom-left-radius: 0;
125
+  border-top-left-radius: 0;
126
+  border-bottom-right-radius: 6px;
127
+  border-top-right-radius: 6px;
128
+}
129
+.twitter-typeahead {
130
+  width: 100%;
131
+}
132
+.input-group .twitter-typeahead {
133
+  display: table-cell !important;
134
+  float: left;
135
+}
136
+.twitter-typeahead .tt-hint {
137
+  color: #999999;
138
+}
139
+.twitter-typeahead .tt-input {
140
+  z-index: 2;
141
+}
142
+.twitter-typeahead .tt-input[disabled],
143
+.twitter-typeahead .tt-input[readonly],
144
+fieldset[disabled] .twitter-typeahead .tt-input {
145
+  cursor: not-allowed;
146
+  background-color: #eeeeee !important;
147
+}
148
+.tt-dropdown-menu {
149
+  position: absolute;
150
+  top: 100%;
151
+  left: 0;
152
+  z-index: 1000;
153
+  min-width: 160px;
154
+  width: 100%;
155
+  padding: 5px 0;
156
+  margin: 2px 0 0;
157
+  list-style: none;
158
+  font-size: 14px;
159
+  background-color: #ffffff;
160
+  border: 1px solid #cccccc;
161
+  border: 1px solid rgba(0, 0, 0, 0.15);
162
+  border-radius: 4px;
163
+  -webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
164
+  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
165
+  background-clip: padding-box;
166
+  *border-right-width: 2px;
167
+  *border-bottom-width: 2px;
168
+}
169
+.tt-dropdown-menu .tt-suggestion {
170
+  display: block;
171
+  padding: 3px 20px;
172
+  clear: both;
173
+  font-weight: normal;
174
+  line-height: 1.42857143;
175
+  color: #333333;
176
+  white-space: nowrap;
177
+}
178
+.tt-dropdown-menu .tt-suggestion.tt-cursor {
179
+  text-decoration: none;
180
+  outline: 0;
181
+  background-color: #f5f5f5;
182
+  color: #262626;
183
+}
184
+.tt-dropdown-menu .tt-suggestion.tt-cursor a {
185
+  color: #262626;
186
+}
187
+.tt-dropdown-menu .tt-suggestion p {
188
+  margin: 0;
189
+}

+ 20
- 1
searx/static/oscar/js/scripts.js 查看文件

@@ -7,6 +7,15 @@
7 7
 
8 8
 */
9 9
 
10
+if(searx.autocompleter) {
11
+    searx.searchResults = new Bloodhound({
12
+        datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
13
+        queryTokenizer: Bloodhound.tokenizers.whitespace,
14
+        remote: '/autocompleter?q=%QUERY'
15
+    });
16
+    searx.searchResults.initialize();
17
+}
18
+
10 19
 $(document).ready(function(){
11 20
     $('.btn-toggle .btn').click(function() {
12 21
         var btnClass = 'btn-' + $(this).data('btn-class');
@@ -42,4 +51,14 @@ $(document).ready(function(){
42 51
     $(".select-all-on-click").click(function () {
43 52
         $(this).select();
44 53
     });
45
-});
54
+    
55
+    if(searx.autocompleter) {
56
+        $('#q').typeahead(null, {
57
+            name: 'search-results',
58
+            displayKey: function(result) {
59
+                return result;
60
+            },
61
+            source: searx.searchResults.ttAdapter()
62
+        });
63
+    }
64
+});  

+ 7
- 0
searx/static/oscar/js/typeahead.bundle.min.js
文件差異過大導致無法顯示
查看文件


+ 3
- 0
searx/templates/oscar/base.html 查看文件

@@ -9,6 +9,7 @@
9 9
     <title>{% block title %}{% endblock %}searx</title>
10 10
     
11 11
     <link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap.min.css') }}" type="text/css" />
12
+    {% if autocomplete %}<link rel="stylesheet" href="{{ url_for('static', filename='css/typeahead.css') }}" type="text/css" />{% endif %}
12 13
     <link rel="stylesheet" href="{{ url_for('static', filename='css/oscar.css') }}" type="text/css" />  
13 14
     
14 15
     <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
@@ -28,6 +29,7 @@
28 29
     
29 30
     <script type="text/javascript">
30 31
         searx = {};
32
+        searx.method = "{{ method or 'POST' }}";
31 33
         searx.autocompleter = {% if autocomplete %}true{% else %}false{% endif %};
32 34
     </script>
33 35
 </head>
@@ -62,6 +64,7 @@
62 64
     </div>
63 65
     <script src="{{ url_for('static', filename='js/jquery-1.11.1.min.js') }}"></script>
64 66
     <script src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script>
67
+    {% if autocomplete %}<script src="{{ url_for('static', filename='js/typeahead.bundle.min.js') }}"></script>{% endif %}
65 68
     <script src="{{ url_for('static', filename='js/scripts.js') }}"></script>
66 69
 </body>
67 70
 </html>