From 4798acc6615efada91c8fb29083a521daf5e1e27 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Tue, 30 Nov 2021 12:43:18 +0100 Subject: [PATCH] [build] /static --- searx/static/themes/oscar/js/searxng.js | 23 ++++++++++++++++++ searx/static/themes/oscar/js/searxng.min.js | 12 ++++++++- .../static/themes/oscar/js/searxng.min.js.map | 2 +- .../themes/simple/img/img_load_error.svg | Bin 0 -> 5030 bytes searx/static/themes/simple/js/searxng.head.js | 4 +++ .../themes/simple/js/searxng.head.min.js | 2 +- .../themes/simple/js/searxng.head.min.js.map | 2 +- searx/static/themes/simple/js/searxng.js | 23 ++++++++++++++++++ searx/static/themes/simple/js/searxng.min.js | 16 +++++++++--- .../themes/simple/js/searxng.min.js.map | 2 +- 10 files changed, 78 insertions(+), 8 deletions(-) create mode 100644 searx/static/themes/simple/img/img_load_error.svg diff --git a/searx/static/themes/oscar/js/searxng.js b/searx/static/themes/oscar/js/searxng.js index 1bbf75ed9..d3aef35e3 100644 --- a/searx/static/themes/oscar/js/searxng.js +++ b/searx/static/themes/oscar/js/searxng.js @@ -327,8 +327,19 @@ $(document).ready(function(){ * * @license Free to use under the MIT License. * +* @example Example usage of searxng.ImageLayout class. +* searxng.image_thumbnail_layout = new searxng.ImageLayout( +* '#urls', // container_selector +* '#urls .result-images', // results_selector +* 'img.image_thumbnail', // img_selector +* 14, // verticalMargin +* 6, // horizontalMargin +* 200 // maxHeight +* ); +* searxng.image_thumbnail_layout.watch(); */ + (function (w, d) { function ImageLayout(container_selector, results_selector, img_selector, verticalMargin, horizontalMargin, maxHeight) { this.container_selector = container_selector; @@ -455,6 +466,11 @@ $(document).ready(function(){ var results_nodes = d.querySelectorAll(this.results_selector); var results_length = results_nodes.length; + function img_load_error(event) { + // console.log("ERROR can't load: " + event.originalTarget.src); + event.originalTarget.src = w.searxng.static_path + w.searxng.theme.img_load_error; + } + function throttleAlign() { if (obj.isAlignDone) { obj.isAlignDone = false; @@ -465,15 +481,22 @@ $(document).ready(function(){ } } + // https://developer.mozilla.org/en-US/docs/Web/API/Window/pageshow_event w.addEventListener('pageshow', throttleAlign); + // https://developer.mozilla.org/en-US/docs/Web/API/FileReader/load_event w.addEventListener('load', throttleAlign); + // https://developer.mozilla.org/en-US/docs/Web/API/Window/resize_event 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); + // https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror img.addEventListener('error', throttleAlign); + if (w.searxng.theme.img_load_error) { + img.addEventListener('error', img_load_error, {once: true}); + } } } }; diff --git a/searx/static/themes/oscar/js/searxng.min.js b/searx/static/themes/oscar/js/searxng.min.js index cc61d1c29..9da3a8b75 100644 --- a/searx/static/themes/oscar/js/searxng.min.js +++ b/searx/static/themes/oscar/js/searxng.min.js @@ -60,6 +60,16 @@ $(document).ready(function(){$("#allow-all-engines").click(function(){$(".onoffs * * @license Free to use under the MIT License. * +* @example Example usage of searxng.ImageLayout class. +* searxng.image_thumbnail_layout = new searxng.ImageLayout( +* '#urls', // container_selector +* '#urls .result-images', // results_selector +* 'img.image_thumbnail', // img_selector +* 14, // verticalMargin +* 6, // horizontalMargin +* 200 // maxHeight +* ); +* searxng.image_thumbnail_layout.watch(); */ -function(o,c){function t(t,e,a,n,i,s){this.container_selector=t,this.results_selector=e,this.img_selector=a,this.verticalMargin=n,this.horizontalMargin=i,this.maxHeight=s,this.isAlignDone=!0}t.prototype._getHeigth=function(t,e){for(var a,n=0,i=0;i`WON+ zg6HDI#V_>#GjQSL!qPwGas2DKCAwn7u5x~{?9sOG)qN3-$BM>t{YyY}Cm-^@bylVtv3>Y0g0{8*&7cKw9ivZcFf46fU z2Nr%Z7npH8@jpR;3s8W8<6#%B&Kv)ya}EO*eo#R0qV&0cJmn&O4#0nf{x6GH8;8TE z;BY`;3V)&J;=s57ao`mOyD)G;IlpmW4*v?B>*LSo_k}-??~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TY(Ug;$f!t&F+ao3iuq?=POAnc65D1(c!1I_{l{$>-X MDQPJd%UcBg58MJ;vH$=8 literal 0 HcmV?d00001 diff --git a/searx/static/themes/simple/js/searxng.head.js b/searx/static/themes/simple/js/searxng.head.js index 21b1754bf..dab0e368a 100644 --- a/searx/static/themes/simple/js/searxng.head.js +++ b/searx/static/themes/simple/js/searxng.head.js @@ -24,6 +24,10 @@ hotkeys: script.getAttribute('data-hotkeys') === 'true', static_path: script.getAttribute('data-static-path'), translations: JSON.parse(script.getAttribute('data-translations')), + theme : { + // image that is displayed if load of failed + img_load_error: 'img/img_load_error.svg' + } }; // update the css diff --git a/searx/static/themes/simple/js/searxng.head.min.js b/searx/static/themes/simple/js/searxng.head.min.js index f42fcbe77..9ccc8d1fd 100644 --- a/searx/static/themes/simple/js/searxng.head.min.js +++ b/searx/static/themes/simple/js/searxng.head.min.js @@ -4,5 +4,5 @@ * (C) Copyright Contributors to the searx project (2014 - 2021). * SPDX-License-Identifier: AGPL-3.0-or-later */ -(function(t,e){"use strict";var a=e.currentScript||function(){var t=e.getElementsByTagName("script");return t[t.length-1]}();t.searxng={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",hotkeys:a.getAttribute("data-hotkeys")==="true",static_path:a.getAttribute("data-static-path"),translations:JSON.parse(a.getAttribute("data-translations"))};var r=e.getElementsByTagName("html")[0];r.classList.remove("no-js");r.classList.add("js");if(t.searxng.touch){r.classList.add("touch")}})(window,document); +(function(t,e){"use strict";var a=e.currentScript||function(){var t=e.getElementsByTagName("script");return t[t.length-1]}();t.searxng={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",hotkeys:a.getAttribute("data-hotkeys")==="true",static_path:a.getAttribute("data-static-path"),translations:JSON.parse(a.getAttribute("data-translations")),theme:{img_load_error:"img/img_load_error.svg"}};var r=e.getElementsByTagName("html")[0];r.classList.remove("no-js");r.classList.add("js");if(t.searxng.touch){r.classList.add("touch")}})(window,document); //# sourceMappingURL=searxng.head.min.js.map \ No newline at end of file diff --git a/searx/static/themes/simple/js/searxng.head.min.js.map b/searx/static/themes/simple/js/searxng.head.min.js.map index 5c841a70d..92faff1d6 100644 --- a/searx/static/themes/simple/js/searxng.head.min.js.map +++ b/searx/static/themes/simple/js/searxng.head.min.js.map @@ -1 +1 @@ -{"version":3,"file":"searxng.head.min.js","sources":["searxng.head.js"],"names":["w","d","script","currentScript","scripts","getElementsByTagName","length","searxng","touch","DocumentTouch","document","method","getAttribute","autocompleter","search_on_category_select","infinite_scroll","hotkeys","static_path","translations","JSON","parse","hmtlElement","classList","remove","add","window"],"mappings":";;;;;;CAOA,SAAUA,EAAGC,gBAIT,IAAIC,EAASD,EAAEE,eAAkB,WAC7B,IAAIC,EAAUH,EAAEI,qBAAqB,UACrC,OAAOD,EAAQA,EAAQE,OAAS,GAFH,GAMjCN,EAAEO,QAAU,CACRC,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,QAASd,EAAOU,aAAa,kBAAoB,OACjDK,YAAaf,EAAOU,aAAa,oBACjCM,aAAcC,KAAKC,MAAMlB,EAAOU,aAAa,uBAIjD,IAAIS,EAAcpB,EAAEI,qBAAqB,QAAQ,GACjDgB,EAAYC,UAAUC,OAAO,SAC7BF,EAAYC,UAAUE,IAAI,MAC1B,GAAIxB,EAAEO,QAAQC,MAAO,CACjBa,EAAYC,UAAUE,IAAI,WA1BlC,CA4BGC,OAAQf"} \ No newline at end of file +{"version":3,"file":"searxng.head.min.js","sources":["searxng.head.js"],"names":["w","d","script","currentScript","scripts","getElementsByTagName","length","searxng","touch","DocumentTouch","document","method","getAttribute","autocompleter","search_on_category_select","infinite_scroll","hotkeys","static_path","translations","JSON","parse","theme","img_load_error","hmtlElement","classList","remove","add","window"],"mappings":";;;;;;CAOA,SAAUA,EAAGC,gBAIT,IAAIC,EAASD,EAAEE,eAAkB,WAC7B,IAAIC,EAAUH,EAAEI,qBAAqB,UACrC,OAAOD,EAAQA,EAAQE,OAAS,GAFH,GAMjCN,EAAEO,QAAU,CACRC,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,QAASd,EAAOU,aAAa,kBAAoB,OACjDK,YAAaf,EAAOU,aAAa,oBACjCM,aAAcC,KAAKC,MAAMlB,EAAOU,aAAa,sBAC7CS,MAAQ,CAEJC,eAAgB,2BAKxB,IAAIC,EAActB,EAAEI,qBAAqB,QAAQ,GACjDkB,EAAYC,UAAUC,OAAO,SAC7BF,EAAYC,UAAUE,IAAI,MAC1B,GAAI1B,EAAEO,QAAQC,MAAO,CACjBe,EAAYC,UAAUE,IAAI,WA9BlC,CAgCGC,OAAQjB"} \ No newline at end of file diff --git a/searx/static/themes/simple/js/searxng.js b/searx/static/themes/simple/js/searxng.js index 830c21d61..c84227541 100644 --- a/searx/static/themes/simple/js/searxng.js +++ b/searx/static/themes/simple/js/searxng.js @@ -879,8 +879,19 @@ searxng.ready(function() { * * @license Free to use under the MIT License. * +* @example Example usage of searxng.ImageLayout class. +* searxng.image_thumbnail_layout = new searxng.ImageLayout( +* '#urls', // container_selector +* '#urls .result-images', // results_selector +* 'img.image_thumbnail', // img_selector +* 14, // verticalMargin +* 6, // horizontalMargin +* 200 // maxHeight +* ); +* searxng.image_thumbnail_layout.watch(); */ + (function (w, d) { function ImageLayout(container_selector, results_selector, img_selector, verticalMargin, horizontalMargin, maxHeight) { this.container_selector = container_selector; @@ -1007,6 +1018,11 @@ searxng.ready(function() { var results_nodes = d.querySelectorAll(this.results_selector); var results_length = results_nodes.length; + function img_load_error(event) { + // console.log("ERROR can't load: " + event.originalTarget.src); + event.originalTarget.src = w.searxng.static_path + w.searxng.theme.img_load_error; + } + function throttleAlign() { if (obj.isAlignDone) { obj.isAlignDone = false; @@ -1017,15 +1033,22 @@ searxng.ready(function() { } } + // https://developer.mozilla.org/en-US/docs/Web/API/Window/pageshow_event w.addEventListener('pageshow', throttleAlign); + // https://developer.mozilla.org/en-US/docs/Web/API/FileReader/load_event w.addEventListener('load', throttleAlign); + // https://developer.mozilla.org/en-US/docs/Web/API/Window/resize_event 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); + // https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror img.addEventListener('error', throttleAlign); + if (w.searxng.theme.img_load_error) { + img.addEventListener('error', img_load_error, {once: true}); + } } } }; diff --git a/searx/static/themes/simple/js/searxng.min.js b/searx/static/themes/simple/js/searxng.min.js index eafe89618..c88e39c65 100644 --- a/searx/static/themes/simple/js/searxng.min.js +++ b/searx/static/themes/simple/js/searxng.min.js @@ -4,7 +4,7 @@ * (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(){function e(e){while(e!==undefined){if(e.classList.contains("detail")){return true}if(e.classList.contains("result")){return false}e=e.parentNode}return false}function n(e){while(e!==undefined){if(e.classList.contains("result")){return e}e=e.parentNode}return undefined}function i(e){return e&&e.classList.contains("result-images")}searxng.on(".result","click",function(t){if(!e(t.target)){r(this)(true);let e=n(t.target);if(i(e)){t.preventDefault();searxng.selectImage(e)}}});searxng.on(".result a","focus",function(t){if(!e(t.target)){let e=n(t.target);if(e&&e.getAttribute("data-vim-selected")===null){r(e)(true)}if(i(e)){searxng.selectImage(e)}}},true);var d={27:{key:"Escape",fun:o,des:"remove focus from the focused input",cat:"Control"},73:{key:"i",fun:p,des:"focus on the search input",cat:"Control"},66:{key:"b",fun:u(-window.innerHeight),des:"scroll one page up",cat:"Navigation"},70:{key:"f",fun:u(window.innerHeight),des:"scroll one page down",cat:"Navigation"},85:{key:"u",fun:u(-window.innerHeight/2),des:"scroll half a page up",cat:"Navigation"},68:{key:"d",fun:u(window.innerHeight/2),des:"scroll half a page down",cat:"Navigation"},71:{key:"g",fun:c(-document.body.scrollHeight,"top"),des:"scroll to the top of the page",cat:"Navigation"},86:{key:"v",fun:c(document.body.scrollHeight,"bottom"),des:"scroll to the bottom of the page",cat:"Navigation"},75:{key:"k",fun:r("up"),des:"select previous search result",cat:"Results"},74:{key:"j",fun:r("down"),des:"select next search result",cat:"Results"},80:{key:"p",fun:l(),des:"go to previous page",cat:"Results"},78:{key:"n",fun:s(),des:"go to next page",cat:"Results"},79:{key:"o",fun:h(false),des:"open search result",cat:"Results"},84:{key:"t",fun:h(true),des:"open the result in a new tab",cat:"Results"},82:{key:"r",fun:t,des:"reload page from the server",cat:"Control"},72:{key:"h",fun:m,des:"toggle help window",cat:"Other"}};if(searxng.hotkeys){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){d[e.keyCode].fun(e)}else{if(e.target===document.body||t==="a"||t==="button"){e.preventDefault();d[e.keyCode].fun()}}}})}function r(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 t(){document.location.reload(true)}function o(e){const t=e.target.tagName.toLowerCase();if(document.activeElement&&(t==="input"||t==="select"||t==="textarea")){document.activeElement.blur()}else{searxng.closeDetail()}}function a(t){return function(){var e=document.querySelector(t);if(e){e.click()}}}function s(){return a('nav#pagination .next_page button[type="submit"]')}function l(){return a('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 a")}if(e!==null){var t=e.getAttribute("href");if(n){window.open(t)}else{window.location.href=t}}}}function g(e){var n={};for(var t in d){var i=d[t];n[i.cat]=n[i.cat]||[];n[i.cat].push(i)}var r=Object.keys(n).sort(function(e,t){return n[t].length-n[e].length});if(r.length===0){return}var o='×';o+="

How to navigate searx with Vim-like hotkeys

";o+="";for(var a=0;a"}o+="";if(!u||l){o+=""}}o+="
";o+="

"+s[0].cat+"

";o+='
    ';for(var c in s){o+="
  • "+s[c].key+" "+s[c].des+"
  • "}o+="
";o+="
";e.innerHTML=o}function m(){var e=document.querySelector("#vim-hotkeys-help");if(e===undefined||e===null){e=document.createElement("div");e.id="vim-hotkeys-help";e.className="dialog-modal";g(e);g(e);g(e);var t=document.getElementsByTagName("body")[0];t.appendChild(e)}else{e.classList.toggle("invisible");return}}searxng.scrollPageToSelected=f;searxng.selectNext=r("down");searxng.selectPrevious=r("up")});(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 g=JSON.parse(this.dataset.mapBoundingbox);var m=JSON.parse(this.dataset.mapGeojson);n.loadStyle("css/leaflet.css");n.loadScript("js/leaflet.js",function(){var e=null;if(g){var t=L.latLng(g[0],g[2]);var n=L.latLng(g[1],g[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(m){L.geoJson(m).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,s,l){"use strict";l.ready(function(){l.image_thumbnail_layout=new l.ImageLayout("#urls","#urls .result-images","img.image_thumbnail",14,6,200);l.image_thumbnail_layout.watch();l.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=s.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")});l.on(".media-loader","click",function(){var e=this.getAttribute("data-target");var t=s.querySelector(e+" > iframe");var n=t.getAttribute("src");if(n===null||n===undefined||n===false){t.setAttribute("src",t.getAttribute("data-src"))}});l.selectImage=function(e){if(e){const t=e.querySelector(".result-images-source img");const n=e.querySelector(".image_thumbnail");const i=e.querySelector(".detail");if(t){const r=t.getAttribute("data-src");if(r){const o=s.createElement("div");const a=new Image;o.classList.add("loader");i.appendChild(o);a.onload=e=>{t.src=r;o.remove()};a.onerror=e=>{o.remove()};a.src=r;t.src=n.src;t.removeAttribute("data-src")}}}s.getElementById("results").classList.add("image-detail-open");l.image_thumbnail_layout.align();l.scrollPageToSelected()};l.closeDetail=function(e){s.getElementById("results").classList.remove("image-detail-open");l.image_thumbnail_layout.align();l.scrollPageToSelected()};l.on(".result-detail-close","click",e=>{e.preventDefault();l.closeDetail()});l.on(".result-detail-previous","click",e=>l.selectPrevious(false));l.on(".result-detail-next","click",e=>l.selectNext(false));e.addEventListener("scroll",function(){var e=s.getElementById("backToTop"),t=document.documentElement.scrollTop||document.body.scrollTop,n=s.getElementById("results");if(e!==null){if(t>=100){n.classList.add("scrolling")}else{n.classList.remove("scrolling")}}},true)})})(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;eo){break}}break;case"down":r=t.nextElementSibling;if(r===null){r=i[0]}break;case"up":r=t.previousElementSibling;if(r===null){r=i[i.length-1]}break;case"bottom":r=i[i.length-1];break;case"top":default:r=i[0]}}if(r){t.removeAttribute("data-vim-selected");r.setAttribute("data-vim-selected","true");var c=r.querySelector("h3 a")||r.querySelector("a");if(c!==null){c.focus()}if(!e){f()}}}}function t(){document.location.reload(true)}function o(e){const t=e.target.tagName.toLowerCase();if(document.activeElement&&(t==="input"||t==="select"||t==="textarea")){document.activeElement.blur()}else{searxng.closeDetail()}}function a(t){return function(){var e=document.querySelector(t);if(e){e.click()}}}function s(){return a('nav#pagination .next_page button[type="submit"]')}function l(){return a('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,r=e.offsetTop,i=r+e.clientHeight,o=120;if(e.previousElementSibling===null&&ir-o){window.scroll(window.scrollX,r-o)}else{var a=t+n;if(a a")}if(e!==null){var t=e.getAttribute("href");if(n){window.open(t)}else{window.location.href=t}}}}function g(e){var n={};for(var t in d){var r=d[t];n[r.cat]=n[r.cat]||[];n[r.cat].push(r)}var i=Object.keys(n).sort(function(e,t){return n[t].length-n[e].length});if(i.length===0){return}var o='×';o+="

How to navigate searx with Vim-like hotkeys

";o+="";for(var a=0;a"}o+="";if(!u||l){o+=""}}o+="
";o+="

"+s[0].cat+"

";o+='
    ';for(var c in s){o+="
  • "+s[c].key+" "+s[c].des+"
  • "}o+="
";o+="
";e.innerHTML=o}function m(){var e=document.querySelector("#vim-hotkeys-help");if(e===undefined||e===null){e=document.createElement("div");e.id="vim-hotkeys-help";e.className="dialog-modal";g(e);g(e);g(e);var t=document.getElementsByTagName("body")[0];t.appendChild(e)}else{e.classList.toggle("invisible");return}}searxng.scrollPageToSelected=f;searxng.selectNext=i("down");searxng.selectPrevious=i("up")});(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 g=JSON.parse(this.dataset.mapBoundingbox);var m=JSON.parse(this.dataset.mapGeojson);n.loadStyle("css/leaflet.css");n.loadScript("js/leaflet.js",function(){var e=null;if(g){var t=L.latLng(g[0],g[2]);var n=L.latLng(g[1],g[3]);e=L.latLngBounds(t,n)}var r=L.map(d);var i="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png";var o='Map data © OpenStreetMap contributors';var a=new L.TileLayer(i,{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(){r.fitBounds(e,{maxZoom:17})},0)}else if(f&&p){if(h){r.setView(new L.latLng(p,f),h)}else{r.setView(new L.latLng(p,f),8)}}r.addLayer(a);var c={"OSM Mapnik":a,"OSM Wikimedia":u};L.control.layers(c).addTo(r);if(m){L.geoJson(m).addTo(r)}});e.preventDefault()})})})(window,document,window.searxng);(function(e,o,a){"use strict";a.ready(function(){let i=null;function e(){if(i==null){a.http("GET","engine_descriptions.json").then(function(e){i=JSON.parse(e);for(const[t,n]of Object.entries(i)){let e=o.querySelectorAll('[data-engine-name="'+t+'"] .engine-description');for(const r of e){let e=" ("+a.translations["Source"]+": "+n[1]+")";r.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,s,l){"use strict";l.ready(function(){l.image_thumbnail_layout=new l.ImageLayout("#urls","#urls .result-images","img.image_thumbnail",14,6,200);l.image_thumbnail_layout.watch();l.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 r=s.querySelector(n);var i=this.innerHTML;if(this.classList.contains("collapsed")){i=i.replace(e,t)}else{i=i.replace(t,e)}this.innerHTML=i;this.classList.toggle("collapsed");r.classList.toggle("invisible")});l.on(".media-loader","click",function(){var e=this.getAttribute("data-target");var t=s.querySelector(e+" > iframe");var n=t.getAttribute("src");if(n===null||n===undefined||n===false){t.setAttribute("src",t.getAttribute("data-src"))}});l.selectImage=function(e){if(e){const t=e.querySelector(".result-images-source img");const n=e.querySelector(".image_thumbnail");const r=e.querySelector(".detail");if(t){const i=t.getAttribute("data-src");if(i){const o=s.createElement("div");const a=new Image;o.classList.add("loader");r.appendChild(o);a.onload=e=>{t.src=i;o.remove()};a.onerror=e=>{o.remove()};a.src=i;t.src=n.src;t.removeAttribute("data-src")}}}s.getElementById("results").classList.add("image-detail-open");l.image_thumbnail_layout.align();l.scrollPageToSelected()};l.closeDetail=function(e){s.getElementById("results").classList.remove("image-detail-open");l.image_thumbnail_layout.align();l.scrollPageToSelected()};l.on(".result-detail-close","click",e=>{e.preventDefault();l.closeDetail()});l.on(".result-detail-previous","click",e=>l.selectPrevious(false));l.on(".result-detail-next","click",e=>l.selectNext(false));e.addEventListener("scroll",function(){var e=s.getElementById("backToTop"),t=document.documentElement.scrollTop||document.body.scrollTop,n=s.getElementById("results");if(e!==null){if(t>=100){n.classList.add("scrolling")}else{n.classList.remove("scrolling")}}},true)})})(window,document,window.searxng);(function(t,n,r){"use strict";var i=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)}r.ready(function(){a=n.getElementById(o);function e(){if(i){s(a);i=false}else{}}if(a!==null){u(a);if(r.autocompleter){r.autocomplete=AutoComplete.call(t,{Url:"./autocompleter",EmptyMessage:r.translations.no_item_found,HttpMethod:r.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&&r.search_on_category_select){n.querySelector(".help").className="invisible";r.on("#categories input","change",function(){var e,t=n.querySelectorAll('#categories input[type="checkbox"]');for(e=0;eExample usage of searxng.ImageLayout class. +* searxng.image_thumbnail_layout = new searxng.ImageLayout( +* '#urls', // container_selector +* '#urls .result-images', // results_selector +* 'img.image_thumbnail', // img_selector +* 14, // verticalMargin +* 6, // horizontalMargin +* 200 // maxHeight +* ); +* searxng.image_thumbnail_layout.watch(); */ -(function(a,c){function e(e,t,n,i,r,o){this.container_selector=e;this.results_selector=t;this.img_selector=n;this.verticalMargin=i;this.horizontalMargin=r;this.maxHeight=o;this.isAlignDone=true}e.prototype._getHeigth=function(e,t){var n,i;var r=0;for(n=0;n0&&i.naturalHeight>0){r+=i.naturalWidth/i.naturalHeight}else{r+=1}}return(t-e.length*this.verticalMargin)/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=this.horizontalMargin+"px";i.style.marginTop=this.horizontalMargin+"px";i.style.marginRight=this.verticalMargin-7+"px";i.style.marginBottom=this.verticalMargin-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;e0&&r.naturalHeight>0){i+=r.naturalWidth/r.naturalHeight}else{i+=1}}return(t-e.length*this.verticalMargin)/i};e.prototype._setSize=function(e,t){var n,r,i;var o=e.length,a;for(n=0;n0&&r.naturalHeight>0){i=t*r.naturalWidth/r.naturalHeight}else{i=t}r.style.width=i+"px";r.style.height=t+"px";r.style.marginLeft=this.horizontalMargin+"px";r.style.marginTop=this.horizontalMargin+"px";r.style.marginRight=this.verticalMargin-7+"px";r.style.marginBottom=this.verticalMargin-7+"px";a=r.parentNode.parentNode;if(!a.classList.contains("js")){a.classList.add("js")}}};e.prototype._alignImgs=function(e){var t,n,r,i;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(r=1;r<=e.length&&t;r++){n=e.slice(0,r);i=this._getHeigth(n,u);if(i0){this._alignImgs(o);o=[]}o.push(i.querySelector(this.img_selector));r=i}if(o.length>0){this._alignImgs(o)}};e.prototype.watch=function(){var e,t;var n=this;var r=c.querySelectorAll(this.results_selector);var i=r.length;function o(e){e.originalTarget.src=s.searxng.static_path+s.searxng.theme.img_load_error}function a(){if(n.isAlignDone){n.isAlignDone=false;setTimeout(function(){n.align();n.isAlignDone=true},100)}}s.addEventListener("pageshow",a);s.addEventListener("load",a);s.addEventListener("resize",a);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=e.From&&n.keyCode<=e.To){a=!e.Not}else{a=e.Not}}}};for(var i in s.prototype.getEventsByType(e,t)){var o=s.merge({Operator:l.AND},e.KeyboardMappings[i]),a=l.AND==o.Operator;o.Conditions.forEach(r);if(a===true){o.Callback.call(e,n)}}};s.prototype.makeRequest=function(e,t,n){var r=Object.getOwnPropertyNames(e.HttpHeaders),i=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}}i.open(o,a,true);for(var u=r.length-1;u>=0;u--){i.setRequestHeader(r[u],e.HttpHeaders[r[u]])}i.onreadystatechange=function(){if(i.readyState==4&&i.status==200){e.$Cache[s]=i.response;t(i.response)}else if(i.status>=400){n()}};return i};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 r=e._Cache(e._Pre());if(r===undefined){var i=s.prototype.makeRequest(e,t,n);s.prototype.ajax(e,i)}else{t(r)}};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)"),r=this.DOMResults.querySelector("li.active");if(r){var i=Array.prototype.indexOf.call(r.parentNode.children,r),o=i+(e.keyCode-39),a=this.DOMResults.getElementsByTagName("li").length;if(o<0){o=a-1}else if(o>=a){o=0}r.classList.remove("active");r.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"),r=this._Limit();if(r<0){e=e.reverse()}else if(r===0){r=e.length}for(var i=0;i0){this.DOMResults.innerHTML=e}else{var r=this._EmptyMessage();if(r!==""){n.innerHTML=r;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 r=0;r