Browse Source

Merge pull request #174 from pointhi/nojs_fix

add no javascript support to oscar-template
Adam Tauber 10 years ago
parent
commit
c5599e3c7c

+ 7
- 2
searx/search.py View File

@@ -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 View File

@@ -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 View File

@@ -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
 }

+ 3
- 1
searx/templates/oscar/base.html View File

@@ -36,8 +36,10 @@
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 !important; visibility: visible !important;}
40
+            .margin_top_if_nojs {margin-top: 20px;}
40 41
             .hide_if_nojs {display: none !important;overflow:none !important;}
42
+            .disabled_if_nojs {pointer-events: none; cursor: default; text-decoration: line-through;}
41 43
         </style>
42 44
     </noscript>
43 45
 </head>

+ 17
- 1
searx/templates/oscar/categories.html View File

@@ -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
+

+ 1
- 1
searx/templates/oscar/result_templates/default.html View File

@@ -6,7 +6,7 @@
6 6
 <small><a class="text-info" href="https://web.archive.org/web/{{ result.url }}">{{ icon('link') }} {{ _('cached') }}</a></small>
7 7
 
8 8
 {% if result.embedded %}
9
-    <small> &bull; <a class="text-info btn-collapse collapsed cursor-pointer media-loader" data-toggle="collapse" data-target="#result-media-{{ index }}" data-btn-text-collapsed="{{ _('show media') }}" data-btn-text-not-collapsed="{{ _('hide media') }}">{{ icon('music') }} {{ _('show media') }}</a></small>
9
+    <small> &bull; <a class="text-info btn-collapse collapsed cursor-pointer media-loader disabled_if_nojs" data-toggle="collapse" data-target="#result-media-{{ index }}" data-btn-text-collapsed="{{ _('show media') }}" data-btn-text-not-collapsed="{{ _('hide media') }}">{{ icon('music') }} {{ _('show media') }}</a></small>
10 10
 {% endif %}
11 11
 
12 12
 {% if result.embedded %}

+ 3
- 3
searx/templates/oscar/result_templates/map.html View File

@@ -7,15 +7,15 @@
7 7
 <small><a class="text-info" href="https://web.archive.org/web/{{ result.pretty_url }}">{{ icon('link') }} {{ _('cached') }}</a></small>
8 8
 
9 9
 {% if (result.latitude and result.longitude) or result.boundingbox %}
10
-    <small> &bull; <a class="text-info btn-collapse collapsed searx_init_map cursor-pointer" data-toggle="collapse" data-target="#result-map-{{ index }}" data-leaflet-target="osm-map-{{ index }}" data-map-lon="{{ result.longitude }}" data-map-lat="{{ result.latitude }}" {% if result.boundingbox %}data-map-boundingbox='{{ result.boundingbox|tojson|safe }}'{% endif %} {% if result.geojson %}data-map-geojson='{{ result.geojson|tojson|safe }}'{% endif %} data-btn-text-collapsed="{{ _('show map') }}" data-btn-text-not-collapsed="{{ _('hide map') }}">{{ icon('globe') }} {{ _('show map') }}</a></small>
10
+    <small> &bull; <a class="text-info btn-collapse collapsed searx_init_map cursor-pointer disabled_if_nojs" data-toggle="collapse" data-target="#result-map-{{ index }}" data-leaflet-target="osm-map-{{ index }}" data-map-lon="{{ result.longitude }}" data-map-lat="{{ result.latitude }}" {% if result.boundingbox %}data-map-boundingbox='{{ result.boundingbox|tojson|safe }}'{% endif %} {% if result.geojson %}data-map-geojson='{{ result.geojson|tojson|safe }}'{% endif %} data-btn-text-collapsed="{{ _('show map') }}" data-btn-text-not-collapsed="{{ _('hide map') }}">{{ icon('globe') }} {{ _('show map') }}</a></small>
11 11
 {% endif %}
12 12
 
13 13
 {% if result.osm and (result.osm.type and result.osm.id) %}
14
-    <small> &bull; <a class="text-info btn-collapse collapsed cursor-pointer searx_overpass_request" data-toggle="collapse" data-target="#result-overpass-{{ index }}" data-osm-type="{{ result.osm.type }}" data-osm-id="{{ result.osm.id }}" data-result-table="result-overpass-table-{{ index }}" data-result-table-loadicon="result-overpass-table-loading-{{ index }}" data-btn-text-collapsed="{{ _('show details') }}" data-btn-text-not-collapsed="{{ _('hide details') }}">{{ icon('map-marker') }} {{ _('show details') }}</a></small>
14
+    <small> &bull; <a class="text-info btn-collapse collapsed cursor-pointer searx_overpass_request disabled_if_nojs" data-toggle="collapse" data-target="#result-overpass-{{ index }}" data-osm-type="{{ result.osm.type }}" data-osm-id="{{ result.osm.id }}" data-result-table="result-overpass-table-{{ index }}" data-result-table-loadicon="result-overpass-table-loading-{{ index }}" data-btn-text-collapsed="{{ _('show details') }}" data-btn-text-not-collapsed="{{ _('hide details') }}">{{ icon('map-marker') }} {{ _('show details') }}</a></small>
15 15
 {% endif %}
16 16
 
17 17
 {# {% if (result.latitude and result.longitude) %}
18
-    <small> &bull; <a class="text-info btn-collapse collapsed cursor-pointer" data-toggle="collapse" data-target="#result-geodata-{{ index }}" data-btn-text-collapsed="{{ _('show geodata') }}" data-btn-text-not-collapsed="{{ _('hide geodata') }}">{{ icon('map-marker') }} {{ _('show geodata') }}</a></small>
18
+    <small> &bull; <a class="text-info btn-collapse collapsed cursor-pointer disabled_if_nojs" data-toggle="collapse" data-target="#result-geodata-{{ index }}" data-btn-text-collapsed="{{ _('show geodata') }}" data-btn-text-not-collapsed="{{ _('hide geodata') }}">{{ icon('map-marker') }} {{ _('show geodata') }}</a></small>
19 19
 {% endif %} #}
20 20
 
21 21
 <div class="container-fluid">

+ 1
- 1
searx/templates/oscar/result_templates/videos.html View File

@@ -6,7 +6,7 @@
6 6
 <small><a class="text-info" href="https://web.archive.org/web/{{ result.url }}">{{ icon('link') }} {{ _('cached') }}</a></small>
7 7
 
8 8
 {% if result.embedded %}
9
-    <small> &bull; <a class="text-info btn-collapse collapsed cursor-pointer media-loader" data-toggle="collapse" data-target="#result-video-{{ index }}" data-btn-text-collapsed="{{ _('show video') }}" data-btn-text-not-collapsed="{{ _('hide video') }}">{{ icon('film') }} {{ _('show video') }}</a></small>
9
+    <small> &bull; <a class="text-info btn-collapse collapsed cursor-pointer media-loader disabled_if_nojs" data-toggle="collapse" data-target="#result-video-{{ index }}" data-btn-text-collapsed="{{ _('show video') }}" data-btn-text-not-collapsed="{{ _('hide video') }}">{{ icon('film') }} {{ _('show video') }}</a></small>
10 10
 {% endif %}
11 11
 
12 12
 {% if result.embedded %}

+ 1
- 1
searx/templates/oscar/search.html View File

@@ -3,7 +3,7 @@
3 3
     <div class="input-group col-sm-12">
4 4
         <input type="search" name="q" class="form-control" id="q" placeholder="{{ _('Search for...') }}" autocomplete="off" value="{{ q }}">
5 5
         <span class="input-group-btn">
6
-            <button type="submit" class="btn btn-default">{{ icon('search') }}<span class="sr-only">{{ _('Start search') }}</span></button>
6
+            <button type="submit" class="btn btn-default"><span class="hide_if_nojs">{{ icon('search') }}</span><span class="hidden active_if_nojs">{{ _('Start search') }}</span></button>
7 7
         </span>
8 8
     </div>
9 9
     <div class="search_categories">

+ 3
- 3
searx/templates/oscar/search_full.html View File

@@ -4,12 +4,12 @@
4 4
     <div class="input-group col-md-8 col-md-offset-2">
5 5
         <input type="search" name="q" class="form-control input-lg autofocus" id="q" placeholder="{{ _('Search for...') }}" autocomplete="off" value="{{ q }}">
6 6
         <span class="input-group-btn">
7
-            <button type="submit" class="btn btn-default input-lg">{{ icon('search') }}<span class="sr-only">{{ _('Start search') }}</span></button>
7
+            <button type="submit" class="btn btn-default input-lg"><span class="hide_if_nojs">{{ icon('search') }}</span><span class="hidden active_if_nojs">{{ _('Start search') }}</span></button>
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>