on master help sign in
[enh] add nojs support into oscar-template
commit5bfaabeb6bb50844fd7389770eb5c8a64e63f13e authorThomas Pointhuber <thomas.pointhuber@gmx.at> dateThu 15 Jan 2015, 15:48 (12 years ago) parent410dbc5
6 files changed+39−13
searx/search.py+7−2 searx/static/themes/oscar/css/oscar.min.css+9−5 searx/static/themes/oscar/less/oscar/checkbox.less+2−2 searx/templates/oscar/base.html+2−1 searx/templates/oscar/categories.html+17−1 searx/templates/oscar/search_full.html+2−2
searx/search.py+7−2
@@ -384,12 +384,17 @@ class Search(object):
384384 for pd_name, pd in self.request_data.items():
385385 if pd_name.startswith('category_'):
386386 category = pd_name[9:]
387+
387388 # if category is not found in list, skip
388389 if category not in categories:
389390 continue
390391
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)
393398
394399 # if no category is specified for this search,
395400 # using user-defined default-configuration which
searx/static/themes/oscar/css/oscar.min.css+9−5
@@ -1,11 +1,14 @@
11html{position:relative;min-height:100%}
22body{margin-bottom:80px}
33.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}
912.result-default{clear:both}
1013.result-images{float:left !important}
1114.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}
2023.search_categories{margin:10px 0;text-transform:capitalize}
2124.cursor-text{cursor:text !important}
2225.cursor-pointer{cursor:pointer !important}
26+
searx/static/themes/oscar/less/oscar/checkbox.less+2−2
@@ -1,9 +1,9 @@
11// 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 {
33 display:none;
44}
55
66// 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 {
88 display:none;
99}
searx/templates/oscar/base.html+2−1
@@ -36,7 +36,8 @@
3636 </script>
3737 <noscript>
3838 <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;}
4041 .hide_if_nojs {display: none !important;overflow:none !important;}
4142 </style>
4243 </noscript>
searx/templates/oscar/categories.html+17−1
@@ -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">
216{% for category in categories %}
317 <label class="btn btn-sm {% if category in selected_categories %}btn-primary active{% else %}btn-default{% endif %}" data-btn-class="primary">
418 <input class="hidden" type="checkbox" id="checkbox_{{ category|replace(' ', '_') }}" name="category_{{ category }}" {% if category in selected_categories %}checked="checked"{% endif %} />{{ _(category) }}</label>
519{% endfor %}
620</div>
21+
22+
searx/templates/oscar/search_full.html+2−2
@@ -8,8 +8,8 @@
88 </span>
99 </div>
1010
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">
1313 <div class="col-md-12 text-center">
1414 {% include 'oscar/categories.html' %}
1515 </div>