Theme: implement search_on_category_select as a preference

The implementation is change to work without javascript:
When enabled, the HTML page contains buttons instead of checkboxes.

* Related to https://github.com/searxng/searxng/issues/769#issuecomment-1132481995
* Fix https://github.com/searxng/searxng/issues/854
This commit is contained in:
Alexandre Flament 2022-07-02 21:09:26 +02:00
parent 69a6d994e1
commit 3de28b283a
9 changed files with 87 additions and 55 deletions

View file

@ -13,8 +13,10 @@
} -%}
<div id="categories" class="search_categories">{{- '' -}}
<div id="categories_container">
{%- if not search_on_category_select or not display_tooltip -%}
{%- for category in categories_as_tabs -%}
<div class="category"><input type="checkbox" id="checkbox_{{ category|replace(' ', '_') }}" name="category_{{ category }}"{% if category in selected_categories %} checked="checked"{% endif %}/>
<div class="category category_checkbox">{{- '' -}}
<input type="checkbox" id="checkbox_{{ category|replace(' ', '_') }}" name="category_{{ category }}"{% if category in selected_categories %} checked="checked"{% endif %}/>
<label for="checkbox_{{ category|replace(' ', '_') }}" class="tooltips">
{{- icon_big(category_icons[category]) if category in category_icons else icon_big('globe-outline') -}}
<div class="category_name">{{- _(category) -}}</div>
@ -22,5 +24,14 @@
</div>
{%- endfor -%}
{%- if display_tooltip %}<div class="help">{{ _('Click on the magnifier to perform search') }}</div>{% endif -%}
{%- else -%}
{%- for category in categories_as_tabs -%}{{- '\n' -}}
<button type="submit" name="category_{{ category|replace(' ', '_') }}" value="on" class="category category_button {% if category in selected_categories %}selected{% endif %}">
{{- icon_big(category_icons[category]) if category in category_icons else icon_big('globe-outline') -}}
<div class="category_name">{{- _(category) -}}</div>{{- '' -}}
</button>{{- '' -}}
{%- endfor -%}
{{- '\n' -}}
{%- endif -%}
</div>{{- '' -}}
</div>

View file

@ -248,6 +248,18 @@
<div class="description">{{ _('Automatically load next page when scrolling to bottom of current page') }}</div>
</fieldset>
{% endif %}
{% if 'search_on_category_select' not in locked_preferences %}
<fieldset>
<legend>{{ _('Search on category select') }}</legend>
<p class="value">
<select name='search_on_category_select'>
<option value="1" {% if search_on_category_select %}selected="selected"{% endif %}>{{ _('On') }}</option>
<option value="0" {% if not search_on_category_select %}selected="selected"{% endif %}>{{ _('Off')}}</option>
</select>
</p>
<div class="description">{{ _('Perform search immediately if a category selected. Disable to select multiple categories. (JavaScript required)') }}</div>
</fieldset>
{% endif %}
{{ plugin_preferences('ui') }}
{{ tab_footer() }}