From a53a4d5012a3aa5bcabbe0d7db8805fdf342d896 Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Fri, 1 Oct 2021 18:07:27 +0200 Subject: [build] /static --- searx/static/themes/simple/js/searx.head.js | 41 - searx/static/themes/simple/js/searx.head.min.js | 2 - .../static/themes/simple/js/searx.head.min.js.map | 1 - searx/static/themes/simple/js/searx.js | 1538 -------------------- searx/static/themes/simple/js/searx.min.js | 24 - searx/static/themes/simple/js/searx.min.js.map | 1 - searx/static/themes/simple/js/searxng.head.js | 30 + searx/static/themes/simple/js/searxng.head.min.js | 8 + .../themes/simple/js/searxng.head.min.js.map | 1 + searx/static/themes/simple/js/searxng.js | 1483 +++++++++++++++++++ searx/static/themes/simple/js/searxng.min.js | 30 + searx/static/themes/simple/js/searxng.min.js.map | 1 + 12 files changed, 1553 insertions(+), 1607 deletions(-) delete mode 100644 searx/static/themes/simple/js/searx.head.js delete mode 100644 searx/static/themes/simple/js/searx.head.min.js delete mode 100644 searx/static/themes/simple/js/searx.head.min.js.map delete mode 100644 searx/static/themes/simple/js/searx.js delete mode 100644 searx/static/themes/simple/js/searx.min.js delete mode 100644 searx/static/themes/simple/js/searx.min.js.map create mode 100644 searx/static/themes/simple/js/searxng.head.js create mode 100644 searx/static/themes/simple/js/searxng.head.min.js create mode 100644 searx/static/themes/simple/js/searxng.head.min.js.map create mode 100644 searx/static/themes/simple/js/searxng.js create mode 100644 searx/static/themes/simple/js/searxng.min.js create mode 100644 searx/static/themes/simple/js/searxng.min.js.map (limited to 'searx/static/themes/simple/js') diff --git a/searx/static/themes/simple/js/searx.head.js b/searx/static/themes/simple/js/searx.head.js deleted file mode 100644 index 0a4fafbce..000000000 --- a/searx/static/themes/simple/js/searx.head.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* 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 -* -*/ -/* global DocumentTouch:readonly */ -(function(w, d) { - 'use strict'; - - // add data- properties - var script = d.currentScript || (function() { - var scripts = d.getElementsByTagName('script'); - return scripts[scripts.length - 1]; - })(); - - // try to detect touch screen - w.searx = { - touch: (("ontouchstart" in w) || w.DocumentTouch && document instanceof DocumentTouch) || false, - method: script.getAttribute('data-method'), - autocompleter: script.getAttribute('data-autocompleter') === 'true', - search_on_category_select: script.getAttribute('data-search-on-category-select') === 'true', - infinite_scroll: script.getAttribute('data-infinite-scroll') === 'true', - static_path: script.getAttribute('data-static-path'), - translations: JSON.parse(script.getAttribute('data-translations')), - }; - - // update the css - d.getElementsByTagName("html")[0].className = (w.searx.touch)?"js touch":"js"; -})(window, document); \ No newline at end of file diff --git a/searx/static/themes/simple/js/searx.head.min.js b/searx/static/themes/simple/js/searx.head.min.js deleted file mode 100644 index 692083d59..000000000 --- a/searx/static/themes/simple/js/searx.head.min.js +++ /dev/null @@ -1,2 +0,0 @@ -(function(t,e){"use strict";var a=e.currentScript||function(){var t=e.getElementsByTagName("script");return t[t.length-1]}();t.searx={touch:"ontouchstart"in t||t.DocumentTouch&&document instanceof DocumentTouch||false,method:a.getAttribute("data-method"),autocompleter:a.getAttribute("data-autocompleter")==="true",search_on_category_select:a.getAttribute("data-search-on-category-select")==="true",infinite_scroll:a.getAttribute("data-infinite-scroll")==="true",static_path:a.getAttribute("data-static-path"),translations:JSON.parse(a.getAttribute("data-translations"))};e.getElementsByTagName("html")[0].className=t.searx.touch?"js touch":"js"})(window,document); -//# sourceMappingURL=searx.head.min.js.map \ No newline at end of file diff --git a/searx/static/themes/simple/js/searx.head.min.js.map b/searx/static/themes/simple/js/searx.head.min.js.map deleted file mode 100644 index 69490193e..000000000 --- a/searx/static/themes/simple/js/searx.head.min.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"searx.head.min.js","sources":["searx.head.js"],"names":["w","d","script","currentScript","scripts","getElementsByTagName","length","searx","touch","DocumentTouch","document","method","getAttribute","autocompleter","search_on_category_select","infinite_scroll","static_path","translations","JSON","parse","className","window"],"mappings":"CAkBA,SAAUA,EAAGC,gBAIT,IAAIC,EAASD,EAAEE,eAAkB,WAC7B,IAAIC,EAAUH,EAAEI,qBAAqB,UACrC,OAAOD,EAAQA,EAAQE,OAAS,GAFH,GAMjCN,EAAEO,MAAQ,CACNC,MAAS,iBAAkBR,GAAMA,EAAES,eAAiBC,oBAAoBD,eAAkB,MAC1FE,OAAQT,EAAOU,aAAa,eAC5BC,cAAeX,EAAOU,aAAa,wBAA0B,OAC7DE,0BAA2BZ,EAAOU,aAAa,oCAAsC,OACrFG,gBAAiBb,EAAOU,aAAa,0BAA4B,OACjEI,YAAad,EAAOU,aAAa,oBACjCK,aAAcC,KAAKC,MAAMjB,EAAOU,aAAa,uBAIjDX,EAAEI,qBAAqB,QAAQ,GAAGe,UAAapB,EAAEO,MAAW,MAAE,WAAW,MArB7E,CAsBGc,OAAQX"} \ No newline at end of file diff --git a/searx/static/themes/simple/js/searx.js b/searx/static/themes/simple/js/searx.js deleted file mode 100644 index 94e4b3426..000000000 --- a/searx/static/themes/simple/js/searx.js +++ /dev/null @@ -1,1538 +0,0 @@ -/** -* 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) { - - 'use strict'; - - // not invented here tookit with bugs fixed elsewhere - // purposes : be just good enough and as small as possible - - // from https://plainjs.com/javascript/events/live-binding-event-handlers-14/ - if (w.Element) { - (function(ElementPrototype) { - ElementPrototype.matches = ElementPrototype.matches || - ElementPrototype.matchesSelector || - ElementPrototype.webkitMatchesSelector || - ElementPrototype.msMatchesSelector || - function(selector) { - var node = this, nodes = (node.parentNode || node.document).querySelectorAll(selector), i = -1; - while (nodes[++i] && nodes[i] != node); - return !!nodes[i]; - }; - })(Element.prototype); - } - - function callbackSafe(callback, el, e) { - try { - callback.call(el, e); - } catch (exception) { - console.log(exception); - } - } - - var searx = window.searx || {}; - - searx.on = function(obj, eventType, callback, useCapture) { - useCapture = useCapture || false; - if (typeof obj !== 'string') { - // obj HTMLElement, HTMLDocument - obj.addEventListener(eventType, callback, useCapture); - } else { - // obj is a selector - d.addEventListener(eventType, function(e) { - var el = e.target || e.srcElement, found = false; - while (el && el.matches && el !== d && !(found = el.matches(obj))) el = el.parentElement; - if (found) callbackSafe(callback, el, e); - }, useCapture); - } - }; - - searx.ready = function(callback) { - if (document.readyState != 'loading') { - callback.call(w); - } else { - w.addEventListener('DOMContentLoaded', callback.bind(w)); - } - }; - - searx.http = function(method, url) { - var req = new XMLHttpRequest(), - resolve = function() {}, - reject = function() {}, - promise = { - then: function(callback) { resolve = callback; return promise; }, - catch: function(callback) { reject = callback; return promise; } - }; - - try { - req.open(method, url, true); - - // On load - req.onload = function() { - if (req.status == 200) { - resolve(req.response, req.responseType); - } else { - reject(Error(req.statusText)); - } - }; - - // Handle network errors - req.onerror = function() { - reject(Error("Network Error")); - }; - - req.onabort = function() { - reject(Error("Transaction is aborted")); - }; - - // Make the request - req.send(); - } catch (ex) { - reject(ex); - } - - return promise; - }; - - searx.loadStyle = function(src) { - var path = searx.static_path + src, - id = "style_" + src.replace('.', '_'), - s = d.getElementById(id); - if (s === null) { - s = d.createElement('link'); - s.setAttribute('id', id); - s.setAttribute('rel', 'stylesheet'); - s.setAttribute('type', 'text/css'); - s.setAttribute('href', path); - d.body.appendChild(s); - } - }; - - searx.loadScript = function(src, callback) { - var path = searx.static_path + src, - id = "script_" + src.replace('.', '_'), - s = d.getElementById(id); - if (s === null) { - s = d.createElement('script'); - s.setAttribute('id', id); - s.setAttribute('src', path); - s.onload = callback; - s.onerror = function() { - s.setAttribute('error', '1'); - }; - d.body.appendChild(s); - } else if (!s.hasAttribute('error')) { - try { - callback.apply(s, []); - } catch (exception) { - console.log(exception); - } - } else { - console.log("callback not executed : script '" + path + "' not loaded."); - } - }; - - searx.insertBefore = function (newNode, referenceNode) { - referenceNode.parentNode.insertBefore(newNode, referenceNode); - }; - - searx.insertAfter = function(newNode, referenceNode) { - referenceNode.parentNode.insertAfter(newNode, referenceNode.nextSibling); - }; - - searx.on('.close', 'click', function() { - this.parentNode.classList.add('invisible'); - }); - - return searx; -})(window, document); -;/*global searx*/ - -searx.ready(function() { - - searx.on('.result', 'click', function() { - highlightResult(this)(true); - }); - - searx.on('.result a', 'focus', function(e) { - var el = e.target; - while (el !== undefined) { - if (el.classList.contains('result')) { - if (el.getAttribute("data-vim-selected") === null) { - highlightResult(el)(true); - } - break; - } - el = el.parentNode; - } - }, true); - - var vimKeys = { - 27: { - key: 'Escape', - fun: removeFocus, - des: 'remove focus from the focused input', - cat: 'Control' - }, - 73: { - key: 'i', - fun: searchInputFocus, - des: 'focus on the search input', - cat: 'Control' - }, - 66: { - key: 'b', - fun: scrollPage(-window.innerHeight), - des: 'scroll one page up', - cat: 'Navigation' - }, - 70: { - key: 'f', - fun: scrollPage(window.innerHeight), - des: 'scroll one page down', - cat: 'Navigation' - }, - 85: { - key: 'u', - fun: scrollPage(-window.innerHeight / 2), - des: 'scroll half a page up', - cat: 'Navigation' - }, - 68: { - key: 'd', - fun: scrollPage(window.innerHeight / 2), - des: 'scroll half a page down', - cat: 'Navigation' - }, - 71: { - key: 'g', - fun: scrollPageTo(-document.body.scrollHeight, 'top'), - des: 'scroll to the top of the page', - cat: 'Navigation' - }, - 86: { - key: 'v', - fun: scrollPageTo(document.body.scrollHeight, 'bottom'), - des: 'scroll to the bottom of the page', - cat: 'Navigation' - }, - 75: { - key: 'k', - fun: highlightResult('up'), - des: 'select previous search result', - cat: 'Results' - }, - 74: { - key: 'j', - fun: highlightResult('down'), - des: 'select next search result', - cat: 'Results' - }, - 80: { - key: 'p', - fun: GoToPreviousPage(), - des: 'go to previous page', - cat: 'Results' - }, - 78: { - key: 'n', - fun: GoToNextPage(), - des: 'go to next page', - cat: 'Results' - }, - 79: { - key: 'o', - fun: openResult(false), - des: 'open search result', - cat: 'Results' - }, - 84: { - key: 't', - fun: openResult(true), - des: 'open the result in a new tab', - cat: 'Results' - }, - 82: { - key: 'r', - fun: reloadPage, - des: 'reload page from the server', - cat: 'Control' - }, - 72: { - key: 'h', - fun: toggleHelp, - des: 'toggle help window', - cat: 'Other' - } - }; - - searx.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(); - if (e.keyCode === 27) { - if (tagName === 'input' || tagName === 'select' || tagName === 'textarea') { - vimKeys[e.keyCode].fun(); - } - } else { - if (e.target === document.body || tagName === 'a' || tagName === 'button') { - e.preventDefault(); - vimKeys[e.keyCode].fun(); - } - } - } - }); - - function highlightResult(which) { - return function(noScroll) { - var current = document.querySelector('.result[data-vim-selected]'), - effectiveWhich = which; - if (current === null) { - // no selection : choose the first one - current = document.querySelector('.result'); - if (current === null) { - // no first one : there are no results - return; - } - // replace up/down actions by selecting first one - if (which === "down" || which === "up") { - effectiveWhich = current; - } - } - - var next, results = document.querySelectorAll('.result'); - - if (typeof effectiveWhich !== 'string') { - next = effectiveWhich; - } else { - switch (effectiveWhich) { - case 'visible': - var top = document.documentElement.scrollTop || document.body.scrollTop; - var bot = top + document.documentElement.clientHeight; - - for (var i = 0; i < results.length; i++) { - next = results[i]; - var etop = next.offsetTop; - var ebot = etop + next.clientHeight; - - if ((ebot <= bot) && (etop > top)) { - break; - } - } - break; - case 'down': - next = current.nextElementSibling; - if (next === null) { - next = results[0]; - } - break; - case 'up': - next = current.previousElementSibling; - if (next === null) { - next = results[results.length - 1]; - } - break; - case 'bottom': - next = results[results.length - 1]; - break; - case 'top': - /* falls through */ - default: - next = results[0]; - } - } - - if (next) { - current.removeAttribute('data-vim-selected'); - next.setAttribute('data-vim-selected', 'true'); - var link = next.querySelector('h3 a') || next.querySelector('a'); - if (link !== null) { - link.focus(); - } - if (!noScroll) { - scrollPageToSelected(); - } - } - }; - } - - function reloadPage() { - document.location.reload(true); - } - - function removeFocus() { - if (document.activeElement) { - document.activeElement.blur(); - } - } - - function pageButtonClick(css_selector) { - return function() { - 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) { - return; - } - var wtop = document.documentElement.scrollTop || document.body.scrollTop, - wheight = document.documentElement.clientHeight, - etop = sel.offsetTop, - ebot = etop + sel.clientHeight, - offset = 120; - // first element ? - if ((sel.previousElementSibling === null) && (ebot < wheight)) { - // set to the top of page if the first element - // is fully included in the viewport - window.scroll(window.scrollX, 0); - return; - } - if (wtop > (etop - offset)) { - window.scroll(window.scrollX, etop - offset); - } else { - var wbot = wtop + wheight; - if (wbot < (ebot + offset)) { - window.scroll(window.scrollX, ebot - wheight + offset); - } - } - } - - function scrollPage(amount) { - return function() { - window.scrollBy(0, amount); - highlightResult('visible')(); - }; - } - - function scrollPageTo(position, nav) { - return function() { - window.scrollTo(0, position); - highlightResult(nav)(); - }; - } - - function searchInputFocus() { - window.scrollTo(0, 0); - document.querySelector('#q').focus(); - } - - function openResult(newTab) { - return function() { - var link = document.querySelector('.result[data-vim-selected] h3 a'); - if (link !== null) { - var url = link.getAttribute('href'); - if (newTab) { - window.open(url); - } else { - window.location.href = url; - } - } - }; - } - - function initHelpContent(divElement) { - var categories = {}; - - for (var k in vimKeys) { - var key = vimKeys[k]; - categories[key.cat] = categories[key.cat] || []; - categories[key.cat].push(key); - } - - var sorted = Object.keys(categories).sort(function(a, b) { - return categories[b].length - categories[a].length; - }); - - if (sorted.length === 0) { - return; - } - - 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]]; - - var lastCategory = i === (sorted.length - 1); - var first = i % 2 === 0; - - if (first) { - html += ''; - } - html += ''; // col-sm-* - - if (!first || lastCategory) { - html += ''; // row - } - } - - html += '
'; - - html += '

' + cat[0].cat + '

'; - html += '
    '; - - for (var cj in cat) { - html += '
  • ' + cat[cj].key + ' ' + cat[cj].des + '
  • '; - } - - html += '
'; - 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%'; - initHelpContent(helpPanel); - initHelpContent(helpPanel); - initHelpContent(helpPanel); - var body = document.getElementsByTagName('body')[0]; - body.appendChild(helpPanel); - } else { - // togggle hidden - helpPanel.classList.toggle('invisible'); - return; - } - } -}); -;/** -* 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, -*/ -/* global L */ -(function (w, d, searx) { - 'use strict'; - - searx.ready(function () { - searx.on('.searx_init_map', 'click', function(event) { - // no more request - this.classList.remove("searx_init_map"); - - // - var leaflet_target = this.dataset.leafletTarget; - var map_lon = parseFloat(this.dataset.mapLon); - var map_lat = parseFloat(this.dataset.mapLat); - var map_zoom = parseFloat(this.dataset.mapZoom); - 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() { - var map_bounds = null; - if(map_boundingbox) { - var southWest = L.latLng(map_boundingbox[0], map_boundingbox[2]); - var northEast = L.latLng(map_boundingbox[1], map_boundingbox[3]); - map_bounds = L.latLngBounds(southWest, northEast); - } - - // init map - var map = L.map(leaflet_target); - // create the tile layer with correct attribution - var osmMapnikUrl='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'; - 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 | Maps data © OpenStreetMap contributors'; - var osmWikimedia = new L.TileLayer(osmWikimediaUrl, {minZoom: 1, maxZoom: 19, attribution: osmWikimediaAttrib}); - // init map view - if(map_bounds) { - // TODO hack: https://github.com/Leaflet/Leaflet/issues/2021 - // Still useful ? - setTimeout(function () { - map.fitBounds(map_bounds, { - maxZoom:17 - }); - }, 0); - } else if (map_lon && map_lat) { - if(map_zoom) { - map.setView(new L.latLng(map_lat, map_lon),map_zoom); - } else { - map.setView(new L.latLng(map_lat, map_lon),8); - } - } - - map.addLayer(osmMapnik); - - var baseLayers = { - "OSM Mapnik": osmMapnik, - "OSM Wikimedia": osmWikimedia, - }; - - L.control.layers(baseLayers).addTo(map); - - if(map_geojson) { - L.geoJson(map_geojson).addTo(map); - } /*else if(map_bounds) { - L.rectangle(map_bounds, {color: "#ff7800", weight: 3, fill:false}).addTo(map); - }*/ - }); - - // this event occour only once per element - event.preventDefault(); - }); - }); -})(window, document, window.searx); -;(function (w, d, searx) { - 'use strict'; - - searx.ready(function() { - let engine_descriptions = null; - function load_engine_descriptions() { - if (engine_descriptions == null) { - searx.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] + ')'; - element.innerHTML = description[0] + source; - } - } - }); - } - } - - if (d.querySelector('body[class="preferences_endpoint"]')) { - for(const el of d.querySelectorAll('[data-engine-name]')) { - searx.on(el, 'mouseenter', load_engine_descriptions); - } - } - }); -})(window, document, window.searx); -;/** -* 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) { - '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(); - - 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'); - var targetElement = d.querySelector(target); - var html = this.innerHTML; - if (this.classList.contains('collapsed')) { - html = html.replace(btnLabelCollapsed, btnLabelNotCollapsed); - } else { - html = html.replace(btnLabelNotCollapsed, btnLabelCollapsed); - } - this.innerHTML = html; - this.classList.toggle('collapsed'); - targetElement.classList.toggle('invisible'); - }); - - 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'); - if (srctest === null || srctest === undefined || srctest === false) { - iframe_load.setAttribute('src', iframe_load.getAttribute('data-src')); - } - }); - - w.addEventListener('scroll', function() { - var e = d.getElementById('backToTop'), - scrollTop = document.documentElement.scrollTop || document.body.scrollTop; - if (e !== null) { - if (scrollTop >= 200) { - e.style.opacity = 1; - } else { - e.style.opacity = 0; - } - } - }); - - }); - -})(window, document, window.searx); -;/** -* 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, -*/ -/* global AutoComplete */ -(function(w, d, searx) { - 'use strict'; - - var firstFocus = true, qinput_id = "q", qinput; - - function placeCursorAtEnd(element) { - if (element.setSelectionRange) { - var len = element.value.length; - element.setSelectionRange(len, len); - } - } - - function submitIfQuery() { - if (qinput.value.length > 0) { - var search = document.getElementById('search'); - setTimeout(search.submit.bind(search), 0); - } - } - - function createClearButton(qinput) { - var cs = document.getElementById('clear_search'); - var updateClearButton = function() { - if (qinput.value.length === 0) { - cs.classList.add("empty"); - } else { - cs.classList.remove("empty"); - } - }; - - // update status, event listener - updateClearButton(); - cs.addEventListener('click', function() { - qinput.value=''; - qinput.focus(); - updateClearButton(); - }); - qinput.addEventListener('keyup', updateClearButton, false); - } - - searx.ready(function() { - qinput = d.getElementById(qinput_id); - - function placeCursorAtEndOnce() { - if (firstFocus) { - placeCursorAtEnd(qinput); - firstFocus = false; - } else { - // e.preventDefault(); - } - } - - if (qinput !== null) { - // clear button - createClearButton(qinput); - - // autocompleter - if (searx.autocompleter) { - searx.autocomplete = AutoComplete.call(w, { - Url: "./autocompleter", - EmptyMessage: searx.translations.no_item_found, - HttpMethod: searx.method, - HttpHeaders: { - "Content-type": "application/x-www-form-urlencoded", - "X-Requested-With": "XMLHttpRequest" - }, - MinChars: 4, - Delay: 300, - }, "#" + qinput_id); - - // hack, see : https://github.com/autocompletejs/autocomplete.js/issues/37 - w.addEventListener('resize', function() { - var event = new CustomEvent("position"); - qinput.dispatchEvent(event); - }); - } - - qinput.addEventListener('focus', placeCursorAtEndOnce, false); - qinput.focus(); - } - - // vanilla js version of search_on_category_select.js - if (qinput !== null && d.querySelector('.help') != null && searx.search_on_category_select) { - d.querySelector('.help').className='invisible'; - - searx.on('#categories input', 'change', function() { - var i, categories = d.querySelectorAll('#categories input[type="checkbox"]'); - for(i=0; i 0) && (img.naturalHeight > 0)) { - r += img.naturalWidth / img.naturalHeight; - } else { - // assume that not loaded images are square - r += 1; - } - } - - return (width - images.length * this.margin) / r; //have to round down because Firefox will automatically roundup value with number of decimals > 3 - }; - - ImageLayout.prototype._setSize = function (images, height) { - var i, img, imgWidth; - var imagesLength = images.length, resultNode; - - for (i = 0; i < imagesLength; i++) { - img = images[i]; - if ((img.naturalWidth > 0) && (img.naturalHeight > 0)) { - imgWidth = height * img.naturalWidth / img.naturalHeight; - } else { - // not loaded image : make it square as _getHeigth said it - imgWidth = height; - } - img.style.width = imgWidth + 'px'; - img.style.height = height + 'px'; - img.style.marginLeft = '3px'; - img.style.marginTop = '3px'; - img.style.marginRight = this.margin - 7 + 'px'; // -4 is the negative margin of the inline element - img.style.marginBottom = this.margin - 7 + 'px'; - resultNode = img.parentNode.parentNode; - if (!resultNode.classList.contains('js')) { - resultNode.classList.add('js'); - } - } - }; - - ImageLayout.prototype._alignImgs = function (imgGroup) { - var isSearching, slice, i, h; - var containerElement = d.querySelector(this.container_selector); - var containerCompStyles = window.getComputedStyle(containerElement); - var containerPaddingLeft = parseInt(containerCompStyles.getPropertyValue('padding-left'), 10); - var containerPaddingRight = parseInt(containerCompStyles.getPropertyValue('padding-right'), 10); - var containerWidth = containerElement.clientWidth - containerPaddingLeft - containerPaddingRight; - - while (imgGroup.length > 0) { - isSearching = true; - for (i = 1; i <= imgGroup.length && isSearching; i++) { - slice = imgGroup.slice(0, i); - h = this._getHeigth(slice, containerWidth); - if (h < this.maxHeight) { - this._setSize(slice, h); - // continue with the remaining images - imgGroup = imgGroup.slice(i); - isSearching = false; - } - } - if (isSearching) { - this._setSize(slice, Math.min(this.maxHeight, h)); - break; - } - } - }; - - ImageLayout.prototype.align = function () { - var i; - var results_selectorNode = d.querySelectorAll(this.results_selector); - var results_length = results_selectorNode.length; - var previous = null; - var current = null; - var imgGroup = []; - - for (i = 0; i < results_length; i++) { - current = results_selectorNode[i]; - if (current.previousElementSibling !== previous && imgGroup.length > 0) { - // the current image is not connected to previous one - // so the current image is the start of a new group of images. - // so call _alignImgs to align the current group - this._alignImgs(imgGroup); - // and start a new empty group of images - imgGroup = []; - } - // add the current image to the group (only the img tag) - imgGroup.push(current.querySelector(this.img_selector)); - // update the previous variable - previous = current; - } - // align the remaining images - if (imgGroup.length > 0) { - this._alignImgs(imgGroup); - } - }; - - ImageLayout.prototype.watch = function () { - var i, img; - var obj = this; - var results_nodes = d.querySelectorAll(this.results_selector); - var results_length = results_nodes.length; - - function throttleAlign() { - if (obj.isAlignDone) { - obj.isAlignDone = false; - setTimeout(function () { - obj.align(); - obj.isAlignDone = true; - }, 100); - } - } - - w.addEventListener('pageshow', throttleAlign); - w.addEventListener('load', throttleAlign); - w.addEventListener('resize', throttleAlign); - - for (i = 0; i < results_length; i++) { - img = results_nodes[i].querySelector(this.img_selector); - if (img !== null && img !== undefined) { - img.addEventListener('load', throttleAlign); - img.addEventListener('error', throttleAlign); - } - } - }; - - w.searx.ImageLayout = ImageLayout; - -}(window, document)); -;(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.AutoComplete = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i @baptistedonaux - */ -var AutoComplete = /** @class */ (function () { - // Constructor - function AutoComplete(params, selector) { - if (params === void 0) { params = {}; } - if (selector === void 0) { selector = "[data-autocomplete]"; } - if (Array.isArray(selector)) { - selector.forEach(function (s) { - new AutoComplete(params, s); - }); - } - else if (typeof selector == "string") { - var elements = document.querySelectorAll(selector); - Array.prototype.forEach.call(elements, function (input) { - new AutoComplete(params, input); - }); - } - else { - var specificParams = AutoComplete.merge(AutoComplete.defaults, params, { - DOMResults: document.createElement("div") - }); - AutoComplete.prototype.create(specificParams, selector); - return specificParams; - } - } - AutoComplete.prototype.create = function (params, element) { - params.Input = element; - if (params.Input.nodeName.match(/^INPUT$/i) && (params.Input.hasAttribute("type") === false || params.Input.getAttribute("type").match(/^TEXT|SEARCH$/i))) { - params.Input.setAttribute("autocomplete", "off"); - params._Position(params); - params.Input.parentNode.appendChild(params.DOMResults); - params.$Listeners = { - blur: params._Blur.bind(params), - destroy: AutoComplete.prototype.destroy.bind(null, params), - focus: params._Focus.bind(params), - keyup: AutoComplete.prototype.event.bind(null, params, EventType.KEYUP), - keydown: AutoComplete.prototype.event.bind(null, params, EventType.KEYDOWN), - position: params._Position.bind(params) - }; - for (var event in params.$Listeners) { - params.Input.addEventListener(event, params.$Listeners[event]); - } - } - }; - AutoComplete.prototype.getEventsByType = function (params, type) { - var mappings = {}; - for (var key in params.KeyboardMappings) { - var event = EventType.KEYUP; - if (params.KeyboardMappings[key].Event !== undefined) { - event = params.KeyboardMappings[key].Event; - } - if (event == type) { - mappings[key] = params.KeyboardMappings[key]; - } - } - return mappings; - }; - AutoComplete.prototype.event = function (params, type, event) { - var eventIdentifier = function (condition) { - if ((match === true && mapping.Operator == ConditionOperator.AND) || (match === false && mapping.Operator == ConditionOperator.OR)) { - condition = AutoComplete.merge({ - Not: false - }, condition); - if (condition.hasOwnProperty("Is")) { - if (condition.Is == event.keyCode) { - match = !condition.Not; - } - else { - match = condition.Not; - } - } - else if (condition.hasOwnProperty("From") && condition.hasOwnProperty("To")) { - if (event.keyCode >= condition.From && event.keyCode <= condition.To) { - match = !condition.Not; - } - else { - match = condition.Not; - } - } - } - }; - for (var name in AutoComplete.prototype.getEventsByType(params, type)) { - var mapping = AutoComplete.merge({ - Operator: ConditionOperator.AND - }, params.KeyboardMappings[name]), match = ConditionOperator.AND == mapping.Operator; - mapping.Conditions.forEach(eventIdentifier); - if (match === true) { - mapping.Callback.call(params, event); - } - } - }; - AutoComplete.prototype.makeRequest = function (params, callback, callbackErr) { - var propertyHttpHeaders = Object.getOwnPropertyNames(params.HttpHeaders), request = new XMLHttpRequest(), method = params._HttpMethod(), url = params._Url(), queryParams = params._Pre(), queryParamsStringify = encodeURIComponent(params._QueryArg()) + "=" + encodeURIComponent(queryParams); - if (method.match(/^GET$/i)) { - if (url.indexOf("?") !== -1) { - url += "&" + queryParamsStringify; - } - else { - url += "?" + queryParamsStringify; - } - } - request.open(method, url, true); - for (var i = propertyHttpHeaders.length - 1; i >= 0; i--) { - request.setRequestHeader(propertyHttpHeaders[i], params.HttpHeaders[propertyHttpHeaders[i]]); - } - request.onreadystatechange = function () { - if (request.readyState == 4 && request.status == 200) { - params.$Cache[queryParams] = request.response; - callback(request.response); - } - else if (request.status >= 400) { - callbackErr(); - } - }; - return request; - }; - AutoComplete.prototype.ajax = function (params, request, timeout) { - if (timeout === void 0) { timeout = true; } - if (params.$AjaxTimer) { - window.clearTimeout(params.$AjaxTimer); - } - if (timeout === true) { - params.$AjaxTimer = window.setTimeout(AutoComplete.prototype.ajax.bind(null, params, request, false), params.Delay); - } - else { - if (params.Request) { - params.Request.abort(); - } - params.Request = request; - params.Request.send(params._QueryArg() + "=" + params._Pre()); - } - }; - AutoComplete.prototype.cache = function (params, callback, callbackErr) { - var response = params._Cache(params._Pre()); - if (response === undefined) { - var request = AutoComplete.prototype.makeRequest(params, callback, callbackErr); - AutoComplete.prototype.ajax(params, request); - } - else { - callback(response); - } - }; - AutoComplete.prototype.destroy = function (params) { - for (var event in params.$Listeners) { - params.Input.removeEventListener(event, params.$Listeners[event]); - } - params.DOMResults.parentNode.removeChild(params.DOMResults); - }; - AutoComplete.merge = function () { - var merge = {}, tmp; - for (var i = 0; i < arguments.length; i++) { - for (tmp in arguments[i]) { - merge[tmp] = arguments[i][tmp]; - } - } - return merge; - }; - AutoComplete.defaults = { - Delay: 150, - EmptyMessage: "No result here", - Highlight: { - getRegex: function (value) { - return new RegExp(value, "ig"); - }, - transform: function (value) { - return "" + value + ""; - } - }, - HttpHeaders: { - "Content-type": "application/x-www-form-urlencoded" - }, - Limit: 0, - MinChars: 0, - HttpMethod: "GET", - QueryArg: "q", - Url: null, - KeyboardMappings: { - "Enter": { - Conditions: [{ - Is: 13, - Not: false - }], - Callback: function (event) { - if (this.DOMResults.getAttribute("class").indexOf("open") != -1) { - var liActive = this.DOMResults.querySelector("li.active"); - if (liActive !== null) { - event.preventDefault(); - this._Select(liActive); - this.DOMResults.setAttribute("class", "autocomplete"); - } - } - }, - Operator: ConditionOperator.AND, - Event: EventType.KEYDOWN - }, - "KeyUpAndDown_down": { - Conditions: [{ - Is: 38, - Not: false - }, - { - Is: 40, - Not: false - }], - Callback: function (event) { - event.preventDefault(); - }, - Operator: ConditionOperator.OR, - Event: EventType.KEYDOWN - }, - "KeyUpAndDown_up": { - Conditions: [{ - Is: 38, - Not: false - }, - { - Is: 40, - Not: false - }], - Callback: function (event) { - event.preventDefault(); - var first = this.DOMResults.querySelector("li:first-child:not(.locked)"), last = this.DOMResults.querySelector("li:last-child:not(.locked)"), active = this.DOMResults.querySelector("li.active"); - if (active) { - var currentIndex = Array.prototype.indexOf.call(active.parentNode.children, active), position = currentIndex + (event.keyCode - 39), lisCount = this.DOMResults.getElementsByTagName("li").length; - if (position < 0) { - position = lisCount - 1; - } - else if (position >= lisCount) { - position = 0; - } - active.classList.remove("active"); - active.parentElement.children.item(position).classList.add("active"); - } - else if (last && event.keyCode == 38) { - last.classList.add("active"); - } - else if (first) { - first.classList.add("active"); - } - }, - Operator: ConditionOperator.OR, - Event: EventType.KEYUP - }, - "AlphaNum": { - Conditions: [{ - Is: 13, - Not: true - }, { - From: 35, - To: 40, - Not: true - }], - Callback: function () { - var oldValue = this.Input.getAttribute("data-autocomplete-old-value"), currentValue = this._Pre(); - if (currentValue !== "" && currentValue.length >= this._MinChars()) { - if (!oldValue || currentValue != oldValue) { - this.DOMResults.setAttribute("class", "autocomplete open"); - } - AutoComplete.prototype.cache(this, function (response) { - this._Render(this._Post(response)); - this._Open(); - }.bind(this), this._Error); - } - else { - this._Close(); - } - }, - Operator: ConditionOperator.AND, - Event: EventType.KEYUP - } - }, - DOMResults: null, - Request: null, - Input: null, - /** - * Return the message when no result returns - */ - _EmptyMessage: function () { - var emptyMessage = ""; - if (this.Input.hasAttribute("data-autocomplete-empty-message")) { - emptyMessage = this.Input.getAttribute("data-autocomplete-empty-message"); - } - else if (this.EmptyMessage !== false) { - emptyMessage = this.EmptyMessage; - } - else { - emptyMessage = ""; - } - return emptyMessage; - }, - /** - * Returns the maximum number of results - */ - _Limit: function () { - var limit = this.Input.getAttribute("data-autocomplete-limit"); - if (isNaN(limit) || limit === null) { - return this.Limit; - } - return parseInt(limit, 10); - }, - /** - * Returns the minimum number of characters entered before firing ajax - */ - _MinChars: function () { - var minchars = this.Input.getAttribute("data-autocomplete-minchars"); - if (isNaN(minchars) || minchars === null) { - return this.MinChars; - } - return parseInt(minchars, 10); - }, - /** - * Apply transformation on labels response - */ - _Highlight: function (label) { - return label.replace(this.Highlight.getRegex(this._Pre()), this.Highlight.transform); - }, - /** - * Returns the HHTP method to use - */ - _HttpMethod: function () { - if (this.Input.hasAttribute("data-autocomplete-method")) { - return this.Input.getAttribute("data-autocomplete-method"); - } - return this.HttpMethod; - }, - /** - * Returns the query param to use - */ - _QueryArg: function () { - if (this.Input.hasAttribute("data-autocomplete-param-name")) { - return this.Input.getAttribute("data-autocomplete-param-name"); - } - return this.QueryArg; - }, - /** - * Returns the URL to use for AJAX request - */ - _Url: function () { - if (this.Input.hasAttribute("data-autocomplete")) { - return this.Input.getAttribute("data-autocomplete"); - } - return this.Url; - }, - /** - * Manage the close - */ - _Blur: function (now) { - if (now === void 0) { now = false; } - if (now) { - this._Close(); - } - else { - var params = this; - setTimeout(function () { - params._Blur(true); - }, 150); - } - }, - /** - * Manage the cache - */ - _Cache: function (value) { - return this.$Cache[value]; - }, - /** - * Manage the open - */ - _Focus: function () { - var oldValue = this.Input.getAttribute("data-autocomplete-old-value"); - if ((!oldValue || this.Input.value != oldValue) && this._MinChars() <= this.Input.value.length) { - this.DOMResults.setAttribute("class", "autocomplete open"); - } - }, - /** - * Bind all results item if one result is opened - */ - _Open: function () { - var params = this; - Array.prototype.forEach.call(this.DOMResults.getElementsByTagName("li"), function (li) { - if (li.getAttribute("class") != "locked") { - li.onclick = function () { - params._Select(li); - }; - } - }); - }, - _Close: function () { - this.DOMResults.setAttribute("class", "autocomplete"); - }, - /** - * Position the results HTML element - */ - _Position: function () { - this.DOMResults.setAttribute("class", "autocomplete"); - this.DOMResults.setAttribute("style", "top:" + (this.Input.offsetTop + this.Input.offsetHeight) + "px;left:" + this.Input.offsetLeft + "px;width:" + this.Input.clientWidth + "px;"); - }, - /** - * Execute the render of results DOM element - */ - _Render: function (response) { - var ul; - if (typeof response == "string") { - ul = this._RenderRaw(response); - } - else { - ul = this._RenderResponseItems(response); - } - if (this.DOMResults.hasChildNodes()) { - this.DOMResults.removeChild(this.DOMResults.childNodes[0]); - } - this.DOMResults.appendChild(ul); - }, - /** - * ResponseItems[] rendering - */ - _RenderResponseItems: function (response) { - var ul = document.createElement("ul"), li = document.createElement("li"), limit = this._Limit(); - // Order - if (limit < 0) { - response = response.reverse(); - } - else if (limit === 0) { - limit = response.length; - } - for (var item = 0; item < Math.min(Math.abs(limit), response.length); item++) { - li.innerHTML = response[item].Label; - li.setAttribute("data-autocomplete-value", response[item].Value); - ul.appendChild(li); - li = document.createElement("li"); - } - return ul; - }, - /** - * string response rendering (RAW HTML) - */ - _RenderRaw: function (response) { - var ul = document.createElement("ul"), li = document.createElement("li"); - if (response.length > 0) { - this.DOMResults.innerHTML = response; - } - else { - var emptyMessage = this._EmptyMessage(); - if (emptyMessage !== "") { - li.innerHTML = emptyMessage; - li.setAttribute("class", "locked"); - ul.appendChild(li); - } - } - return ul; - }, - /** - * Deal with request response - */ - _Post: function (response) { - try { - var returnResponse = []; - //JSON return - var json = JSON.parse(response); - if (Object.keys(json).length === 0) { - return ""; - } - if (Array.isArray(json)) { - for (var i = 0; i < Object.keys(json).length; i++) { - returnResponse[returnResponse.length] = { "Value": json[i], "Label": this._Highlight(json[i]) }; - } - } - else { - for (var value in json) { - returnResponse.push({ - "Value": value, - "Label": this._Highlight(json[value]) - }); - } - } - return returnResponse; - } - catch (event) { - //HTML return - return response; - } - }, - /** - * Return the autocomplete value to send (before request) - */ - _Pre: function () { - return this.Input.value; - }, - /** - * Choice one result item - */ - _Select: function (item) { - if (item.hasAttribute("data-autocomplete-value")) { - this.Input.value = item.getAttribute("data-autocomplete-value"); - } - else { - this.Input.value = item.innerHTML; - } - this.Input.setAttribute("data-autocomplete-old-value", this.Input.value); - }, - /** - * Handle HTTP error on the request - */ - _Error: function () { - }, - $AjaxTimer: null, - $Cache: {}, - $Listeners: {} - }; - return AutoComplete; -}()); -module.exports = AutoComplete; - -},{}]},{},[1])(1) -}); diff --git a/searx/static/themes/simple/js/searx.min.js b/searx/static/themes/simple/js/searx.min.js deleted file mode 100644 index 30b89899c..000000000 --- a/searx/static/themes/simple/js/searx.min.js +++ /dev/null @@ -1,24 +0,0 @@ -window.searx=function(t,o){"use strict";if(t.Element){(function(e){e.matches=e.matches||e.matchesSelector||e.webkitMatchesSelector||e.msMatchesSelector||function(e){var t=this,n=(t.parentNode||t.document).querySelectorAll(e),i=-1;while(n[++i]&&n[i]!=t);return!!n[i]}})(Element.prototype)}function a(e,t,n){try{e.call(t,n)}catch(e){console.log(e)}}var s=window.searx||{};s.on=function(i,e,r,t){t=t||false;if(typeof i!=="string"){i.addEventListener(e,r,t)}else{o.addEventListener(e,function(e){var t=e.target||e.srcElement,n=false;while(t&&t.matches&&t!==o&&!(n=t.matches(i)))t=t.parentElement;if(n)a(r,t,e)},t)}};s.ready=function(e){if(document.readyState!="loading"){e.call(t)}else{t.addEventListener("DOMContentLoaded",e.bind(t))}};s.http=function(e,t){var n=new XMLHttpRequest,i=function(){},r=function(){},o={then:function(e){i=e;return o},catch:function(e){r=e;return o}};try{n.open(e,t,true);n.onload=function(){if(n.status==200){i(n.response,n.responseType)}else{r(Error(n.statusText))}};n.onerror=function(){r(Error("Network Error"))};n.onabort=function(){r(Error("Transaction is aborted"))};n.send()}catch(e){r(e)}return o};s.loadStyle=function(e){var t=s.static_path+e,n="style_"+e.replace(".","_"),i=o.getElementById(n);if(i===null){i=o.createElement("link");i.setAttribute("id",n);i.setAttribute("rel","stylesheet");i.setAttribute("type","text/css");i.setAttribute("href",t);o.body.appendChild(i)}};s.loadScript=function(e,t){var n=s.static_path+e,i="script_"+e.replace(".","_"),r=o.getElementById(i);if(r===null){r=o.createElement("script");r.setAttribute("id",i);r.setAttribute("src",n);r.onload=t;r.onerror=function(){r.setAttribute("error","1")};o.body.appendChild(r)}else if(!r.hasAttribute("error")){try{t.apply(r,[])}catch(e){console.log(e)}}else{console.log("callback not executed : script '"+n+"' not loaded.")}};s.insertBefore=function(e,t){t.parentNode.insertBefore(e,t)};s.insertAfter=function(e,t){t.parentNode.insertAfter(e,t.nextSibling)};s.on(".close","click",function(){this.parentNode.classList.add("invisible")});return s}(window,document);searx.ready(function(){searx.on(".result","click",function(){n(this)(true)});searx.on(".result a","focus",function(e){var t=e.target;while(t!==undefined){if(t.classList.contains("result")){if(t.getAttribute("data-vim-selected")===null){n(t)(true)}break}t=t.parentNode}},true);var d={27:{key:"Escape",fun:t,des:"remove focus from the focused input",cat:"Control"},73:{key:"i",fun:l,des:"focus on the search input",cat:"Control"},66:{key:"b",fun:a(-window.innerHeight),des:"scroll one page up",cat:"Navigation"},70:{key:"f",fun:a(window.innerHeight),des:"scroll one page down",cat:"Navigation"},85:{key:"u",fun:a(-window.innerHeight/2),des:"scroll half a page up",cat:"Navigation"},68:{key:"d",fun:a(window.innerHeight/2),des:"scroll half a page down",cat:"Navigation"},71:{key:"g",fun:s(-document.body.scrollHeight,"top"),des:"scroll to the top of the page",cat:"Navigation"},86:{key:"v",fun:s(document.body.scrollHeight,"bottom"),des:"scroll to the bottom of the page",cat:"Navigation"},75:{key:"k",fun:n("up"),des:"select previous search result",cat:"Results"},74:{key:"j",fun:n("down"),des:"select next search result",cat:"Results"},80:{key:"p",fun:o(),des:"go to previous page",cat:"Results"},78:{key:"n",fun:r(),des:"go to next page",cat:"Results"},79:{key:"o",fun:u(false),des:"open search result",cat:"Results"},84:{key:"t",fun:u(true),des:"open the result in a new tab",cat:"Results"},82:{key:"r",fun:e,des:"reload page from the server",cat:"Control"},72:{key:"h",fun:p,des:"toggle help window",cat:"Other"}};searx.on(document,"keydown",function(e){if(Object.prototype.hasOwnProperty.call(d,e.keyCode)&&!e.ctrlKey&&!e.altKey&&!e.shiftKey&&!e.metaKey){var t=e.target.tagName.toLowerCase();if(e.keyCode===27){if(t==="input"||t==="select"||t==="textarea"){d[e.keyCode].fun()}}else{if(e.target===document.body||t==="a"||t==="button"){e.preventDefault();d[e.keyCode].fun()}}}});function n(d){return function(e){var t=document.querySelector(".result[data-vim-selected]"),n=d;if(t===null){t=document.querySelector(".result");if(t===null){return}if(d==="down"||d==="up"){n=t}}var i,r=document.querySelectorAll(".result");if(typeof n!=="string"){i=n}else{switch(n){case"visible":var o=document.documentElement.scrollTop||document.body.scrollTop;var a=o+document.documentElement.clientHeight;for(var s=0;so){break}}break;case"down":i=t.nextElementSibling;if(i===null){i=r[0]}break;case"up":i=t.previousElementSibling;if(i===null){i=r[r.length-1]}break;case"bottom":i=r[r.length-1];break;case"top":default:i=r[0]}}if(i){t.removeAttribute("data-vim-selected");i.setAttribute("data-vim-selected","true");var c=i.querySelector("h3 a")||i.querySelector("a");if(c!==null){c.focus()}if(!e){f()}}}}function e(){document.location.reload(true)}function t(){if(document.activeElement){document.activeElement.blur()}}function i(t){return function(){var e=document.querySelector(t);if(e){e.click()}}}function r(){return i('nav#pagination .next_page button[type="submit"]')}function o(){return i('nav#pagination .previous_page button[type="submit"]')}function f(){var e=document.querySelector(".result[data-vim-selected]");if(e===null){return}var t=document.documentElement.scrollTop||document.body.scrollTop,n=document.documentElement.clientHeight,i=e.offsetTop,r=i+e.clientHeight,o=120;if(e.previousElementSibling===null&&ri-o){window.scroll(window.scrollX,i-o)}else{var a=t+n;if(a"}o+="";o+="

"+s[0].cat+"

";o+='
    ';for(var c in s){o+="
  • "+s[c].key+" "+s[c].des+"
  • "}o+="
";o+="";if(!u||l){o+=""}}o+="";e.innerHTML=o}function p(){var e=document.querySelector("#vim-hotkeys-help");console.log(e);if(e===undefined||e===null){e=document.createElement("div");e.id="vim-hotkeys-help";e.className="dialog-modal";e.style="width: 40%";c(e);c(e);c(e);var t=document.getElementsByTagName("body")[0];t.appendChild(e)}else{e.classList.toggle("invisible");return}}});(function(e,t,n){"use strict";n.ready(function(){n.on(".searx_init_map","click",function(e){this.classList.remove("searx_init_map");var d=this.dataset.leafletTarget;var f=parseFloat(this.dataset.mapLon);var p=parseFloat(this.dataset.mapLat);var h=parseFloat(this.dataset.mapZoom);var m=JSON.parse(this.dataset.mapBoundingbox);var g=JSON.parse(this.dataset.mapGeojson);n.loadStyle("css/leaflet.css");n.loadScript("js/leaflet.js",function(){var e=null;if(m){var t=L.latLng(m[0],m[2]);var n=L.latLng(m[1],m[3]);e=L.latLngBounds(t,n)}var i=L.map(d);var r="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png";var o='Map data © OpenStreetMap contributors';var a=new L.TileLayer(r,{minZoom:1,maxZoom:19,attribution:o});var s="https://maps.wikimedia.org/osm-intl/{z}/{x}/{y}.png";var l='Wikimedia maps | Maps data © OpenStreetMap contributors';var u=new L.TileLayer(s,{minZoom:1,maxZoom:19,attribution:l});if(e){setTimeout(function(){i.fitBounds(e,{maxZoom:17})},0)}else if(f&&p){if(h){i.setView(new L.latLng(p,f),h)}else{i.setView(new L.latLng(p,f),8)}}i.addLayer(a);var c={"OSM Mapnik":a,"OSM Wikimedia":u};L.control.layers(c).addTo(i);if(g){L.geoJson(g).addTo(i)}});e.preventDefault()})})})(window,document,window.searx);(function(e,o,a){"use strict";a.ready(function(){let r=null;function e(){if(r==null){a.http("GET","engine_descriptions.json").then(function(e){r=JSON.parse(e);for(const[t,n]of Object.entries(r)){let e=o.querySelectorAll('[data-engine-name="'+t+'"] .engine-description');for(const i of e){let e=" ("+a.translations["Source"]+": "+n[1]+")";i.innerHTML=n[0]+e}}})}}if(o.querySelector('body[class="preferences_endpoint"]')){for(const t of o.querySelectorAll("[data-engine-name]")){a.on(t,"mouseenter",e)}}})})(window,document,window.searx);(function(e,o,t){"use strict";t.ready(function(){t.image_thumbnail_layout=new t.ImageLayout("#urls","#urls .result-images","img.image_thumbnail",10,200);t.image_thumbnail_layout.watch();t.on(".btn-collapse","click",function(){var e=this.getAttribute("data-btn-text-collapsed");var t=this.getAttribute("data-btn-text-not-collapsed");var n=this.getAttribute("data-target");var i=o.querySelector(n);var r=this.innerHTML;if(this.classList.contains("collapsed")){r=r.replace(e,t)}else{r=r.replace(t,e)}this.innerHTML=r;this.classList.toggle("collapsed");i.classList.toggle("invisible")});t.on(".media-loader","click",function(){var e=this.getAttribute("data-target");var t=o.querySelector(e+" > iframe");var n=t.getAttribute("src");if(n===null||n===undefined||n===false){t.setAttribute("src",t.getAttribute("data-src"))}});e.addEventListener("scroll",function(){var e=o.getElementById("backToTop"),t=document.documentElement.scrollTop||document.body.scrollTop;if(e!==null){if(t>=200){e.style.opacity=1}else{e.style.opacity=0}}})})})(window,document,window.searx);(function(t,n,i){"use strict";var r=true,o="q",a;function s(e){if(e.setSelectionRange){var t=e.value.length;e.setSelectionRange(t,t)}}function l(){if(a.value.length>0){var e=document.getElementById("search");setTimeout(e.submit.bind(e),0)}}function u(e){var t=document.getElementById("clear_search");var n=function(){if(e.value.length===0){t.classList.add("empty")}else{t.classList.remove("empty")}};n();t.addEventListener("click",function(){e.value="";e.focus();n()});e.addEventListener("keyup",n,false)}i.ready(function(){a=n.getElementById(o);function e(){if(r){s(a);r=false}else{}}if(a!==null){u(a);if(i.autocompleter){i.autocomplete=AutoComplete.call(t,{Url:"./autocompleter",EmptyMessage:i.translations.no_item_found,HttpMethod:i.method,HttpHeaders:{"Content-type":"application/x-www-form-urlencoded","X-Requested-With":"XMLHttpRequest"},MinChars:4,Delay:300},"#"+o);t.addEventListener("resize",function(){var e=new CustomEvent("position");a.dispatchEvent(e)})}a.addEventListener("focus",e,false);a.focus()}if(a!==null&&n.querySelector(".help")!=null&&i.search_on_category_select){n.querySelector(".help").className="invisible";i.on("#categories input","change",function(){var e,t=n.querySelectorAll('#categories input[type="checkbox"]');for(e=0;e0&&i.naturalHeight>0){r+=i.naturalWidth/i.naturalHeight}else{r+=1}}return(t-e.length*this.margin)/r};e.prototype._setSize=function(e,t){var n,i,r;var o=e.length,a;for(n=0;n0&&i.naturalHeight>0){r=t*i.naturalWidth/i.naturalHeight}else{r=t}i.style.width=r+"px";i.style.height=t+"px";i.style.marginLeft="3px";i.style.marginTop="3px";i.style.marginRight=this.margin-7+"px";i.style.marginBottom=this.margin-7+"px";a=i.parentNode.parentNode;if(!a.classList.contains("js")){a.classList.add("js")}}};e.prototype._alignImgs=function(e){var t,n,i,r;var o=c.querySelector(this.container_selector);var a=window.getComputedStyle(o);var s=parseInt(a.getPropertyValue("padding-left"),10);var l=parseInt(a.getPropertyValue("padding-right"),10);var u=o.clientWidth-s-l;while(e.length>0){t=true;for(i=1;i<=e.length&&t;i++){n=e.slice(0,i);r=this._getHeigth(n,u);if(r0){this._alignImgs(o);o=[]}o.push(r.querySelector(this.img_selector));i=r}if(o.length>0){this._alignImgs(o)}};e.prototype.watch=function(){var e,t;var n=this;var i=c.querySelectorAll(this.results_selector);var r=i.length;function o(){if(n.isAlignDone){n.isAlignDone=false;setTimeout(function(){n.align();n.isAlignDone=true},100)}}a.addEventListener("pageshow",o);a.addEventListener("load",o);a.addEventListener("resize",o);for(e=0;e=e.From&&n.keyCode<=e.To){a=!e.Not}else{a=e.Not}}}};for(var r in s.prototype.getEventsByType(e,t)){var o=s.merge({Operator:l.AND},e.KeyboardMappings[r]),a=l.AND==o.Operator;o.Conditions.forEach(i);if(a===true){o.Callback.call(e,n)}}};s.prototype.makeRequest=function(e,t,n){var i=Object.getOwnPropertyNames(e.HttpHeaders),r=new XMLHttpRequest,o=e._HttpMethod(),a=e._Url(),s=e._Pre(),l=encodeURIComponent(e._QueryArg())+"="+encodeURIComponent(s);if(o.match(/^GET$/i)){if(a.indexOf("?")!==-1){a+="&"+l}else{a+="?"+l}}r.open(o,a,true);for(var u=i.length-1;u>=0;u--){r.setRequestHeader(i[u],e.HttpHeaders[i[u]])}r.onreadystatechange=function(){if(r.readyState==4&&r.status==200){e.$Cache[s]=r.response;t(r.response)}else if(r.status>=400){n()}};return r};s.prototype.ajax=function(e,t,n){if(n===void 0){n=true}if(e.$AjaxTimer){window.clearTimeout(e.$AjaxTimer)}if(n===true){e.$AjaxTimer=window.setTimeout(s.prototype.ajax.bind(null,e,t,false),e.Delay)}else{if(e.Request){e.Request.abort()}e.Request=t;e.Request.send(e._QueryArg()+"="+e._Pre())}};s.prototype.cache=function(e,t,n){var i=e._Cache(e._Pre());if(i===undefined){var r=s.prototype.makeRequest(e,t,n);s.prototype.ajax(e,r)}else{t(i)}};s.prototype.destroy=function(e){for(var t in e.$Listeners){e.Input.removeEventListener(t,e.$Listeners[t])}e.DOMResults.parentNode.removeChild(e.DOMResults)};s.merge=function(){var e={},t;for(var n=0;n"+e+""}},HttpHeaders:{"Content-type":"application/x-www-form-urlencoded"},Limit:0,MinChars:0,HttpMethod:"GET",QueryArg:"q",Url:null,KeyboardMappings:{Enter:{Conditions:[{Is:13,Not:false}],Callback:function(e){if(this.DOMResults.getAttribute("class").indexOf("open")!=-1){var t=this.DOMResults.querySelector("li.active");if(t!==null){e.preventDefault();this._Select(t);this.DOMResults.setAttribute("class","autocomplete")}}},Operator:l.AND,Event:o.KEYDOWN},KeyUpAndDown_down:{Conditions:[{Is:38,Not:false},{Is:40,Not:false}],Callback:function(e){e.preventDefault()},Operator:l.OR,Event:o.KEYDOWN},KeyUpAndDown_up:{Conditions:[{Is:38,Not:false},{Is:40,Not:false}],Callback:function(e){e.preventDefault();var t=this.DOMResults.querySelector("li:first-child:not(.locked)"),n=this.DOMResults.querySelector("li:last-child:not(.locked)"),i=this.DOMResults.querySelector("li.active");if(i){var r=Array.prototype.indexOf.call(i.parentNode.children,i),o=r+(e.keyCode-39),a=this.DOMResults.getElementsByTagName("li").length;if(o<0){o=a-1}else if(o>=a){o=0}i.classList.remove("active");i.parentElement.children.item(o).classList.add("active")}else if(n&&e.keyCode==38){n.classList.add("active")}else if(t){t.classList.add("active")}},Operator:l.OR,Event:o.KEYUP},AlphaNum:{Conditions:[{Is:13,Not:true},{From:35,To:40,Not:true}],Callback:function(){var e=this.Input.getAttribute("data-autocomplete-old-value"),t=this._Pre();if(t!==""&&t.length>=this._MinChars()){if(!e||t!=e){this.DOMResults.setAttribute("class","autocomplete open")}s.prototype.cache(this,function(e){this._Render(this._Post(e));this._Open()}.bind(this),this._Error)}else{this._Close()}},Operator:l.AND,Event:o.KEYUP}},DOMResults:null,Request:null,Input:null,_EmptyMessage:function(){var e="";if(this.Input.hasAttribute("data-autocomplete-empty-message")){e=this.Input.getAttribute("data-autocomplete-empty-message")}else if(this.EmptyMessage!==false){e=this.EmptyMessage}else{e=""}return e},_Limit:function(){var e=this.Input.getAttribute("data-autocomplete-limit");if(isNaN(e)||e===null){return this.Limit}return parseInt(e,10)},_MinChars:function(){var e=this.Input.getAttribute("data-autocomplete-minchars");if(isNaN(e)||e===null){return this.MinChars}return parseInt(e,10)},_Highlight:function(e){return e.replace(this.Highlight.getRegex(this._Pre()),this.Highlight.transform)},_HttpMethod:function(){if(this.Input.hasAttribute("data-autocomplete-method")){return this.Input.getAttribute("data-autocomplete-method")}return this.HttpMethod},_QueryArg:function(){if(this.Input.hasAttribute("data-autocomplete-param-name")){return this.Input.getAttribute("data-autocomplete-param-name")}return this.QueryArg},_Url:function(){if(this.Input.hasAttribute("data-autocomplete")){return this.Input.getAttribute("data-autocomplete")}return this.Url},_Blur:function(e){if(e===void 0){e=false}if(e){this._Close()}else{var t=this;setTimeout(function(){t._Blur(true)},150)}},_Cache:function(e){return this.$Cache[e]},_Focus:function(){var e=this.Input.getAttribute("data-autocomplete-old-value");if((!e||this.Input.value!=e)&&this._MinChars()<=this.Input.value.length){this.DOMResults.setAttribute("class","autocomplete open")}},_Open:function(){var t=this;Array.prototype.forEach.call(this.DOMResults.getElementsByTagName("li"),function(e){if(e.getAttribute("class")!="locked"){e.onclick=function(){t._Select(e)}}})},_Close:function(){this.DOMResults.setAttribute("class","autocomplete")},_Position:function(){this.DOMResults.setAttribute("class","autocomplete");this.DOMResults.setAttribute("style","top:"+(this.Input.offsetTop+this.Input.offsetHeight)+"px;left:"+this.Input.offsetLeft+"px;width:"+this.Input.clientWidth+"px;")},_Render:function(e){var t;if(typeof e=="string"){t=this._RenderRaw(e)}else{t=this._RenderResponseItems(e)}if(this.DOMResults.hasChildNodes()){this.DOMResults.removeChild(this.DOMResults.childNodes[0])}this.DOMResults.appendChild(t)},_RenderResponseItems:function(e){var t=document.createElement("ul"),n=document.createElement("li"),i=this._Limit();if(i<0){e=e.reverse()}else if(i===0){i=e.length}for(var r=0;r0){this.DOMResults.innerHTML=e}else{var i=this._EmptyMessage();if(i!==""){n.innerHTML=i;n.setAttribute("class","locked");t.appendChild(n)}}return t},_Post:function(t){try{var e=[];var n=JSON.parse(t);if(Object.keys(n).length===0){return""}if(Array.isArray(n)){for(var i=0;i top)) { + break; + } + } + break; + case 'down': + next = current.nextElementSibling; + if (next === null) { + next = results[0]; + } + break; + case 'up': + next = current.previousElementSibling; + if (next === null) { + next = results[results.length - 1]; + } + break; + case 'bottom': + next = results[results.length - 1]; + break; + case 'top': + /* falls through */ + default: + next = results[0]; + } + } + + if (next) { + current.removeAttribute('data-vim-selected'); + next.setAttribute('data-vim-selected', 'true'); + var link = next.querySelector('h3 a') || next.querySelector('a'); + if (link !== null) { + link.focus(); + } + if (!noScroll) { + scrollPageToSelected(); + } + } + }; + } + + function reloadPage() { + document.location.reload(true); + } + + function removeFocus() { + if (document.activeElement) { + document.activeElement.blur(); + } + } + + function pageButtonClick(css_selector) { + return function() { + 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) { + return; + } + var wtop = document.documentElement.scrollTop || document.body.scrollTop, + wheight = document.documentElement.clientHeight, + etop = sel.offsetTop, + ebot = etop + sel.clientHeight, + offset = 120; + // first element ? + if ((sel.previousElementSibling === null) && (ebot < wheight)) { + // set to the top of page if the first element + // is fully included in the viewport + window.scroll(window.scrollX, 0); + return; + } + if (wtop > (etop - offset)) { + window.scroll(window.scrollX, etop - offset); + } else { + var wbot = wtop + wheight; + if (wbot < (ebot + offset)) { + window.scroll(window.scrollX, ebot - wheight + offset); + } + } + } + + function scrollPage(amount) { + return function() { + window.scrollBy(0, amount); + highlightResult('visible')(); + }; + } + + function scrollPageTo(position, nav) { + return function() { + window.scrollTo(0, position); + highlightResult(nav)(); + }; + } + + function searchInputFocus() { + window.scrollTo(0, 0); + document.querySelector('#q').focus(); + } + + function openResult(newTab) { + return function() { + var link = document.querySelector('.result[data-vim-selected] h3 a'); + if (link !== null) { + var url = link.getAttribute('href'); + if (newTab) { + window.open(url); + } else { + window.location.href = url; + } + } + }; + } + + function initHelpContent(divElement) { + var categories = {}; + + for (var k in vimKeys) { + var key = vimKeys[k]; + categories[key.cat] = categories[key.cat] || []; + categories[key.cat].push(key); + } + + var sorted = Object.keys(categories).sort(function(a, b) { + return categories[b].length - categories[a].length; + }); + + if (sorted.length === 0) { + return; + } + + 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]]; + + var lastCategory = i === (sorted.length - 1); + var first = i % 2 === 0; + + if (first) { + html += ''; + } + html += ''; // col-sm-* + + if (!first || lastCategory) { + html += ''; // row + } + } + + html += '
'; + + html += '

' + cat[0].cat + '

'; + html += '
    '; + + for (var cj in cat) { + html += '
  • ' + cat[cj].key + ' ' + cat[cj].des + '
  • '; + } + + html += '
'; + 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%'; + initHelpContent(helpPanel); + initHelpContent(helpPanel); + initHelpContent(helpPanel); + var body = document.getElementsByTagName('body')[0]; + body.appendChild(helpPanel); + } else { + // togggle hidden + helpPanel.classList.toggle('invisible'); + return; + } + } +}); +;/* SPDX-License-Identifier: AGPL-3.0-or-later */ +/* global L */ +(function (w, d, searxng) { + 'use strict'; + + searxng.ready(function () { + searxng.on('.searxng_init_map', 'click', function(event) { + // no more request + this.classList.remove("searxng_init_map"); + + // + var leaflet_target = this.dataset.leafletTarget; + var map_lon = parseFloat(this.dataset.mapLon); + var map_lat = parseFloat(this.dataset.mapLat); + var map_zoom = parseFloat(this.dataset.mapZoom); + var map_boundingbox = JSON.parse(this.dataset.mapBoundingbox); + var map_geojson = JSON.parse(this.dataset.mapGeojson); + + 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]); + var northEast = L.latLng(map_boundingbox[1], map_boundingbox[3]); + map_bounds = L.latLngBounds(southWest, northEast); + } + + // init map + var map = L.map(leaflet_target); + // create the tile layer with correct attribution + var osmMapnikUrl='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'; + 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 | Maps data © OpenStreetMap contributors'; + var osmWikimedia = new L.TileLayer(osmWikimediaUrl, {minZoom: 1, maxZoom: 19, attribution: osmWikimediaAttrib}); + // init map view + if(map_bounds) { + // TODO hack: https://github.com/Leaflet/Leaflet/issues/2021 + // Still useful ? + setTimeout(function () { + map.fitBounds(map_bounds, { + maxZoom:17 + }); + }, 0); + } else if (map_lon && map_lat) { + if(map_zoom) { + map.setView(new L.latLng(map_lat, map_lon),map_zoom); + } else { + map.setView(new L.latLng(map_lat, map_lon),8); + } + } + + map.addLayer(osmMapnik); + + var baseLayers = { + "OSM Mapnik": osmMapnik, + "OSM Wikimedia": osmWikimedia, + }; + + L.control.layers(baseLayers).addTo(map); + + if(map_geojson) { + L.geoJson(map_geojson).addTo(map); + } /*else if(map_bounds) { + L.rectangle(map_bounds, {color: "#ff7800", weight: 3, fill:false}).addTo(map); + }*/ + }); + + // this event occour only once per element + event.preventDefault(); + }); + }); +})(window, document, window.searxng); +;/* SPDX-License-Identifier: AGPL-3.0-or-later */ +(function (w, d, searxng) { + 'use strict'; + + searxng.ready(function() { + let engine_descriptions = null; + function load_engine_descriptions() { + if (engine_descriptions == null) { + 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 = ' (' + searxng.translations['Source'] + ': ' + description[1] + ')'; + element.innerHTML = description[0] + source; + } + } + }); + } + } + + if (d.querySelector('body[class="preferences_endpoint"]')) { + for(const el of d.querySelectorAll('[data-engine-name]')) { + searxng.on(el, 'mouseenter', load_engine_descriptions); + } + } + }); +})(window, document, window.searxng); +;/* SPDX-License-Identifier: AGPL-3.0-or-later */ +(function(w, d, searxng) { + 'use strict'; + + searxng.ready(function() { + searxng.image_thumbnail_layout = new searxng.ImageLayout('#urls', '#urls .result-images', 'img.image_thumbnail', 10, 200); + searxng.image_thumbnail_layout.watch(); + + 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'); + var targetElement = d.querySelector(target); + var html = this.innerHTML; + if (this.classList.contains('collapsed')) { + html = html.replace(btnLabelCollapsed, btnLabelNotCollapsed); + } else { + html = html.replace(btnLabelNotCollapsed, btnLabelCollapsed); + } + this.innerHTML = html; + this.classList.toggle('collapsed'); + targetElement.classList.toggle('invisible'); + }); + + 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'); + if (srctest === null || srctest === undefined || srctest === false) { + iframe_load.setAttribute('src', iframe_load.getAttribute('data-src')); + } + }); + + w.addEventListener('scroll', function() { + var e = d.getElementById('backToTop'), + scrollTop = document.documentElement.scrollTop || document.body.scrollTop; + if (e !== null) { + if (scrollTop >= 200) { + e.style.opacity = 1; + } else { + e.style.opacity = 0; + } + } + }); + + }); + +})(window, document, window.searxng); +;/* SPDX-License-Identifier: AGPL-3.0-or-later */ +/* global AutoComplete */ +(function(w, d, searxng) { + 'use strict'; + + var firstFocus = true, qinput_id = "q", qinput; + + function placeCursorAtEnd(element) { + if (element.setSelectionRange) { + var len = element.value.length; + element.setSelectionRange(len, len); + } + } + + function submitIfQuery() { + if (qinput.value.length > 0) { + var search = document.getElementById('search'); + setTimeout(search.submit.bind(search), 0); + } + } + + function createClearButton(qinput) { + var cs = document.getElementById('clear_search'); + var updateClearButton = function() { + if (qinput.value.length === 0) { + cs.classList.add("empty"); + } else { + cs.classList.remove("empty"); + } + }; + + // update status, event listener + updateClearButton(); + cs.addEventListener('click', function() { + qinput.value=''; + qinput.focus(); + updateClearButton(); + }); + qinput.addEventListener('keyup', updateClearButton, false); + } + + searxng.ready(function() { + qinput = d.getElementById(qinput_id); + + function placeCursorAtEndOnce() { + if (firstFocus) { + placeCursorAtEnd(qinput); + firstFocus = false; + } else { + // e.preventDefault(); + } + } + + if (qinput !== null) { + // clear button + createClearButton(qinput); + + // autocompleter + if (searxng.autocompleter) { + searxng.autocomplete = AutoComplete.call(w, { + Url: "./autocompleter", + EmptyMessage: searxng.translations.no_item_found, + HttpMethod: searxng.method, + HttpHeaders: { + "Content-type": "application/x-www-form-urlencoded", + "X-Requested-With": "XMLHttpRequest" + }, + MinChars: 4, + Delay: 300, + }, "#" + qinput_id); + + // hack, see : https://github.com/autocompletejs/autocomplete.js/issues/37 + w.addEventListener('resize', function() { + var event = new CustomEvent("position"); + qinput.dispatchEvent(event); + }); + } + + qinput.addEventListener('focus', placeCursorAtEndOnce, false); + qinput.focus(); + } + + // vanilla js version of search_on_category_select.js + if (qinput !== null && d.querySelector('.help') != null && searxng.search_on_category_select) { + d.querySelector('.help').className='invisible'; + + searxng.on('#categories input', 'change', function() { + var i, categories = d.querySelectorAll('#categories input[type="checkbox"]'); + for(i=0; i 0) && (img.naturalHeight > 0)) { + r += img.naturalWidth / img.naturalHeight; + } else { + // assume that not loaded images are square + r += 1; + } + } + + return (width - images.length * this.margin) / r; //have to round down because Firefox will automatically roundup value with number of decimals > 3 + }; + + ImageLayout.prototype._setSize = function (images, height) { + var i, img, imgWidth; + var imagesLength = images.length, resultNode; + + for (i = 0; i < imagesLength; i++) { + img = images[i]; + if ((img.naturalWidth > 0) && (img.naturalHeight > 0)) { + imgWidth = height * img.naturalWidth / img.naturalHeight; + } else { + // not loaded image : make it square as _getHeigth said it + imgWidth = height; + } + img.style.width = imgWidth + 'px'; + img.style.height = height + 'px'; + img.style.marginLeft = '3px'; + img.style.marginTop = '3px'; + img.style.marginRight = this.margin - 7 + 'px'; // -4 is the negative margin of the inline element + img.style.marginBottom = this.margin - 7 + 'px'; + resultNode = img.parentNode.parentNode; + if (!resultNode.classList.contains('js')) { + resultNode.classList.add('js'); + } + } + }; + + ImageLayout.prototype._alignImgs = function (imgGroup) { + var isSearching, slice, i, h; + var containerElement = d.querySelector(this.container_selector); + var containerCompStyles = window.getComputedStyle(containerElement); + var containerPaddingLeft = parseInt(containerCompStyles.getPropertyValue('padding-left'), 10); + var containerPaddingRight = parseInt(containerCompStyles.getPropertyValue('padding-right'), 10); + var containerWidth = containerElement.clientWidth - containerPaddingLeft - containerPaddingRight; + + while (imgGroup.length > 0) { + isSearching = true; + for (i = 1; i <= imgGroup.length && isSearching; i++) { + slice = imgGroup.slice(0, i); + h = this._getHeigth(slice, containerWidth); + if (h < this.maxHeight) { + this._setSize(slice, h); + // continue with the remaining images + imgGroup = imgGroup.slice(i); + isSearching = false; + } + } + if (isSearching) { + this._setSize(slice, Math.min(this.maxHeight, h)); + break; + } + } + }; + + ImageLayout.prototype.align = function () { + var i; + var results_selectorNode = d.querySelectorAll(this.results_selector); + var results_length = results_selectorNode.length; + var previous = null; + var current = null; + var imgGroup = []; + + for (i = 0; i < results_length; i++) { + current = results_selectorNode[i]; + if (current.previousElementSibling !== previous && imgGroup.length > 0) { + // the current image is not connected to previous one + // so the current image is the start of a new group of images. + // so call _alignImgs to align the current group + this._alignImgs(imgGroup); + // and start a new empty group of images + imgGroup = []; + } + // add the current image to the group (only the img tag) + imgGroup.push(current.querySelector(this.img_selector)); + // update the previous variable + previous = current; + } + // align the remaining images + if (imgGroup.length > 0) { + this._alignImgs(imgGroup); + } + }; + + ImageLayout.prototype.watch = function () { + var i, img; + var obj = this; + var results_nodes = d.querySelectorAll(this.results_selector); + var results_length = results_nodes.length; + + function throttleAlign() { + if (obj.isAlignDone) { + obj.isAlignDone = false; + setTimeout(function () { + obj.align(); + obj.isAlignDone = true; + }, 100); + } + } + + w.addEventListener('pageshow', throttleAlign); + w.addEventListener('load', throttleAlign); + w.addEventListener('resize', throttleAlign); + + for (i = 0; i < results_length; i++) { + img = results_nodes[i].querySelector(this.img_selector); + if (img !== null && img !== undefined) { + img.addEventListener('load', throttleAlign); + img.addEventListener('error', throttleAlign); + } + } + }; + + w.searxng.ImageLayout = ImageLayout; + +}(window, document)); +;(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.AutoComplete = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i @baptistedonaux + */ +var AutoComplete = /** @class */ (function () { + // Constructor + function AutoComplete(params, selector) { + if (params === void 0) { params = {}; } + if (selector === void 0) { selector = "[data-autocomplete]"; } + if (Array.isArray(selector)) { + selector.forEach(function (s) { + new AutoComplete(params, s); + }); + } + else if (typeof selector == "string") { + var elements = document.querySelectorAll(selector); + Array.prototype.forEach.call(elements, function (input) { + new AutoComplete(params, input); + }); + } + else { + var specificParams = AutoComplete.merge(AutoComplete.defaults, params, { + DOMResults: document.createElement("div") + }); + AutoComplete.prototype.create(specificParams, selector); + return specificParams; + } + } + AutoComplete.prototype.create = function (params, element) { + params.Input = element; + if (params.Input.nodeName.match(/^INPUT$/i) && (params.Input.hasAttribute("type") === false || params.Input.getAttribute("type").match(/^TEXT|SEARCH$/i))) { + params.Input.setAttribute("autocomplete", "off"); + params._Position(params); + params.Input.parentNode.appendChild(params.DOMResults); + params.$Listeners = { + blur: params._Blur.bind(params), + destroy: AutoComplete.prototype.destroy.bind(null, params), + focus: params._Focus.bind(params), + keyup: AutoComplete.prototype.event.bind(null, params, EventType.KEYUP), + keydown: AutoComplete.prototype.event.bind(null, params, EventType.KEYDOWN), + position: params._Position.bind(params) + }; + for (var event in params.$Listeners) { + params.Input.addEventListener(event, params.$Listeners[event]); + } + } + }; + AutoComplete.prototype.getEventsByType = function (params, type) { + var mappings = {}; + for (var key in params.KeyboardMappings) { + var event = EventType.KEYUP; + if (params.KeyboardMappings[key].Event !== undefined) { + event = params.KeyboardMappings[key].Event; + } + if (event == type) { + mappings[key] = params.KeyboardMappings[key]; + } + } + return mappings; + }; + AutoComplete.prototype.event = function (params, type, event) { + var eventIdentifier = function (condition) { + if ((match === true && mapping.Operator == ConditionOperator.AND) || (match === false && mapping.Operator == ConditionOperator.OR)) { + condition = AutoComplete.merge({ + Not: false + }, condition); + if (condition.hasOwnProperty("Is")) { + if (condition.Is == event.keyCode) { + match = !condition.Not; + } + else { + match = condition.Not; + } + } + else if (condition.hasOwnProperty("From") && condition.hasOwnProperty("To")) { + if (event.keyCode >= condition.From && event.keyCode <= condition.To) { + match = !condition.Not; + } + else { + match = condition.Not; + } + } + } + }; + for (var name in AutoComplete.prototype.getEventsByType(params, type)) { + var mapping = AutoComplete.merge({ + Operator: ConditionOperator.AND + }, params.KeyboardMappings[name]), match = ConditionOperator.AND == mapping.Operator; + mapping.Conditions.forEach(eventIdentifier); + if (match === true) { + mapping.Callback.call(params, event); + } + } + }; + AutoComplete.prototype.makeRequest = function (params, callback, callbackErr) { + var propertyHttpHeaders = Object.getOwnPropertyNames(params.HttpHeaders), request = new XMLHttpRequest(), method = params._HttpMethod(), url = params._Url(), queryParams = params._Pre(), queryParamsStringify = encodeURIComponent(params._QueryArg()) + "=" + encodeURIComponent(queryParams); + if (method.match(/^GET$/i)) { + if (url.indexOf("?") !== -1) { + url += "&" + queryParamsStringify; + } + else { + url += "?" + queryParamsStringify; + } + } + request.open(method, url, true); + for (var i = propertyHttpHeaders.length - 1; i >= 0; i--) { + request.setRequestHeader(propertyHttpHeaders[i], params.HttpHeaders[propertyHttpHeaders[i]]); + } + request.onreadystatechange = function () { + if (request.readyState == 4 && request.status == 200) { + params.$Cache[queryParams] = request.response; + callback(request.response); + } + else if (request.status >= 400) { + callbackErr(); + } + }; + return request; + }; + AutoComplete.prototype.ajax = function (params, request, timeout) { + if (timeout === void 0) { timeout = true; } + if (params.$AjaxTimer) { + window.clearTimeout(params.$AjaxTimer); + } + if (timeout === true) { + params.$AjaxTimer = window.setTimeout(AutoComplete.prototype.ajax.bind(null, params, request, false), params.Delay); + } + else { + if (params.Request) { + params.Request.abort(); + } + params.Request = request; + params.Request.send(params._QueryArg() + "=" + params._Pre()); + } + }; + AutoComplete.prototype.cache = function (params, callback, callbackErr) { + var response = params._Cache(params._Pre()); + if (response === undefined) { + var request = AutoComplete.prototype.makeRequest(params, callback, callbackErr); + AutoComplete.prototype.ajax(params, request); + } + else { + callback(response); + } + }; + AutoComplete.prototype.destroy = function (params) { + for (var event in params.$Listeners) { + params.Input.removeEventListener(event, params.$Listeners[event]); + } + params.DOMResults.parentNode.removeChild(params.DOMResults); + }; + AutoComplete.merge = function () { + var merge = {}, tmp; + for (var i = 0; i < arguments.length; i++) { + for (tmp in arguments[i]) { + merge[tmp] = arguments[i][tmp]; + } + } + return merge; + }; + AutoComplete.defaults = { + Delay: 150, + EmptyMessage: "No result here", + Highlight: { + getRegex: function (value) { + return new RegExp(value, "ig"); + }, + transform: function (value) { + return "" + value + ""; + } + }, + HttpHeaders: { + "Content-type": "application/x-www-form-urlencoded" + }, + Limit: 0, + MinChars: 0, + HttpMethod: "GET", + QueryArg: "q", + Url: null, + KeyboardMappings: { + "Enter": { + Conditions: [{ + Is: 13, + Not: false + }], + Callback: function (event) { + if (this.DOMResults.getAttribute("class").indexOf("open") != -1) { + var liActive = this.DOMResults.querySelector("li.active"); + if (liActive !== null) { + event.preventDefault(); + this._Select(liActive); + this.DOMResults.setAttribute("class", "autocomplete"); + } + } + }, + Operator: ConditionOperator.AND, + Event: EventType.KEYDOWN + }, + "KeyUpAndDown_down": { + Conditions: [{ + Is: 38, + Not: false + }, + { + Is: 40, + Not: false + }], + Callback: function (event) { + event.preventDefault(); + }, + Operator: ConditionOperator.OR, + Event: EventType.KEYDOWN + }, + "KeyUpAndDown_up": { + Conditions: [{ + Is: 38, + Not: false + }, + { + Is: 40, + Not: false + }], + Callback: function (event) { + event.preventDefault(); + var first = this.DOMResults.querySelector("li:first-child:not(.locked)"), last = this.DOMResults.querySelector("li:last-child:not(.locked)"), active = this.DOMResults.querySelector("li.active"); + if (active) { + var currentIndex = Array.prototype.indexOf.call(active.parentNode.children, active), position = currentIndex + (event.keyCode - 39), lisCount = this.DOMResults.getElementsByTagName("li").length; + if (position < 0) { + position = lisCount - 1; + } + else if (position >= lisCount) { + position = 0; + } + active.classList.remove("active"); + active.parentElement.children.item(position).classList.add("active"); + } + else if (last && event.keyCode == 38) { + last.classList.add("active"); + } + else if (first) { + first.classList.add("active"); + } + }, + Operator: ConditionOperator.OR, + Event: EventType.KEYUP + }, + "AlphaNum": { + Conditions: [{ + Is: 13, + Not: true + }, { + From: 35, + To: 40, + Not: true + }], + Callback: function () { + var oldValue = this.Input.getAttribute("data-autocomplete-old-value"), currentValue = this._Pre(); + if (currentValue !== "" && currentValue.length >= this._MinChars()) { + if (!oldValue || currentValue != oldValue) { + this.DOMResults.setAttribute("class", "autocomplete open"); + } + AutoComplete.prototype.cache(this, function (response) { + this._Render(this._Post(response)); + this._Open(); + }.bind(this), this._Error); + } + else { + this._Close(); + } + }, + Operator: ConditionOperator.AND, + Event: EventType.KEYUP + } + }, + DOMResults: null, + Request: null, + Input: null, + /** + * Return the message when no result returns + */ + _EmptyMessage: function () { + var emptyMessage = ""; + if (this.Input.hasAttribute("data-autocomplete-empty-message")) { + emptyMessage = this.Input.getAttribute("data-autocomplete-empty-message"); + } + else if (this.EmptyMessage !== false) { + emptyMessage = this.EmptyMessage; + } + else { + emptyMessage = ""; + } + return emptyMessage; + }, + /** + * Returns the maximum number of results + */ + _Limit: function () { + var limit = this.Input.getAttribute("data-autocomplete-limit"); + if (isNaN(limit) || limit === null) { + return this.Limit; + } + return parseInt(limit, 10); + }, + /** + * Returns the minimum number of characters entered before firing ajax + */ + _MinChars: function () { + var minchars = this.Input.getAttribute("data-autocomplete-minchars"); + if (isNaN(minchars) || minchars === null) { + return this.MinChars; + } + return parseInt(minchars, 10); + }, + /** + * Apply transformation on labels response + */ + _Highlight: function (label) { + return label.replace(this.Highlight.getRegex(this._Pre()), this.Highlight.transform); + }, + /** + * Returns the HHTP method to use + */ + _HttpMethod: function () { + if (this.Input.hasAttribute("data-autocomplete-method")) { + return this.Input.getAttribute("data-autocomplete-method"); + } + return this.HttpMethod; + }, + /** + * Returns the query param to use + */ + _QueryArg: function () { + if (this.Input.hasAttribute("data-autocomplete-param-name")) { + return this.Input.getAttribute("data-autocomplete-param-name"); + } + return this.QueryArg; + }, + /** + * Returns the URL to use for AJAX request + */ + _Url: function () { + if (this.Input.hasAttribute("data-autocomplete")) { + return this.Input.getAttribute("data-autocomplete"); + } + return this.Url; + }, + /** + * Manage the close + */ + _Blur: function (now) { + if (now === void 0) { now = false; } + if (now) { + this._Close(); + } + else { + var params = this; + setTimeout(function () { + params._Blur(true); + }, 150); + } + }, + /** + * Manage the cache + */ + _Cache: function (value) { + return this.$Cache[value]; + }, + /** + * Manage the open + */ + _Focus: function () { + var oldValue = this.Input.getAttribute("data-autocomplete-old-value"); + if ((!oldValue || this.Input.value != oldValue) && this._MinChars() <= this.Input.value.length) { + this.DOMResults.setAttribute("class", "autocomplete open"); + } + }, + /** + * Bind all results item if one result is opened + */ + _Open: function () { + var params = this; + Array.prototype.forEach.call(this.DOMResults.getElementsByTagName("li"), function (li) { + if (li.getAttribute("class") != "locked") { + li.onclick = function () { + params._Select(li); + }; + } + }); + }, + _Close: function () { + this.DOMResults.setAttribute("class", "autocomplete"); + }, + /** + * Position the results HTML element + */ + _Position: function () { + this.DOMResults.setAttribute("class", "autocomplete"); + this.DOMResults.setAttribute("style", "top:" + (this.Input.offsetTop + this.Input.offsetHeight) + "px;left:" + this.Input.offsetLeft + "px;width:" + this.Input.clientWidth + "px;"); + }, + /** + * Execute the render of results DOM element + */ + _Render: function (response) { + var ul; + if (typeof response == "string") { + ul = this._RenderRaw(response); + } + else { + ul = this._RenderResponseItems(response); + } + if (this.DOMResults.hasChildNodes()) { + this.DOMResults.removeChild(this.DOMResults.childNodes[0]); + } + this.DOMResults.appendChild(ul); + }, + /** + * ResponseItems[] rendering + */ + _RenderResponseItems: function (response) { + var ul = document.createElement("ul"), li = document.createElement("li"), limit = this._Limit(); + // Order + if (limit < 0) { + response = response.reverse(); + } + else if (limit === 0) { + limit = response.length; + } + for (var item = 0; item < Math.min(Math.abs(limit), response.length); item++) { + li.innerHTML = response[item].Label; + li.setAttribute("data-autocomplete-value", response[item].Value); + ul.appendChild(li); + li = document.createElement("li"); + } + return ul; + }, + /** + * string response rendering (RAW HTML) + */ + _RenderRaw: function (response) { + var ul = document.createElement("ul"), li = document.createElement("li"); + if (response.length > 0) { + this.DOMResults.innerHTML = response; + } + else { + var emptyMessage = this._EmptyMessage(); + if (emptyMessage !== "") { + li.innerHTML = emptyMessage; + li.setAttribute("class", "locked"); + ul.appendChild(li); + } + } + return ul; + }, + /** + * Deal with request response + */ + _Post: function (response) { + try { + var returnResponse = []; + //JSON return + var json = JSON.parse(response); + if (Object.keys(json).length === 0) { + return ""; + } + if (Array.isArray(json)) { + for (var i = 0; i < Object.keys(json).length; i++) { + returnResponse[returnResponse.length] = { "Value": json[i], "Label": this._Highlight(json[i]) }; + } + } + else { + for (var value in json) { + returnResponse.push({ + "Value": value, + "Label": this._Highlight(json[value]) + }); + } + } + return returnResponse; + } + catch (event) { + //HTML return + return response; + } + }, + /** + * Return the autocomplete value to send (before request) + */ + _Pre: function () { + return this.Input.value; + }, + /** + * Choice one result item + */ + _Select: function (item) { + if (item.hasAttribute("data-autocomplete-value")) { + this.Input.value = item.getAttribute("data-autocomplete-value"); + } + else { + this.Input.value = item.innerHTML; + } + this.Input.setAttribute("data-autocomplete-old-value", this.Input.value); + }, + /** + * Handle HTTP error on the request + */ + _Error: function () { + }, + $AjaxTimer: null, + $Cache: {}, + $Listeners: {} + }; + return AutoComplete; +}()); +module.exports = AutoComplete; + +},{}]},{},[1])(1) +}); diff --git a/searx/static/themes/simple/js/searxng.min.js b/searx/static/themes/simple/js/searxng.min.js new file mode 100644 index 000000000..c2e27c37c --- /dev/null +++ b/searx/static/themes/simple/js/searxng.min.js @@ -0,0 +1,30 @@ +/** + * @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(t,o){"use strict";if(t.Element){(function(e){e.matches=e.matches||e.matchesSelector||e.webkitMatchesSelector||e.msMatchesSelector||function(e){var t=this,n=(t.parentNode||t.document).querySelectorAll(e),i=-1;while(n[++i]&&n[i]!=t);return!!n[i]}})(Element.prototype)}function a(e,t,n){try{e.call(t,n)}catch(e){console.log(e)}}var s=window.searxng||{};s.on=function(i,e,r,t){t=t||false;if(typeof i!=="string"){i.addEventListener(e,r,t)}else{o.addEventListener(e,function(e){var t=e.target||e.srcElement,n=false;while(t&&t.matches&&t!==o&&!(n=t.matches(i)))t=t.parentElement;if(n)a(r,t,e)},t)}};s.ready=function(e){if(document.readyState!="loading"){e.call(t)}else{t.addEventListener("DOMContentLoaded",e.bind(t))}};s.http=function(e,t){var n=new XMLHttpRequest,i=function(){},r=function(){},o={then:function(e){i=e;return o},catch:function(e){r=e;return o}};try{n.open(e,t,true);n.onload=function(){if(n.status==200){i(n.response,n.responseType)}else{r(Error(n.statusText))}};n.onerror=function(){r(Error("Network Error"))};n.onabort=function(){r(Error("Transaction is aborted"))};n.send()}catch(e){r(e)}return o};s.loadStyle=function(e){var t=s.static_path+e,n="style_"+e.replace(".","_"),i=o.getElementById(n);if(i===null){i=o.createElement("link");i.setAttribute("id",n);i.setAttribute("rel","stylesheet");i.setAttribute("type","text/css");i.setAttribute("href",t);o.body.appendChild(i)}};s.loadScript=function(e,t){var n=s.static_path+e,i="script_"+e.replace(".","_"),r=o.getElementById(i);if(r===null){r=o.createElement("script");r.setAttribute("id",i);r.setAttribute("src",n);r.onload=t;r.onerror=function(){r.setAttribute("error","1")};o.body.appendChild(r)}else if(!r.hasAttribute("error")){try{t.apply(r,[])}catch(e){console.log(e)}}else{console.log("callback not executed : script '"+n+"' not loaded.")}};s.insertBefore=function(e,t){t.parentNode.insertBefore(e,t)};s.insertAfter=function(e,t){t.parentNode.insertAfter(e,t.nextSibling)};s.on(".close","click",function(){this.parentNode.classList.add("invisible")});return s}(window,document);searxng.ready(function(){searxng.on(".result","click",function(){n(this)(true)});searxng.on(".result a","focus",function(e){var t=e.target;while(t!==undefined){if(t.classList.contains("result")){if(t.getAttribute("data-vim-selected")===null){n(t)(true)}break}t=t.parentNode}},true);var d={27:{key:"Escape",fun:t,des:"remove focus from the focused input",cat:"Control"},73:{key:"i",fun:l,des:"focus on the search input",cat:"Control"},66:{key:"b",fun:a(-window.innerHeight),des:"scroll one page up",cat:"Navigation"},70:{key:"f",fun:a(window.innerHeight),des:"scroll one page down",cat:"Navigation"},85:{key:"u",fun:a(-window.innerHeight/2),des:"scroll half a page up",cat:"Navigation"},68:{key:"d",fun:a(window.innerHeight/2),des:"scroll half a page down",cat:"Navigation"},71:{key:"g",fun:s(-document.body.scrollHeight,"top"),des:"scroll to the top of the page",cat:"Navigation"},86:{key:"v",fun:s(document.body.scrollHeight,"bottom"),des:"scroll to the bottom of the page",cat:"Navigation"},75:{key:"k",fun:n("up"),des:"select previous search result",cat:"Results"},74:{key:"j",fun:n("down"),des:"select next search result",cat:"Results"},80:{key:"p",fun:o(),des:"go to previous page",cat:"Results"},78:{key:"n",fun:r(),des:"go to next page",cat:"Results"},79:{key:"o",fun:u(false),des:"open search result",cat:"Results"},84:{key:"t",fun:u(true),des:"open the result in a new tab",cat:"Results"},82:{key:"r",fun:e,des:"reload page from the server",cat:"Control"},72:{key:"h",fun:p,des:"toggle help window",cat:"Other"}};searxng.on(document,"keydown",function(e){if(Object.prototype.hasOwnProperty.call(d,e.keyCode)&&!e.ctrlKey&&!e.altKey&&!e.shiftKey&&!e.metaKey){var t=e.target.tagName.toLowerCase();if(e.keyCode===27){if(t==="input"||t==="select"||t==="textarea"){d[e.keyCode].fun()}}else{if(e.target===document.body||t==="a"||t==="button"){e.preventDefault();d[e.keyCode].fun()}}}});function n(d){return function(e){var t=document.querySelector(".result[data-vim-selected]"),n=d;if(t===null){t=document.querySelector(".result");if(t===null){return}if(d==="down"||d==="up"){n=t}}var i,r=document.querySelectorAll(".result");if(typeof n!=="string"){i=n}else{switch(n){case"visible":var o=document.documentElement.scrollTop||document.body.scrollTop;var a=o+document.documentElement.clientHeight;for(var s=0;so){break}}break;case"down":i=t.nextElementSibling;if(i===null){i=r[0]}break;case"up":i=t.previousElementSibling;if(i===null){i=r[r.length-1]}break;case"bottom":i=r[r.length-1];break;case"top":default:i=r[0]}}if(i){t.removeAttribute("data-vim-selected");i.setAttribute("data-vim-selected","true");var c=i.querySelector("h3 a")||i.querySelector("a");if(c!==null){c.focus()}if(!e){f()}}}}function e(){document.location.reload(true)}function t(){if(document.activeElement){document.activeElement.blur()}}function i(t){return function(){var e=document.querySelector(t);if(e){e.click()}}}function r(){return i('nav#pagination .next_page button[type="submit"]')}function o(){return i('nav#pagination .previous_page button[type="submit"]')}function f(){var e=document.querySelector(".result[data-vim-selected]");if(e===null){return}var t=document.documentElement.scrollTop||document.body.scrollTop,n=document.documentElement.clientHeight,i=e.offsetTop,r=i+e.clientHeight,o=120;if(e.previousElementSibling===null&&ri-o){window.scroll(window.scrollX,i-o)}else{var a=t+n;if(a"}o+="";o+="

"+s[0].cat+"

";o+='
    ';for(var c in s){o+="
  • "+s[c].key+" "+s[c].des+"
  • "}o+="
";o+="";if(!u||l){o+=""}}o+="";e.innerHTML=o}function p(){var e=document.querySelector("#vim-hotkeys-help");console.log(e);if(e===undefined||e===null){e=document.createElement("div");e.id="vim-hotkeys-help";e.className="dialog-modal";e.style="width: 40%";c(e);c(e);c(e);var t=document.getElementsByTagName("body")[0];t.appendChild(e)}else{e.classList.toggle("invisible");return}}});(function(e,t,n){"use strict";n.ready(function(){n.on(".searxng_init_map","click",function(e){this.classList.remove("searxng_init_map");var d=this.dataset.leafletTarget;var f=parseFloat(this.dataset.mapLon);var p=parseFloat(this.dataset.mapLat);var h=parseFloat(this.dataset.mapZoom);var m=JSON.parse(this.dataset.mapBoundingbox);var g=JSON.parse(this.dataset.mapGeojson);n.loadStyle("css/leaflet.css");n.loadScript("js/leaflet.js",function(){var e=null;if(m){var t=L.latLng(m[0],m[2]);var n=L.latLng(m[1],m[3]);e=L.latLngBounds(t,n)}var i=L.map(d);var r="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png";var o='Map data © OpenStreetMap contributors';var a=new L.TileLayer(r,{minZoom:1,maxZoom:19,attribution:o});var s="https://maps.wikimedia.org/osm-intl/{z}/{x}/{y}.png";var l='Wikimedia maps | Maps data © OpenStreetMap contributors';var u=new L.TileLayer(s,{minZoom:1,maxZoom:19,attribution:l});if(e){setTimeout(function(){i.fitBounds(e,{maxZoom:17})},0)}else if(f&&p){if(h){i.setView(new L.latLng(p,f),h)}else{i.setView(new L.latLng(p,f),8)}}i.addLayer(a);var c={"OSM Mapnik":a,"OSM Wikimedia":u};L.control.layers(c).addTo(i);if(g){L.geoJson(g).addTo(i)}});e.preventDefault()})})})(window,document,window.searxng);(function(e,o,a){"use strict";a.ready(function(){let r=null;function e(){if(r==null){a.http("GET","engine_descriptions.json").then(function(e){r=JSON.parse(e);for(const[t,n]of Object.entries(r)){let e=o.querySelectorAll('[data-engine-name="'+t+'"] .engine-description');for(const i of e){let e=" ("+a.translations["Source"]+": "+n[1]+")";i.innerHTML=n[0]+e}}})}}if(o.querySelector('body[class="preferences_endpoint"]')){for(const t of o.querySelectorAll("[data-engine-name]")){a.on(t,"mouseenter",e)}}})})(window,document,window.searxng);(function(e,o,t){"use strict";t.ready(function(){t.image_thumbnail_layout=new t.ImageLayout("#urls","#urls .result-images","img.image_thumbnail",10,200);t.image_thumbnail_layout.watch();t.on(".btn-collapse","click",function(){var e=this.getAttribute("data-btn-text-collapsed");var t=this.getAttribute("data-btn-text-not-collapsed");var n=this.getAttribute("data-target");var i=o.querySelector(n);var r=this.innerHTML;if(this.classList.contains("collapsed")){r=r.replace(e,t)}else{r=r.replace(t,e)}this.innerHTML=r;this.classList.toggle("collapsed");i.classList.toggle("invisible")});t.on(".media-loader","click",function(){var e=this.getAttribute("data-target");var t=o.querySelector(e+" > iframe");var n=t.getAttribute("src");if(n===null||n===undefined||n===false){t.setAttribute("src",t.getAttribute("data-src"))}});e.addEventListener("scroll",function(){var e=o.getElementById("backToTop"),t=document.documentElement.scrollTop||document.body.scrollTop;if(e!==null){if(t>=200){e.style.opacity=1}else{e.style.opacity=0}}})})})(window,document,window.searxng);(function(t,n,i){"use strict";var r=true,o="q",a;function s(e){if(e.setSelectionRange){var t=e.value.length;e.setSelectionRange(t,t)}}function l(){if(a.value.length>0){var e=document.getElementById("search");setTimeout(e.submit.bind(e),0)}}function u(e){var t=document.getElementById("clear_search");var n=function(){if(e.value.length===0){t.classList.add("empty")}else{t.classList.remove("empty")}};n();t.addEventListener("click",function(){e.value="";e.focus();n()});e.addEventListener("keyup",n,false)}i.ready(function(){a=n.getElementById(o);function e(){if(r){s(a);r=false}else{}}if(a!==null){u(a);if(i.autocompleter){i.autocomplete=AutoComplete.call(t,{Url:"./autocompleter",EmptyMessage:i.translations.no_item_found,HttpMethod:i.method,HttpHeaders:{"Content-type":"application/x-www-form-urlencoded","X-Requested-With":"XMLHttpRequest"},MinChars:4,Delay:300},"#"+o);t.addEventListener("resize",function(){var e=new CustomEvent("position");a.dispatchEvent(e)})}a.addEventListener("focus",e,false);a.focus()}if(a!==null&&n.querySelector(".help")!=null&&i.search_on_category_select){n.querySelector(".help").className="invisible";i.on("#categories input","change",function(){var e,t=n.querySelectorAll('#categories input[type="checkbox"]');for(e=0;e0&&i.naturalHeight>0){r+=i.naturalWidth/i.naturalHeight}else{r+=1}}return(t-e.length*this.margin)/r};e.prototype._setSize=function(e,t){var n,i,r;var o=e.length,a;for(n=0;n0&&i.naturalHeight>0){r=t*i.naturalWidth/i.naturalHeight}else{r=t}i.style.width=r+"px";i.style.height=t+"px";i.style.marginLeft="3px";i.style.marginTop="3px";i.style.marginRight=this.margin-7+"px";i.style.marginBottom=this.margin-7+"px";a=i.parentNode.parentNode;if(!a.classList.contains("js")){a.classList.add("js")}}};e.prototype._alignImgs=function(e){var t,n,i,r;var o=c.querySelector(this.container_selector);var a=window.getComputedStyle(o);var s=parseInt(a.getPropertyValue("padding-left"),10);var l=parseInt(a.getPropertyValue("padding-right"),10);var u=o.clientWidth-s-l;while(e.length>0){t=true;for(i=1;i<=e.length&&t;i++){n=e.slice(0,i);r=this._getHeigth(n,u);if(r0){this._alignImgs(o);o=[]}o.push(r.querySelector(this.img_selector));i=r}if(o.length>0){this._alignImgs(o)}};e.prototype.watch=function(){var e,t;var n=this;var i=c.querySelectorAll(this.results_selector);var r=i.length;function o(){if(n.isAlignDone){n.isAlignDone=false;setTimeout(function(){n.align();n.isAlignDone=true},100)}}a.addEventListener("pageshow",o);a.addEventListener("load",o);a.addEventListener("resize",o);for(e=0;e=e.From&&n.keyCode<=e.To){a=!e.Not}else{a=e.Not}}}};for(var r in s.prototype.getEventsByType(e,t)){var o=s.merge({Operator:l.AND},e.KeyboardMappings[r]),a=l.AND==o.Operator;o.Conditions.forEach(i);if(a===true){o.Callback.call(e,n)}}};s.prototype.makeRequest=function(e,t,n){var i=Object.getOwnPropertyNames(e.HttpHeaders),r=new XMLHttpRequest,o=e._HttpMethod(),a=e._Url(),s=e._Pre(),l=encodeURIComponent(e._QueryArg())+"="+encodeURIComponent(s);if(o.match(/^GET$/i)){if(a.indexOf("?")!==-1){a+="&"+l}else{a+="?"+l}}r.open(o,a,true);for(var u=i.length-1;u>=0;u--){r.setRequestHeader(i[u],e.HttpHeaders[i[u]])}r.onreadystatechange=function(){if(r.readyState==4&&r.status==200){e.$Cache[s]=r.response;t(r.response)}else if(r.status>=400){n()}};return r};s.prototype.ajax=function(e,t,n){if(n===void 0){n=true}if(e.$AjaxTimer){window.clearTimeout(e.$AjaxTimer)}if(n===true){e.$AjaxTimer=window.setTimeout(s.prototype.ajax.bind(null,e,t,false),e.Delay)}else{if(e.Request){e.Request.abort()}e.Request=t;e.Request.send(e._QueryArg()+"="+e._Pre())}};s.prototype.cache=function(e,t,n){var i=e._Cache(e._Pre());if(i===undefined){var r=s.prototype.makeRequest(e,t,n);s.prototype.ajax(e,r)}else{t(i)}};s.prototype.destroy=function(e){for(var t in e.$Listeners){e.Input.removeEventListener(t,e.$Listeners[t])}e.DOMResults.parentNode.removeChild(e.DOMResults)};s.merge=function(){var e={},t;for(var n=0;n"+e+""}},HttpHeaders:{"Content-type":"application/x-www-form-urlencoded"},Limit:0,MinChars:0,HttpMethod:"GET",QueryArg:"q",Url:null,KeyboardMappings:{Enter:{Conditions:[{Is:13,Not:false}],Callback:function(e){if(this.DOMResults.getAttribute("class").indexOf("open")!=-1){var t=this.DOMResults.querySelector("li.active");if(t!==null){e.preventDefault();this._Select(t);this.DOMResults.setAttribute("class","autocomplete")}}},Operator:l.AND,Event:o.KEYDOWN},KeyUpAndDown_down:{Conditions:[{Is:38,Not:false},{Is:40,Not:false}],Callback:function(e){e.preventDefault()},Operator:l.OR,Event:o.KEYDOWN},KeyUpAndDown_up:{Conditions:[{Is:38,Not:false},{Is:40,Not:false}],Callback:function(e){e.preventDefault();var t=this.DOMResults.querySelector("li:first-child:not(.locked)"),n=this.DOMResults.querySelector("li:last-child:not(.locked)"),i=this.DOMResults.querySelector("li.active");if(i){var r=Array.prototype.indexOf.call(i.parentNode.children,i),o=r+(e.keyCode-39),a=this.DOMResults.getElementsByTagName("li").length;if(o<0){o=a-1}else if(o>=a){o=0}i.classList.remove("active");i.parentElement.children.item(o).classList.add("active")}else if(n&&e.keyCode==38){n.classList.add("active")}else if(t){t.classList.add("active")}},Operator:l.OR,Event:o.KEYUP},AlphaNum:{Conditions:[{Is:13,Not:true},{From:35,To:40,Not:true}],Callback:function(){var e=this.Input.getAttribute("data-autocomplete-old-value"),t=this._Pre();if(t!==""&&t.length>=this._MinChars()){if(!e||t!=e){this.DOMResults.setAttribute("class","autocomplete open")}s.prototype.cache(this,function(e){this._Render(this._Post(e));this._Open()}.bind(this),this._Error)}else{this._Close()}},Operator:l.AND,Event:o.KEYUP}},DOMResults:null,Request:null,Input:null,_EmptyMessage:function(){var e="";if(this.Input.hasAttribute("data-autocomplete-empty-message")){e=this.Input.getAttribute("data-autocomplete-empty-message")}else if(this.EmptyMessage!==false){e=this.EmptyMessage}else{e=""}return e},_Limit:function(){var e=this.Input.getAttribute("data-autocomplete-limit");if(isNaN(e)||e===null){return this.Limit}return parseInt(e,10)},_MinChars:function(){var e=this.Input.getAttribute("data-autocomplete-minchars");if(isNaN(e)||e===null){return this.MinChars}return parseInt(e,10)},_Highlight:function(e){return e.replace(this.Highlight.getRegex(this._Pre()),this.Highlight.transform)},_HttpMethod:function(){if(this.Input.hasAttribute("data-autocomplete-method")){return this.Input.getAttribute("data-autocomplete-method")}return this.HttpMethod},_QueryArg:function(){if(this.Input.hasAttribute("data-autocomplete-param-name")){return this.Input.getAttribute("data-autocomplete-param-name")}return this.QueryArg},_Url:function(){if(this.Input.hasAttribute("data-autocomplete")){return this.Input.getAttribute("data-autocomplete")}return this.Url},_Blur:function(e){if(e===void 0){e=false}if(e){this._Close()}else{var t=this;setTimeout(function(){t._Blur(true)},150)}},_Cache:function(e){return this.$Cache[e]},_Focus:function(){var e=this.Input.getAttribute("data-autocomplete-old-value");if((!e||this.Input.value!=e)&&this._MinChars()<=this.Input.value.length){this.DOMResults.setAttribute("class","autocomplete open")}},_Open:function(){var t=this;Array.prototype.forEach.call(this.DOMResults.getElementsByTagName("li"),function(e){if(e.getAttribute("class")!="locked"){e.onclick=function(){t._Select(e)}}})},_Close:function(){this.DOMResults.setAttribute("class","autocomplete")},_Position:function(){this.DOMResults.setAttribute("class","autocomplete");this.DOMResults.setAttribute("style","top:"+(this.Input.offsetTop+this.Input.offsetHeight)+"px;left:"+this.Input.offsetLeft+"px;width:"+this.Input.clientWidth+"px;")},_Render:function(e){var t;if(typeof e=="string"){t=this._RenderRaw(e)}else{t=this._RenderResponseItems(e)}if(this.DOMResults.hasChildNodes()){this.DOMResults.removeChild(this.DOMResults.childNodes[0])}this.DOMResults.appendChild(t)},_RenderResponseItems:function(e){var t=document.createElement("ul"),n=document.createElement("li"),i=this._Limit();if(i<0){e=e.reverse()}else if(i===0){i=e.length}for(var r=0;r0){this.DOMResults.innerHTML=e}else{var i=this._EmptyMessage();if(i!==""){n.innerHTML=i;n.setAttribute("class","locked");t.appendChild(n)}}return t},_Post:function(t){try{var e=[];var n=JSON.parse(t);if(Object.keys(n).length===0){return""}if(Array.isArray(n)){for(var i=0;i