From 74b08303622c5545f04a3faf52f6c6962a43ea5f Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Fri, 1 Oct 2021 16:33:31 +0200 Subject: [PATCH] SearXNG: simple theme --- .../themes/__common__/js/image_layout.js | 2 +- searx/static/themes/oscar/src/js/01_init.js | 2 - .../themes/oscar/src/js/element_modifiers.js | 2 +- searx/static/themes/simple/.jshintignore | 1 - searx/static/themes/simple/gruntfile.js | 16 +++---- .../themes/simple/src/js/head/00_init.js | 25 +++------- .../simple/src/js/main/00_searx_toolkit.js | 47 +++++++------------ .../simple/src/js/main/searx_keyboard.js | 11 +++-- .../simple/src/js/main/searx_mapresult.js | 32 ++++--------- .../simple/src/js/main/searx_preferences.js | 13 ++--- .../simple/src/js/main/searx_results.js | 31 ++++-------- .../themes/simple/src/js/main/searx_search.js | 39 +++++---------- .../themes/simple/src/less/definitions.less | 2 +- .../static/themes/simple/src/less/mixins.less | 2 +- .../static/themes/simple/src/less/search.less | 2 +- .../static/themes/simple/src/less/style.less | 2 +- searx/templates/simple/base.html | 14 +++--- .../templates/simple/messages/no_results.html | 2 +- searx/templates/simple/preferences.html | 12 ++--- .../simple/result_templates/map.html | 2 +- searx/templates/simple/stats.html | 2 +- 21 files changed, 96 insertions(+), 165 deletions(-) delete mode 100644 searx/static/themes/simple/.jshintignore diff --git a/searx/static/themes/__common__/js/image_layout.js b/searx/static/themes/__common__/js/image_layout.js index ea54cf51..fa96f62c 100644 --- a/searx/static/themes/__common__/js/image_layout.js +++ b/searx/static/themes/__common__/js/image_layout.js @@ -158,6 +158,6 @@ } }; - w.searx.ImageLayout = ImageLayout; + w.searxng.ImageLayout = ImageLayout; }(window, document)); diff --git a/searx/static/themes/oscar/src/js/01_init.js b/searx/static/themes/oscar/src/js/01_init.js index 3066caad..8853d990 100644 --- a/searx/static/themes/oscar/src/js/01_init.js +++ b/searx/static/themes/oscar/src/js/01_init.js @@ -23,5 +23,3 @@ window.searxng = (function(d) { translations: JSON.parse(script.getAttribute('data-translations')) }; })(document); - -window.searx = {}; diff --git a/searx/static/themes/oscar/src/js/element_modifiers.js b/searx/static/themes/oscar/src/js/element_modifiers.js index 58e87f0f..e9de297e 100644 --- a/searx/static/themes/oscar/src/js/element_modifiers.js +++ b/searx/static/themes/oscar/src/js/element_modifiers.js @@ -103,6 +103,6 @@ $(document).ready(function(){ /** * Layout images according to their sizes */ - searxng.image_thumbnail_layout = new searx.ImageLayout('#main_results', '#main_results .result-images', 'img.img-thumbnail', 15, 200); + searxng.image_thumbnail_layout = new searxng.ImageLayout('#main_results', '#main_results .result-images', 'img.img-thumbnail', 15, 200); searxng.image_thumbnail_layout.watch(); }); diff --git a/searx/static/themes/simple/.jshintignore b/searx/static/themes/simple/.jshintignore deleted file mode 100644 index 3b2b7148..00000000 --- a/searx/static/themes/simple/.jshintignore +++ /dev/null @@ -1 +0,0 @@ -js/searx_src/autocomplete.js diff --git a/searx/static/themes/simple/gruntfile.js b/searx/static/themes/simple/gruntfile.js index 47e5a962..325a973b 100644 --- a/searx/static/themes/simple/gruntfile.js +++ b/searx/static/themes/simple/gruntfile.js @@ -72,8 +72,8 @@ module.exports = function(grunt) { separator: ';' }, files: { - 'js/searx.head.js': ['src/js/head/*.js'], - 'js/searx.js': ['src/js/main/*.js', '../__common__/js/*.js', './node_modules/autocomplete-js/dist/autocomplete.js'] + 'js/searxng.head.js': ['src/js/head/*.js'], + 'js/searxng.js': ['src/js/main/*.js', '../__common__/js/*.js', './node_modules/autocomplete-js/dist/autocomplete.js'] } } }, @@ -90,8 +90,8 @@ module.exports = function(grunt) { }, dist: { files: { - 'js/searx.head.min.js': ['js/searx.head.js'], - 'js/searx.min.js': ['js/searx.js'] + 'js/searxng.head.min.js': ['js/searxng.head.js'], + 'js/searxng.min.js': ['js/searxng.js'] } } }, @@ -165,8 +165,8 @@ module.exports = function(grunt) { paths: ["less"], }, files: { - "css/searx.css": "src/less/style.less", - "css/searx-rtl.css": "src/less/style-rtl.less" + "css/searxng.css": "src/less/style.less", + "css/searxng-rtl.css": "src/less/style-rtl.less" } }, production: { @@ -181,8 +181,8 @@ module.exports = function(grunt) { sourceMapRootpath: '../', }, files: { - "css/searx.min.css": "src/less/style.less", - "css/searx-rtl.min.css": "src/less/style-rtl.less" + "css/searxng.min.css": "src/less/style.less", + "css/searxng-rtl.min.css": "src/less/style-rtl.less" } }, }, 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 0a4fafbc..4406b764 100644 --- a/searx/static/themes/simple/src/js/head/00_init.js +++ b/searx/static/themes/simple/src/js/head/00_init.js @@ -1,20 +1,9 @@ /** -* searx is free software: you can redistribute it and/or modify -* it under the terms of the GNU Affero General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* searx is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU Affero General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with searx. If not, see < http://www.gnu.org/licenses/ >. -* -* (C) 2019 by Alexandre Flament -* -*/ + * @license + * (C) Copyright Contributors to the SearXNG project. + * (C) Copyright Contributors to the searx project (2014 - 2021). + * SPDX-License-Identifier: AGPL-3.0-or-later + */ /* global DocumentTouch:readonly */ (function(w, d) { 'use strict'; @@ -26,7 +15,7 @@ })(); // try to detect touch screen - w.searx = { + w.searxng = { touch: (("ontouchstart" in w) || w.DocumentTouch && document instanceof DocumentTouch) || false, method: script.getAttribute('data-method'), autocompleter: script.getAttribute('data-autocompleter') === 'true', @@ -37,5 +26,5 @@ }; // update the css - d.getElementsByTagName("html")[0].className = (w.searx.touch)?"js touch":"js"; + d.getElementsByTagName("html")[0].className = (w.searxng.touch)?"js touch":"js"; })(window, document); \ No newline at end of file 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 335caa3a..7dc50108 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 @@ -1,21 +1,10 @@ /** -* searx is free software: you can redistribute it and/or modify -* it under the terms of the GNU Affero General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* searx is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU Affero General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with searx. If not, see < http://www.gnu.org/licenses/ >. -* -* (C) 2017 by Alexandre Flament, -* -*/ -window.searx = (function(w, d) { + * @license + * (C) Copyright Contributors to the SearXNG project. + * (C) Copyright Contributors to the searx project (2014 - 2021). + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +window.searxng = (function(w, d) { 'use strict'; @@ -45,9 +34,9 @@ window.searx = (function(w, d) { } } - var searx = window.searx || {}; + var searxng = window.searxng || {}; - searx.on = function(obj, eventType, callback, useCapture) { + searxng.on = function(obj, eventType, callback, useCapture) { useCapture = useCapture || false; if (typeof obj !== 'string') { // obj HTMLElement, HTMLDocument @@ -62,7 +51,7 @@ window.searx = (function(w, d) { } }; - searx.ready = function(callback) { + searxng.ready = function(callback) { if (document.readyState != 'loading') { callback.call(w); } else { @@ -70,7 +59,7 @@ window.searx = (function(w, d) { } }; - searx.http = function(method, url) { + searxng.http = function(method, url) { var req = new XMLHttpRequest(), resolve = function() {}, reject = function() {}, @@ -109,8 +98,8 @@ window.searx = (function(w, d) { return promise; }; - searx.loadStyle = function(src) { - var path = searx.static_path + src, + searxng.loadStyle = function(src) { + var path = searxng.static_path + src, id = "style_" + src.replace('.', '_'), s = d.getElementById(id); if (s === null) { @@ -123,8 +112,8 @@ window.searx = (function(w, d) { } }; - searx.loadScript = function(src, callback) { - var path = searx.static_path + src, + searxng.loadScript = function(src, callback) { + var path = searxng.static_path + src, id = "script_" + src.replace('.', '_'), s = d.getElementById(id); if (s === null) { @@ -147,17 +136,17 @@ window.searx = (function(w, d) { } }; - searx.insertBefore = function (newNode, referenceNode) { + searxng.insertBefore = function (newNode, referenceNode) { referenceNode.parentNode.insertBefore(newNode, referenceNode); }; - searx.insertAfter = function(newNode, referenceNode) { + searxng.insertAfter = function(newNode, referenceNode) { referenceNode.parentNode.insertAfter(newNode, referenceNode.nextSibling); }; - searx.on('.close', 'click', function() { + searxng.on('.close', 'click', function() { this.parentNode.classList.add('invisible'); }); - return searx; + return searxng; })(window, document); 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 8f410524..c00a1a45 100644 --- a/searx/static/themes/simple/src/js/main/searx_keyboard.js +++ b/searx/static/themes/simple/src/js/main/searx_keyboard.js @@ -1,12 +1,13 @@ -/*global searx*/ +/* SPDX-License-Identifier: AGPL-3.0-or-later */ +/*global searxng*/ -searx.ready(function() { +searxng.ready(function() { - searx.on('.result', 'click', function() { + searxng.on('.result', 'click', function() { highlightResult(this)(true); }); - searx.on('.result a', 'focus', function(e) { + searxng.on('.result a', 'focus', function(e) { var el = e.target; while (el !== undefined) { if (el.classList.contains('result')) { @@ -118,7 +119,7 @@ searx.ready(function() { } }; - searx.on(document, "keydown", function(e) { + searxng.on(document, "keydown", function(e) { // 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) { var tagName = e.target.tagName.toLowerCase(); 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 20da7761..75d13b51 100644 --- a/searx/static/themes/simple/src/js/main/searx_mapresult.js +++ b/searx/static/themes/simple/src/js/main/searx_mapresult.js @@ -1,28 +1,12 @@ -/** -* searx is free software: you can redistribute it and/or modify -* it under the terms of the GNU Affero General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* searx is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU Affero General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with searx. If not, see < http://www.gnu.org/licenses/ >. -* -* (C) 2014 by Thomas Pointhuber, -* (C) 2017 by Alexandre Flament, -*/ +/* SPDX-License-Identifier: AGPL-3.0-or-later */ /* global L */ -(function (w, d, searx) { +(function (w, d, searxng) { 'use strict'; - searx.ready(function () { - searx.on('.searx_init_map', 'click', function(event) { + searxng.ready(function () { + searxng.on('.searxng_init_map', 'click', function(event) { // no more request - this.classList.remove("searx_init_map"); + this.classList.remove("searxng_init_map"); // var leaflet_target = this.dataset.leafletTarget; @@ -32,8 +16,8 @@ var map_boundingbox = JSON.parse(this.dataset.mapBoundingbox); var map_geojson = JSON.parse(this.dataset.mapGeojson); - searx.loadStyle('css/leaflet.css'); - searx.loadScript('js/leaflet.js', function() { + searxng.loadStyle('css/leaflet.css'); + searxng.loadScript('js/leaflet.js', function() { var map_bounds = null; if(map_boundingbox) { var southWest = L.latLng(map_boundingbox[0], map_boundingbox[2]); @@ -87,4 +71,4 @@ event.preventDefault(); }); }); -})(window, document, window.searx); +})(window, document, window.searxng); diff --git a/searx/static/themes/simple/src/js/main/searx_preferences.js b/searx/static/themes/simple/src/js/main/searx_preferences.js index 136d9f03..b19026a4 100644 --- a/searx/static/themes/simple/src/js/main/searx_preferences.js +++ b/searx/static/themes/simple/src/js/main/searx_preferences.js @@ -1,16 +1,17 @@ -(function (w, d, searx) { +/* SPDX-License-Identifier: AGPL-3.0-or-later */ +(function (w, d, searxng) { 'use strict'; - searx.ready(function() { + searxng.ready(function() { let engine_descriptions = null; function load_engine_descriptions() { if (engine_descriptions == null) { - searx.http("GET", "engine_descriptions.json").then(function(content) { + searxng.http("GET", "engine_descriptions.json").then(function(content) { engine_descriptions = JSON.parse(content); for (const [engine_name, description] of Object.entries(engine_descriptions)) { let elements = d.querySelectorAll('[data-engine-name="' + engine_name + '"] .engine-description'); for(const element of elements) { - let source = ' (' + searx.translations['Source'] + ': ' + description[1] + ')'; + let source = ' (' + searxng.translations['Source'] + ': ' + description[1] + ')'; element.innerHTML = description[0] + source; } } @@ -20,8 +21,8 @@ if (d.querySelector('body[class="preferences_endpoint"]')) { for(const el of d.querySelectorAll('[data-engine-name]')) { - searx.on(el, 'mouseenter', load_engine_descriptions); + searxng.on(el, 'mouseenter', load_engine_descriptions); } } }); -})(window, document, window.searx); +})(window, document, window.searxng); 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 115c27b1..79af25af 100644 --- a/searx/static/themes/simple/src/js/main/searx_results.js +++ b/searx/static/themes/simple/src/js/main/searx_results.js @@ -1,27 +1,12 @@ -/** -* searx is free software: you can redistribute it and/or modify -* it under the terms of the GNU Affero General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* searx is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU Affero General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with searx. If not, see < http://www.gnu.org/licenses/ >. -* -* (C) 2017 by Alexandre Flament, -*/ -(function(w, d, searx) { +/* SPDX-License-Identifier: AGPL-3.0-or-later */ +(function(w, d, searxng) { 'use strict'; - searx.ready(function() { - searx.image_thumbnail_layout = new searx.ImageLayout('#urls', '#urls .result-images', 'img.image_thumbnail', 10, 200); - searx.image_thumbnail_layout.watch(); + searxng.ready(function() { + searxng.image_thumbnail_layout = new searxng.ImageLayout('#urls', '#urls .result-images', 'img.image_thumbnail', 10, 200); + searxng.image_thumbnail_layout.watch(); - searx.on('.btn-collapse', 'click', function() { + searxng.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 +22,7 @@ targetElement.classList.toggle('invisible'); }); - searx.on('.media-loader', 'click', function() { + searxng.on('.media-loader', 'click', function() { var target = this.getAttribute('data-target'); var iframe_load = d.querySelector(target + ' > iframe'); var srctest = iframe_load.getAttribute('src'); @@ -60,4 +45,4 @@ }); -})(window, document, window.searx); +})(window, document, window.searxng); 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 c593ba6a..d3149340 100644 --- a/searx/static/themes/simple/src/js/main/searx_search.js +++ b/searx/static/themes/simple/src/js/main/searx_search.js @@ -1,21 +1,6 @@ -/** -* searx is free software: you can redistribute it and/or modify -* it under the terms of the GNU Affero General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* searx is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU Affero General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with searx. If not, see < http://www.gnu.org/licenses/ >. -* -* (C) 2017 by Alexandre Flament, -*/ +/* SPDX-License-Identifier: AGPL-3.0-or-later */ /* global AutoComplete */ -(function(w, d, searx) { +(function(w, d, searxng) { 'use strict'; var firstFocus = true, qinput_id = "q", qinput; @@ -54,7 +39,7 @@ qinput.addEventListener('keyup', updateClearButton, false); } - searx.ready(function() { + searxng.ready(function() { qinput = d.getElementById(qinput_id); function placeCursorAtEndOnce() { @@ -71,11 +56,11 @@ createClearButton(qinput); // autocompleter - if (searx.autocompleter) { - searx.autocomplete = AutoComplete.call(w, { + if (searxng.autocompleter) { + searxng.autocomplete = AutoComplete.call(w, { Url: "./autocompleter", - EmptyMessage: searx.translations.no_item_found, - HttpMethod: searx.method, + EmptyMessage: searxng.translations.no_item_found, + HttpMethod: searxng.method, HttpHeaders: { "Content-type": "application/x-www-form-urlencoded", "X-Requested-With": "XMLHttpRequest" @@ -96,10 +81,10 @@ } // vanilla js version of search_on_category_select.js - if (qinput !== null && d.querySelector('.help') != null && searx.search_on_category_select) { + if (qinput !== null && d.querySelector('.help') != null && searxng.search_on_category_select) { d.querySelector('.help').className='invisible'; - searx.on('#categories input', 'change', function() { + searxng.on('#categories input', 'change', function() { var i, categories = d.querySelectorAll('#categories input[type="checkbox"]'); for(i=0; i - - - + + + @@ -13,13 +13,13 @@ {% block title %}{% endblock %}{{ instance_name }} {% block meta %}{% endblock %} {% if rtl %} - + {% else %} - + {% endif %} {% block styles %}{% endblock %} - + diff --git a/searx/templates/simple/messages/no_results.html b/searx/templates/simple/messages/no_results.html index 845f3e21..a3ab9775 100644 --- a/searx/templates/simple/messages/no_results.html +++ b/searx/templates/simple/messages/no_results.html @@ -11,7 +11,7 @@

{%- endfor %} -

{{ _('Please, try again later or find another searx instance.') }} ({{ _('Public instances') }})

+

{{ _('Please, try again later or find another SearXNG instance.') }} ({{ _('Public instances') }})

{% else %}