From 973c97c85b493bf142bd1b903cf9bf8931fcfbad Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Sun, 12 Apr 2015 19:27:48 +0200 Subject: [PATCH] [enh] new plugin: search on category select (currently only in oscar theme) TODO purge mootools from default/courgette and integrate jquery ++ this theme --- searx/plugins/__init__.py | 4 +++- searx/plugins/search_on_category_select.py | 6 ++++++ searx/static/js/search_on_category_select.js | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 searx/plugins/search_on_category_select.py create mode 100644 searx/static/js/search_on_category_select.js diff --git a/searx/plugins/__init__.py b/searx/plugins/__init__.py index f3cf1bf2b..adcbd28fc 100644 --- a/searx/plugins/__init__.py +++ b/searx/plugins/__init__.py @@ -1,4 +1,5 @@ -from searx.plugins import self_ip +from searx.plugins import (self_ip, + search_on_category_select) from searx import logger from sys import exit @@ -52,3 +53,4 @@ class PluginStore(): plugins = PluginStore() plugins.register(self_ip) +plugins.register(search_on_category_select) diff --git a/searx/plugins/search_on_category_select.py b/searx/plugins/search_on_category_select.py new file mode 100644 index 000000000..3b01ce5b5 --- /dev/null +++ b/searx/plugins/search_on_category_select.py @@ -0,0 +1,6 @@ +from flask.ext.babel import gettext +name = 'Search on category select' +description = gettext('Perform search immediately if a category selected') +default_on = False + +js_dependencies = ('js/search_on_category_select.js',) diff --git a/searx/static/js/search_on_category_select.js b/searx/static/js/search_on_category_select.js new file mode 100644 index 000000000..6156ca4e8 --- /dev/null +++ b/searx/static/js/search_on_category_select.js @@ -0,0 +1,14 @@ +$(document).ready(function() { + if($('#q')) { + $('#categories label').click(function(e) { + $('#categories input[type="checkbox"]').each(function(i, checkbox) { + $(checkbox).prop('checked', false); + }); + $('#categories label').removeClass('btn-primary').removeClass('active').addClass('btn-default'); + $(this).removeClass('btn-default').addClass('btn-primary').addClass('active'); + $($(this).children()[0]).prop('checked', 'checked'); + $('#search_form').submit(); + return false; + }); + } +});