瀏覽代碼

[enh] add nojs support into oscar-template

Thomas Pointhuber 10 年之前
父節點
當前提交
5bfaabeb6b

+ 7
- 2
searx/search.py 查看文件

@@ -384,12 +384,17 @@ class Search(object):
384 384
             for pd_name, pd in self.request_data.items():
385 385
                 if pd_name.startswith('category_'):
386 386
                     category = pd_name[9:]
387
+
387 388
                     # if category is not found in list, skip
388 389
                     if category not in categories:
389 390
                         continue
390 391
 
391
-                    # add category to list
392
-                    self.categories.append(category)
392
+                    if pd != 'off':
393
+                        # add category to list
394
+                        self.categories.append(category)
395
+                    elif category in self.categories:
396
+                        # remove category from list if property is set to 'off'
397
+                        self.categories.remove(category)
393 398
 
394 399
             # if no category is specified for this search,
395 400
             # using user-defined default-configuration which

+ 9
- 5
searx/static/themes/oscar/css/oscar.min.css 查看文件

@@ -1,11 +1,14 @@
1 1
 html{position:relative;min-height:100%}
2 2
 body{margin-bottom:80px}
3 3
 .footer{position:absolute;bottom:0;width:100%;height:60px}
4
-input[type=checkbox]:checked~.label_hide_if_checked{display:none}
5
-input[type=checkbox]:not(:checked)~.label_hide_if_not_checked{display:none}
6
-.result_header{margin-bottom:5px;margin-top:20px}.result_header .favicon{margin-bottom:-3px}
7
-.result_header a{vertical-align:bottom}.result_header a .highlight{font-weight:bold}
8
-.result-content{margin-top:5px}.result-content .highlight{font-weight:bold}
4
+input[type=checkbox]:checked+.label_hide_if_checked,input[type=checkbox]:checked+.label_hide_if_not_checked+.label_hide_if_checked{display:none}
5
+input[type=checkbox]:not(:checked)+.label_hide_if_not_checked,input[type=checkbox]:not(:checked)+.label_hide_if_checked+.label_hide_if_not_checked{display:none}
6
+.result_header{margin-bottom:5px;margin-top:20px}
7
+.result_header .favicon{margin-bottom:-3px}
8
+.result_header a{vertical-align:bottom}
9
+.result_header a .highlight{font-weight:bold}
10
+.result-content{margin-top:5px}
11
+.result-content .highlight{font-weight:bold}
9 12
 .result-default{clear:both}
10 13
 .result-images{float:left !important}
11 14
 .img-thumbnail{margin:5px;max-height:128px;min-height:128px}
@@ -20,3 +23,4 @@ input[type=checkbox]:not(:checked)~.label_hide_if_not_checked{display:none}
20 23
 .search_categories{margin:10px 0;text-transform:capitalize}
21 24
 .cursor-text{cursor:text !important}
22 25
 .cursor-pointer{cursor:pointer !important}
26
+

+ 2
- 2
searx/static/themes/oscar/less/oscar/checkbox.less 查看文件

@@ -1,9 +1,9 @@
1 1
 // Hide element if checkbox is checked
2
-input[type=checkbox]:checked ~ .label_hide_if_checked {
2
+input[type=checkbox]:checked + .label_hide_if_checked, input[type=checkbox]:checked + .label_hide_if_not_checked + .label_hide_if_checked {
3 3
   display:none;
4 4
 }
5 5
 
6 6
 // Hide element if checkbox is not checked
7
-input[type=checkbox]:not(:checked) ~ .label_hide_if_not_checked {
7
+input[type=checkbox]:not(:checked) + .label_hide_if_not_checked, input[type=checkbox]:not(:checked) + .label_hide_if_checked + .label_hide_if_not_checked {
8 8
   display:none;
9 9
 }

+ 2
- 1
searx/templates/oscar/base.html 查看文件

@@ -36,7 +36,8 @@
36 36
     </script>
37 37
     <noscript>
38 38
         <style type="text/css">
39
-            .tab-content > .active_if_nojs {display: block;}
39
+            .tab-content > .active_if_nojs, .active_if_nojs {display: block;}
40
+            .margin_top_if_nojs {margin-top: 20px;}
40 41
             .hide_if_nojs {display: none !important;overflow:none !important;}
41 42
         </style>
42 43
     </noscript>

+ 17
- 1
searx/templates/oscar/categories.html 查看文件

@@ -1,6 +1,22 @@
1
-<div id="categories" class="btn-group btn-toggle" data-toggle="buttons">
1
+<!-- used if scripts are disabled -->
2
+<noscript>
3
+<div id="categories" class="btn-group btn-toggle">
4
+{% for category in categories %}
5
+    <!--<div class="checkbox">-->
6
+        <input class="hidden" type="checkbox" id="checkbox_{{ category|replace(' ', '_') }}_nojs" name="category_{{ category }}" {% if category in selected_categories %}checked="checked"{% endif %} />
7
+        <label class="btn btn-sm btn-primary active label_hide_if_not_checked" for="checkbox_{{ category|replace(' ', '_') }}_nojs">{{ _(category) }}</label>
8
+        <label class="btn btn-sm btn-default label_hide_if_checked" for="checkbox_{{ category|replace(' ', '_') }}_nojs">{{ _(category) }}</label>
9
+    <!--</div>-->
10
+    {% if category in selected_categories %}<input class="hidden" type="checkbox" id="checkbox_{{ category|replace(' ', '_') }}_dis_activation" name="category_{{ category }}" value="off" checked="checked"/>{% endif %}
11
+{% endfor %}
12
+</div>
13
+</noscript>
14
+
15
+<div id="categories" class="btn-group btn-toggle hide_if_nojs" data-toggle="buttons">
2 16
 {% for category in categories %}
3 17
     <label class="btn btn-sm {% if category in selected_categories %}btn-primary active{% else %}btn-default{% endif %}" data-btn-class="primary">
4 18
         <input class="hidden" type="checkbox" id="checkbox_{{ category|replace(' ', '_') }}" name="category_{{ category }}" {% if category in selected_categories %}checked="checked"{% endif %} />{{ _(category) }}</label>
5 19
 {% endfor %}
6 20
 </div>
21
+
22
+

+ 2
- 2
searx/templates/oscar/search_full.html 查看文件

@@ -8,8 +8,8 @@
8 8
         </span>
9 9
     </div>
10 10
 
11
-    <button type="button" class="btn btn-link btn-collapse center-block collapsed" data-toggle="collapse" data-target="#search_categories" data-btn-text-collapsed="{{ _('Show search filters') }}" data-btn-text-not-collapsed="{{ _('Hide search filters') }}">{{ _('Show search filters') }}</button>
12
-    <div class="row collapse" id="search_categories">
11
+    <button type="button" class="btn btn-link btn-collapse center-block collapsed hide_if_nojs" data-toggle="collapse" data-target="#search_categories" data-btn-text-collapsed="{{ _('Show search filters') }}" data-btn-text-not-collapsed="{{ _('Hide search filters') }}">{{ _('Show search filters') }}</button>
12
+    <div class="row collapse active_if_nojs margin_top_if_nojs" id="search_categories">
13 13
         <div class="col-md-12 text-center">
14 14
             {% include 'oscar/categories.html' %}
15 15
         </div>