From e46a2a3e13b8e66180441e9e7f2fe95ed93cad7e Mon Sep 17 00:00:00 2001 From: bonswouar Date: Thu, 7 Sep 2023 16:13:44 +0200 Subject: [PATCH] [feat] simple theme: image preview use arrow keys --- .../static/themes/simple/src/js/main/keyboard.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/searx/static/themes/simple/src/js/main/keyboard.js b/searx/static/themes/simple/src/js/main/keyboard.js index 0c52673d9..09bb16214 100644 --- a/searx/static/themes/simple/src/js/main/keyboard.js +++ b/searx/static/themes/simple/src/js/main/keyboard.js @@ -32,6 +32,10 @@ searxng.ready(function () { return resultElement && resultElement.classList.contains('result-images'); } + function hasImageInDetail () { + return document.querySelector('#results.image-detail-open') !== null; + } + searxng.on('.result', 'click', function (e) { if (!isElementInDetail(e.target)) { highlightResult(this)(true, true); @@ -171,6 +175,18 @@ searxng.ready(function () { }); } + searxng.on(document, 'keydown', function (e) { + if (hasImageInDetail()) { + if (e.key === 'ArrowLeft') { + e.preventDefault(); + searxng.selectPrevious(false); + } else if (e.key === 'ArrowRight') { + e.preventDefault(); + searxng.selectNext(false); + } + } + }); + function highlightResult (which) { return function (noScroll, keepFocus) { var current = document.querySelector('.result[data-vim-selected]'),