1
0
mirror of https://github.com/searxng/searxng.git synced 2024-10-06 03:20:10 +02:00

[fix] simple theme: disable hotkeys when they are not enabled in the preferences

This commit is contained in:
Alexandre Flament 2021-11-05 10:26:01 +01:00
parent ba342db55e
commit d1c09c84e2
3 changed files with 17 additions and 14 deletions

View File

@ -21,6 +21,7 @@
autocompleter: script.getAttribute('data-autocompleter') === 'true', autocompleter: script.getAttribute('data-autocompleter') === 'true',
search_on_category_select: script.getAttribute('data-search-on-category-select') === 'true', search_on_category_select: script.getAttribute('data-search-on-category-select') === 'true',
infinite_scroll: script.getAttribute('data-infinite-scroll') === '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')),
}; };

View File

@ -119,20 +119,22 @@ searxng.ready(function() {
} }
}; };
searxng.on(document, "keydown", function(e) { if (searxng.hotkeys) {
// check for modifiers so we don't break browser's hotkeys searxng.on(document, "keydown", function(e) {
if (Object.prototype.hasOwnProperty.call(vimKeys, e.keyCode) && !e.ctrlKey && !e.altKey && !e.shiftKey && !e.metaKey) { // check for modifiers so we don't break browser's hotkeys
var tagName = e.target.tagName.toLowerCase(); if (Object.prototype.hasOwnProperty.call(vimKeys, e.keyCode) && !e.ctrlKey && !e.altKey && !e.shiftKey && !e.metaKey) {
if (e.keyCode === 27) { var tagName = e.target.tagName.toLowerCase();
vimKeys[e.keyCode].fun(e); if (e.keyCode === 27) {
} else { vimKeys[e.keyCode].fun(e);
if (e.target === document.body || tagName === 'a' || tagName === 'button') { } else {
e.preventDefault(); if (e.target === document.body || tagName === 'a' || tagName === 'button') {
vimKeys[e.keyCode].fun(); e.preventDefault();
vimKeys[e.keyCode].fun();
}
} }
} }
} });
}); }
function highlightResult(which) { function highlightResult(which) {
return function(noScroll) { return function(noScroll) {
@ -353,8 +355,7 @@ searxng.ready(function() {
} }
function toggleHelp() { function toggleHelp() {
var helpPanel = document.querySelector('#vim-hotkeys-help'); var helpPanel = document.querySelector('#vim-hotkeys-help');
console.log(helpPanel);
if (helpPanel === undefined || helpPanel === null) { if (helpPanel === undefined || helpPanel === null) {
// first call // first call
helpPanel = document.createElement('div'); helpPanel = document.createElement('div');

View File

@ -24,6 +24,7 @@
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-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-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>
<!--<![endif]--> <!--<![endif]-->