From f77f797f8c7016a5748acfcf934a2c54d15af765 Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Tue, 24 Aug 2021 11:31:29 +0200 Subject: [PATCH] [mod] simple theme: fix eslint errors, fix VIM keys * VIM keys: fix the next page and previous pages (n, p keys) * Map: Enable the wikipedia map (the layer was initialized but not included) --- .../themes/simple/src/js/head/00_init.js | 1 + .../simple/src/js/main/00_searx_toolkit.js | 9 +-- .../simple/src/js/main/searx_keyboard.js | 76 ++++++++++--------- .../simple/src/js/main/searx_mapresult.js | 7 +- .../simple/src/js/main/searx_results.js | 4 +- .../themes/simple/src/js/main/searx_search.js | 5 +- searx/templates/simple/results.html | 4 +- 7 files changed, 56 insertions(+), 50 deletions(-) diff --git a/searx/static/themes/simple/src/js/head/00_init.js b/searx/static/themes/simple/src/js/head/00_init.js index be7560451..0a4fafbce 100644 --- a/searx/static/themes/simple/src/js/head/00_init.js +++ b/searx/static/themes/simple/src/js/head/00_init.js @@ -15,6 +15,7 @@ * (C) 2019 by Alexandre Flament * */ +/* global DocumentTouch:readonly */ (function(w, d) { 'use strict'; diff --git a/searx/static/themes/simple/src/js/main/00_searx_toolkit.js b/searx/static/themes/simple/src/js/main/00_searx_toolkit.js index dbef4be73..335caa3ad 100644 --- a/searx/static/themes/simple/src/js/main/00_searx_toolkit.js +++ b/searx/static/themes/simple/src/js/main/00_searx_toolkit.js @@ -70,7 +70,7 @@ window.searx = (function(w, d) { } }; - searx.http = function(method, url, callback) { + searx.http = function(method, url) { var req = new XMLHttpRequest(), resolve = function() {}, reject = function() {}, @@ -148,15 +148,14 @@ window.searx = (function(w, d) { }; searx.insertBefore = function (newNode, referenceNode) { - element.parentNode.insertBefore(newNode, referenceNode); + referenceNode.parentNode.insertBefore(newNode, referenceNode); }; searx.insertAfter = function(newNode, referenceNode) { - referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling); + referenceNode.parentNode.insertAfter(newNode, referenceNode.nextSibling); }; - searx.on('.close', 'click', function(e) { - var el = e.target || e.srcElement; + searx.on('.close', 'click', function() { this.parentNode.classList.add('invisible'); }); 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 = '×'; - html += '

How to navigate searx with Vim-like hotkeys

'; - html += ''; + var html = '×'; + html += '

How to navigate searx with Vim-like hotkeys

'; + html += '
'; for (var i = 0; i < sorted.length; i++) { var cat = categories[sorted[i]]; @@ -338,29 +342,29 @@ searx.ready(function() { } } - html += '
'; + html += ''; - 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; + } } - }); diff --git a/searx/static/themes/simple/src/js/main/searx_mapresult.js b/searx/static/themes/simple/src/js/main/searx_mapresult.js index 7b3982c11..20da7761a 100644 --- a/searx/static/themes/simple/src/js/main/searx_mapresult.js +++ b/searx/static/themes/simple/src/js/main/searx_mapresult.js @@ -15,6 +15,7 @@ * (C) 2014 by Thomas Pointhuber, * (C) 2017 by Alexandre Flament, */ +/* global L */ (function (w, d, searx) { 'use strict'; @@ -47,7 +48,7 @@ var osmMapnikAttrib='Map data © OpenStreetMap contributors'; var osmMapnik = new L.TileLayer(osmMapnikUrl, {minZoom: 1, maxZoom: 19, attribution: osmMapnikAttrib}); var osmWikimediaUrl='https://maps.wikimedia.org/osm-intl/{z}/{x}/{y}.png'; - var osmWikimediaAttrib = 'Wikimedia maps beta | Maps data © OpenStreetMap contributors'; + var osmWikimediaAttrib = 'Wikimedia maps | Maps data © OpenStreetMap contributors'; var osmWikimedia = new L.TileLayer(osmWikimediaUrl, {minZoom: 1, maxZoom: 19, attribution: osmWikimediaAttrib}); // init map view if(map_bounds) { @@ -69,8 +70,8 @@ map.addLayer(osmMapnik); var baseLayers = { - "OSM Mapnik": osmMapnik/*, - "OSM Wikimedia": osmWikimedia*/ + "OSM Mapnik": osmMapnik, + "OSM Wikimedia": osmWikimedia, }; L.control.layers(baseLayers).addTo(map); diff --git a/searx/static/themes/simple/src/js/main/searx_results.js b/searx/static/themes/simple/src/js/main/searx_results.js index fe00efc90..115c27b1d 100644 --- a/searx/static/themes/simple/src/js/main/searx_results.js +++ b/searx/static/themes/simple/src/js/main/searx_results.js @@ -21,7 +21,7 @@ searx.image_thumbnail_layout = new searx.ImageLayout('#urls', '#urls .result-images', 'img.image_thumbnail', 10, 200); searx.image_thumbnail_layout.watch(); - searx.on('.btn-collapse', 'click', function(event) { + searx.on('.btn-collapse', 'click', function() { var btnLabelCollapsed = this.getAttribute('data-btn-text-collapsed'); var btnLabelNotCollapsed = this.getAttribute('data-btn-text-not-collapsed'); var target = this.getAttribute('data-target'); @@ -37,7 +37,7 @@ targetElement.classList.toggle('invisible'); }); - searx.on('.media-loader', 'click', function(event) { + searx.on('.media-loader', 'click', function() { var target = this.getAttribute('data-target'); var iframe_load = d.querySelector(target + ' > iframe'); var srctest = iframe_load.getAttribute('src'); diff --git a/searx/static/themes/simple/src/js/main/searx_search.js b/searx/static/themes/simple/src/js/main/searx_search.js index 0e498717c..235262b37 100644 --- a/searx/static/themes/simple/src/js/main/searx_search.js +++ b/searx/static/themes/simple/src/js/main/searx_search.js @@ -14,6 +14,7 @@ * * (C) 2017 by Alexandre Flament, */ +/* global AutoComplete */ (function(w, d, searx) { 'use strict'; @@ -56,7 +57,7 @@ searx.ready(function() { qinput = d.getElementById(qinput_id); - function placeCursorAtEndOnce(e) { + function placeCursorAtEndOnce() { if (firstFocus) { placeCursorAtEnd(qinput); firstFocus = false; @@ -98,7 +99,7 @@ if (qinput !== null && searx.search_on_category_select) { d.querySelector('.help').className='invisible'; - searx.on('#categories input', 'change', function(e) { + searx.on('#categories input', 'change', function() { var i, categories = d.querySelectorAll('#categories input[type="checkbox"]'); for(i=0; i {% if pageno > 1 %} -
+
{{- engine_data_form(engine_data) -}} @@ -163,7 +163,7 @@
{% endif %} -
+
{{- engine_data_form(engine_data) -}}