diff options
| author | Markus Heiser <markus.heiser@darmarIT.de> | 2021-08-31 16:13:47 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-31 16:13:47 +0000 |
| commit | 37b3d8c33b243f342d80aac45cc023d66408a749 (patch) | |
| tree | 8a88c4febecbe2853c01613d19d9b5a678c21c37 /searx/static/themes/simple/src/js/main/searx_keyboard.js | |
| parent | 840a32756489fe6fa5b27f2d08034033a0cc79de (diff) | |
| parent | d246679dbe5eccc5e7d5be50b8c78c76e1f0bebb (diff) | |
Merge pull request #276 from dalf/simple_eslint
Simple theme: eslint and bug fix
Diffstat (limited to 'searx/static/themes/simple/src/js/main/searx_keyboard.js')
| -rw-r--r-- | searx/static/themes/simple/src/js/main/searx_keyboard.js | 76 |
1 files changed, 40 insertions, 36 deletions
diff --git a/searx/static/themes/simple/src/js/main/searx_keyboard.js b/searx/static/themes/simple/src/js/main/searx_keyboard.js index 657d9ec93..8f410524f 100644 --- a/searx/static/themes/simple/src/js/main/searx_keyboard.js +++ b/searx/static/themes/simple/src/js/main/searx_keyboard.js @@ -1,3 +1,5 @@ +/*global searx*/ + searx.ready(function() { searx.on('.result', 'click', function() { @@ -80,13 +82,13 @@ searx.ready(function() { }, 80: { key: 'p', - fun: pageButtonClick(0), + fun: GoToPreviousPage(), des: 'go to previous page', cat: 'Results' }, 78: { key: 'n', - fun: pageButtonClick(1), + fun: GoToNextPage(), des: 'go to next page', cat: 'Results' }, @@ -118,7 +120,7 @@ searx.ready(function() { searx.on(document, "keydown", function(e) { // check for modifiers so we don't break browser's hotkeys - if (vimKeys.hasOwnProperty(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(); if (e.keyCode === 27) { if (tagName === 'input' || tagName === 'select' || tagName === 'textarea') { @@ -216,21 +218,23 @@ searx.ready(function() { } } - function pageButtonClick(num) { + function pageButtonClick(css_selector) { return function() { - var buttons = $('div#pagination button[type="submit"]'); - if (buttons.length !== 2) { - console.log('page navigation with this theme is not supported'); - return; - } - if (num >= 0 && num < buttons.length) { - buttons[num].click(); - } else { - console.log('pageButtonClick(): invalid argument'); + var button = document.querySelector(css_selector); + if (button) { + button.click(); } }; } + function GoToNextPage() { + return pageButtonClick('nav#pagination .next_page button[type="submit"]'); + } + + function GoToPreviousPage() { + return pageButtonClick('nav#pagination .previous_page button[type="submit"]'); + } + function scrollPageToSelected() { var sel = document.querySelector('.result[data-vim-selected]'); if (sel === null) { @@ -308,9 +312,9 @@ searx.ready(function() { return; } - var html = '<a href="#" class="close" aria-label="close" title="close">×</a>'; - html += '<h3>How to navigate searx with Vim-like hotkeys</h3>'; - html += '<table>'; + var html = '<a href="#" class="close" aria-label="close" title="close">×</a>'; + html += '<h3>How to navigate searx with Vim-like hotkeys</h3>'; + html += '<table>'; for (var i = 0; i < sorted.length; i++) { var cat = categories[sorted[i]]; @@ -338,29 +342,29 @@ searx.ready(function() { } } - html += '</table>'; + html += '</table>'; - divElement.innerHTML = html; - } + divElement.innerHTML = html; + } function toggleHelp() { - var helpPanel = document.querySelector('#vim-hotkeys-help'); - console.log(helpPanel); - if (helpPanel === undefined || helpPanel === null) { - // first call - helpPanel = document.createElement('div'); - helpPanel.id = 'vim-hotkeys-help'; - helpPanel.className='dialog-modal'; - helpPanel.style='width: 40%'; + var helpPanel = document.querySelector('#vim-hotkeys-help'); + console.log(helpPanel); + if (helpPanel === undefined || helpPanel === null) { + // first call + helpPanel = document.createElement('div'); + helpPanel.id = 'vim-hotkeys-help'; + helpPanel.className='dialog-modal'; + helpPanel.style='width: 40%'; + initHelpContent(helpPanel); initHelpContent(helpPanel); - var body = document.getElementsByTagName('body')[0]; - body.appendChild(helpPanel); - } else { - // togggle hidden - helpPanel.classList.toggle('invisible'); - return; - } - + initHelpContent(helpPanel); + var body = document.getElementsByTagName('body')[0]; + body.appendChild(helpPanel); + } else { + // togggle hidden + helpPanel.classList.toggle('invisible'); + return; + } } - }); |