mirror of
https://github.com/searxng/searxng
synced 2024-01-01 19:24:07 +01:00
[fix] plugins in simple theme
The previous commit introduced a new plugin Resource API. This commit implements the necessary changes in the simple theme. (There's no change to infinite_scroll.py because it hasn't actually yet been implemented in the Simple theme.)
This commit is contained in:
parent
3f77ff29a3
commit
1af96e2a7e
7 changed files with 46 additions and 52 deletions
|
@ -26,4 +26,5 @@ preference_section = 'ui'
|
||||||
|
|
||||||
js_dependencies = (
|
js_dependencies = (
|
||||||
Resource(path='plugins/js/search_on_category_select.js', themes=('oscar',)),
|
Resource(path='plugins/js/search_on_category_select.js', themes=('oscar',)),
|
||||||
|
Resource(path='themes/simple/src/js/plugins/search_on_category_select.js', themes=('simple',)),
|
||||||
)
|
)
|
||||||
|
|
|
@ -12,5 +12,6 @@ preference_section = 'ui'
|
||||||
|
|
||||||
js_dependencies = (
|
js_dependencies = (
|
||||||
Resource(path='plugins/js/vim_hotkeys.js', themes=('oscar',)),
|
Resource(path='plugins/js/vim_hotkeys.js', themes=('oscar',)),
|
||||||
|
Resource(path='themes/simple/src/js/plugins/vim_hotkeys.js', themes=('simple',)),
|
||||||
)
|
)
|
||||||
css_dependencies = (Resource(path='plugins/css/vim_hotkeys.css', themes=('oscar',)),)
|
css_dependencies = (Resource(path='plugins/css/vim_hotkeys.css', themes=('oscar',)),)
|
||||||
|
|
|
@ -19,9 +19,6 @@
|
||||||
touch: (("ontouchstart" in w) || w.DocumentTouch && document instanceof DocumentTouch) || false,
|
touch: (("ontouchstart" in w) || w.DocumentTouch && document instanceof DocumentTouch) || false,
|
||||||
method: script.getAttribute('data-method'),
|
method: script.getAttribute('data-method'),
|
||||||
autocompleter: script.getAttribute('data-autocompleter') === 'true',
|
autocompleter: script.getAttribute('data-autocompleter') === 'true',
|
||||||
search_on_category_select: script.getAttribute('data-search-on-category-select') === 'true',
|
|
||||||
infinite_scroll: script.getAttribute('data-infinite-scroll') === 'true',
|
|
||||||
hotkeys: script.getAttribute('data-hotkeys') === 'true',
|
|
||||||
static_path: script.getAttribute('data-static-path'),
|
static_path: script.getAttribute('data-static-path'),
|
||||||
translations: JSON.parse(script.getAttribute('data-translations')),
|
translations: JSON.parse(script.getAttribute('data-translations')),
|
||||||
theme: {
|
theme: {
|
||||||
|
@ -37,4 +34,4 @@
|
||||||
if (w.searxng.touch) {
|
if (w.searxng.touch) {
|
||||||
hmtlElement.classList.add('touch');
|
hmtlElement.classList.add('touch');
|
||||||
}
|
}
|
||||||
})(window, document);
|
})(window, document);
|
||||||
|
|
|
@ -12,13 +12,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function submitIfQuery () {
|
|
||||||
if (qinput.value.length > 0) {
|
|
||||||
var search = document.getElementById('search');
|
|
||||||
setTimeout(search.submit.bind(search), 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function createClearButton (qinput) {
|
function createClearButton (qinput) {
|
||||||
var cs = document.getElementById('clear_search');
|
var cs = document.getElementById('clear_search');
|
||||||
var updateClearButton = function () {
|
var updateClearButton = function () {
|
||||||
|
@ -95,30 +88,6 @@
|
||||||
qinput.addEventListener('focus', placeCursorAtEndOnce, false);
|
qinput.addEventListener('focus', placeCursorAtEndOnce, false);
|
||||||
qinput.focus();
|
qinput.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
// vanilla js version of search_on_category_select.js
|
|
||||||
if (qinput !== null && d.querySelector('.help') != null && searxng.search_on_category_select) {
|
|
||||||
d.querySelector('.help').className = 'invisible';
|
|
||||||
|
|
||||||
searxng.on('#categories input', 'change', function () {
|
|
||||||
var i, categories = d.querySelectorAll('#categories input[type="checkbox"]');
|
|
||||||
for (i = 0; i < categories.length; i++) {
|
|
||||||
if (categories[i] !== this && categories[i].checked) {
|
|
||||||
categories[i].click();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (! this.checked) {
|
|
||||||
this.click();
|
|
||||||
}
|
|
||||||
submitIfQuery();
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
searxng.on(d.getElementById('safesearch'), 'change', submitIfQuery);
|
|
||||||
searxng.on(d.getElementById('time_range'), 'change', submitIfQuery);
|
|
||||||
searxng.on(d.getElementById('language'), 'change', submitIfQuery);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
})(window, document, window.searxng);
|
})(window, document, window.searxng);
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
const qinput = document.getElementById('q');
|
||||||
|
|
||||||
|
function submitIfQuery() {
|
||||||
|
if (qinput.value.length > 0) {
|
||||||
|
var search = document.getElementById('search');
|
||||||
|
setTimeout(search.submit.bind(search), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// vanilla js version of search_on_category_select.js
|
||||||
|
if (qinput !== null && document.querySelector('.help') != null) {
|
||||||
|
document.querySelector('.help').className = 'invisible';
|
||||||
|
|
||||||
|
searxng.on('#categories input', 'change', function () {
|
||||||
|
var i, categories = document.querySelectorAll('#categories input[type="checkbox"]');
|
||||||
|
for (i = 0; i < categories.length; i++) {
|
||||||
|
if (categories[i] !== this && categories[i].checked) {
|
||||||
|
categories[i].click();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!this.checked) {
|
||||||
|
this.click();
|
||||||
|
}
|
||||||
|
submitIfQuery();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
searxng.on(document.getElementById('safesearch'), 'change', submitIfQuery);
|
||||||
|
searxng.on(document.getElementById('time_range'), 'change', submitIfQuery);
|
||||||
|
searxng.on(document.getElementById('language'), 'change', submitIfQuery);
|
||||||
|
}
|
|
@ -154,22 +154,20 @@ searxng.ready(function () {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (searxng.hotkeys) {
|
searxng.on(document, "keydown", function (e) {
|
||||||
searxng.on(document, "keydown", function (e) {
|
// check for modifiers so we don't break browser's hotkeys
|
||||||
// check for modifiers so we don't break browser's hotkeys
|
if (Object.prototype.hasOwnProperty.call(vimKeys, e.keyCode) && !e.ctrlKey && !e.altKey && !e.shiftKey && !e.metaKey) {
|
||||||
if (Object.prototype.hasOwnProperty.call(vimKeys, e.keyCode) && !e.ctrlKey && !e.altKey && !e.shiftKey && !e.metaKey) {
|
var tagName = e.target.tagName.toLowerCase();
|
||||||
var tagName = e.target.tagName.toLowerCase();
|
if (e.keyCode === 27) {
|
||||||
if (e.keyCode === 27) {
|
vimKeys[e.keyCode].fun(e);
|
||||||
vimKeys[e.keyCode].fun(e);
|
} else {
|
||||||
} else {
|
if (e.target === document.body || tagName === 'a' || tagName === 'button') {
|
||||||
if (e.target === document.body || tagName === 'a' || tagName === 'button') {
|
e.preventDefault();
|
||||||
e.preventDefault();
|
vimKeys[e.keyCode].fun();
|
||||||
vimKeys[e.keyCode].fun();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
function highlightResult (which) {
|
function highlightResult (which) {
|
||||||
return function (noScroll) {
|
return function (noScroll) {
|
|
@ -24,9 +24,6 @@
|
||||||
<script src="{{ url_for('static', filename='js/searxng.head.min.js') }}"
|
<script src="{{ url_for('static', filename='js/searxng.head.min.js') }}"
|
||||||
data-method="{{ method or 'POST' }}"
|
data-method="{{ method or 'POST' }}"
|
||||||
data-autocompleter="{% if autocomplete %}true{% else %}false{% endif %}"
|
data-autocompleter="{% if autocomplete %}true{% else %}false{% endif %}"
|
||||||
data-search-on-category-select="{{ 'true' if 'plugins/js/search_on_category_select.js' in scripts else 'false'}}"
|
|
||||||
data-infinite-scroll="{{ 'true' if 'plugins/js/infinite_scroll.js' in scripts else 'false' }}"
|
|
||||||
data-hotkeys="{{ 'true' if 'plugins/js/vim_hotkeys.js' in scripts else 'false' }}"
|
|
||||||
data-static-path="{{ url_for('static', filename='themes/simple') }}/"
|
data-static-path="{{ url_for('static', filename='themes/simple') }}/"
|
||||||
data-translations="{{ translations }}"></script>
|
data-translations="{{ translations }}"></script>
|
||||||
{% block head %}
|
{% block head %}
|
||||||
|
|
Loading…
Add table
Reference in a new issue