mirror of
https://github.com/searxng/searxng.git
synced 2025-04-28 06:04:43 +00:00
14 lines
28 KiB
JavaScript
14 lines
28 KiB
JavaScript
/**
|
||
* @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(h,d){h.Element&&function(r){r.matches=r.matches||r.matchesSelector||r.webkitMatchesSelector||r.msMatchesSelector||function(a){for(var l=this,n=(l.parentNode||l.document).querySelectorAll(a),e=-1;n[++e]&&n[e]!=l;);return!!n[e]}}(Element.prototype);function u(r,a,l){try{r.call(a,l)}catch(n){console.log(n)}}var p=window.searxng||{};p.on=function(r,a,l,n){n=n||!1,typeof r!="string"?r.addEventListener(a,l,n):d.addEventListener(a,function(e){for(var t=e.target||e.srcElement,o=!1;t&&t.matches&&t!==d&&!(o=t.matches(r));)t=t.parentElement;o&&u(l,t,e)},n)},p.ready=function(r){document.readyState!="loading"?r.call(h):h.addEventListener("DOMContentLoaded",r.bind(h))},p.http=function(r,a,l=null){return new Promise(function(n,e){try{var t=new XMLHttpRequest;t.open(r,a,!0),t.timeout=2e4,t.onload=function(){t.status==200?n(t.response,t.responseType):e(Error(t.statusText))},t.onerror=function(){e(Error("Network Error"))},t.onabort=function(){e(Error("Transaction is aborted"))},t.ontimeout=function(){e(Error("Timeout"))},l?t.send(l):t.send()}catch(o){e(o)}})},p.loadStyle=function(r){var a=p.settings.theme_static_path+"/"+r,l="style_"+r.replace(".","_"),n=d.getElementById(l);n===null&&(n=d.createElement("link"),n.setAttribute("id",l),n.setAttribute("rel","stylesheet"),n.setAttribute("type","text/css"),n.setAttribute("href",a),d.body.appendChild(n))},p.loadScript=function(r,a){var l=p.settings.theme_static_path+"/"+r,n="script_"+r.replace(".","_"),e=d.getElementById(n);if(e===null)e=d.createElement("script"),e.setAttribute("id",n),e.setAttribute("src",l),e.onload=a,e.onerror=function(){e.setAttribute("error","1")},d.body.appendChild(e);else if(e.hasAttribute("error"))console.log("callback not executed : script '"+l+"' not loaded.");else try{a.apply(e,[])}catch(t){console.log(t)}},p.insertBefore=function(r,a){a.parentNode.insertBefore(r,a)},p.insertAfter=function(r,a){a.parentNode.insertAfter(r,a.nextSibling)},p.on(".close","click",function(){this.parentNode.classList.add("invisible")});function m(){for(var r of d.getElementsByTagName("body")[0].classList.values())if(r.endsWith("_endpoint"))return r.split("_")[0];return""}return p.endpoint=m(),p}(window,document);searxng.ready(function(){if(searxng.infinite_scroll_supported="IntersectionObserver"in window&&"IntersectionObserverEntry"in window&&"intersectionRatio"in window.IntersectionObserverEntry.prototype,searxng.endpoint!=="results")return;if(!searxng.infinite_scroll_supported){console.log("IntersectionObserver not supported");return}let h=document;var d=h.getElementById("results").classList.contains("only_template_images");function u(){var r=h.createElement("div");return r.classList.add("loader"),r}function p(r,a){r.textContent="",a.forEach(l=>r.appendChild(l))}function m(r){var a=h.querySelector("#pagination form.next_page");if(a){p(h.querySelector("#pagination"),[u()]);var l=new FormData(a);searxng.http("POST",h.querySelector("#search").getAttribute("action"),l).then(function(n){var e=new DOMParser().parseFromString(n,"text/html"),t=e.querySelectorAll("#urls article"),o=e.querySelector("#pagination");h.querySelector("#pagination").remove(),t.length>0&&!d&&h.querySelector("#urls").appendChild(h.createElement("hr")),t.forEach(c=>{h.querySelector("#urls").appendChild(c)}),o&&(h.querySelector("#results").appendChild(o),r())}).catch(function(n){console.log(n);var e=h.createElement("div");e.textContent=searxng.settings.translations.error_loading_next_page,e.classList.add("dialog-error"),e.setAttribute("role","alert"),p(h.querySelector("#pagination"),[e])})}}if(searxng.settings.infinite_scroll&&searxng.infinite_scroll_supported){const r={rootMargin:"20rem"},a="article.result:last-child",l=new IntersectionObserver(n=>{const e=n[0];e.isIntersecting&&(l.unobserve(e.target),m(()=>l.observe(h.querySelector(a),r)))});l.observe(h.querySelector(a),r)}});searxng.ready(function(){function h(i){for(;i!==void 0;){if(i.classList.contains("detail"))return!0;if(i.classList.contains("result"))return!1;i=i.parentNode}return!1}function d(i){for(;i!==void 0;){if(i.classList.contains("result"))return i;i=i.parentNode}}function u(i){return i&&i.classList.contains("result-images")}searxng.on(".result","click",function(i){if(!h(i.target)){a(this)(!0,!0);let f=d(i.target);u(f)&&(i.preventDefault(),searxng.selectImage(f))}}),searxng.on(".result a","focus",function(i){if(!h(i.target)){let f=d(i.target);f&&f.getAttribute("data-vim-selected")===null&&a(f)(!0),u(f)&&searxng.selectImage(f)}},!0);var p={Escape:{key:"ESC",fun:n,des:"remove focus from the focused input",cat:"Control"},c:{key:"c",fun:O,des:"copy url of the selected result to the clipboard",cat:"Results"},h:{key:"h",fun:_,des:"toggle help window",cat:"Other"},i:{key:"i",fun:v,des:"focus on the search input",cat:"Control"},n:{key:"n",fun:t(),des:"go to next page",cat:"Results"},o:{key:"o",fun:b(!1),des:"open search result",cat:"Results"},p:{key:"p",fun:o(),des:"go to previous page",cat:"Results"},r:{key:"r",fun:l,des:"reload page from the server",cat:"Control"},t:{key:"t",fun:b(!0),des:"open the result in a new tab",cat:"Results"}},m={default:Object.assign({ArrowLeft:{key:"←",fun:a("up"),des:"select previous search result",cat:"Results"},ArrowRight:{key:"→",fun:a("down"),des:"select next search result",cat:"Results"}},p),vim:Object.assign({b:{key:"b",fun:s(-window.innerHeight),des:"scroll one page up",cat:"Navigation"},f:{key:"f",fun:s(window.innerHeight),des:"scroll one page down",cat:"Navigation"},u:{key:"u",fun:s(-window.innerHeight/2),des:"scroll half a page up",cat:"Navigation"},d:{key:"d",fun:s(window.innerHeight/2),des:"scroll half a page down",cat:"Navigation"},g:{key:"g",fun:g(-document.body.scrollHeight,"top"),des:"scroll to the top of the page",cat:"Navigation"},v:{key:"v",fun:g(document.body.scrollHeight,"bottom"),des:"scroll to the bottom of the page",cat:"Navigation"},k:{key:"k",fun:a("up"),des:"select previous search result",cat:"Results"},j:{key:"j",fun:a("down"),des:"select next search result",cat:"Results"},y:{key:"y",fun:O,des:"copy url of the selected result to the clipboard",cat:"Results"}},p)},r=m[searxng.settings.hotkeys]||m.default;searxng.on(document,"keydown",function(i){if(Object.prototype.hasOwnProperty.call(r,i.key)&&!i.ctrlKey&&!i.altKey&&!i.shiftKey&&!i.metaKey){var f=i.target.tagName.toLowerCase();i.key==="Escape"?r[i.key].fun(i):(i.target===document.body||f==="a"||f==="button")&&(i.preventDefault(),r[i.key].fun())}});function a(i){return function(f,M){var E=document.querySelector(".result[data-vim-selected]"),A=i;if(E===null){if(E=document.querySelector(".result"),E===null)return;(i==="down"||i==="up")&&(A=E)}var y,w=document.querySelectorAll(".result");if(w=Array.from(w),typeof A!="string")y=A;else switch(A){case"visible":for(var T=document.documentElement.scrollTop||document.body.scrollTop,x=T+document.documentElement.clientHeight,I=0;I<w.length;I++){y=w[I];var R=y.offsetTop,N=R+y.clientHeight;if(N<=x&&R>T)break}break;case"down":y=w[w.indexOf(E)+1]||E;break;case"up":y=w[w.indexOf(E)-1]||E;break;case"bottom":y=w[w.length-1];break;case"top":default:y=w[0]}if(y){if(E.removeAttribute("data-vim-selected"),y.setAttribute("data-vim-selected","true"),!M){var D=y.querySelector("h3 a")||y.querySelector("a");D!==null&&D.focus()}f||c()}}}function l(){document.location.reload(!0)}function n(i){const f=i.target.tagName.toLowerCase();document.activeElement&&(f==="input"||f==="select"||f==="textarea")?document.activeElement.blur():searxng.closeDetail()}function e(i){return function(){var f=document.querySelector(i);f&&f.click()}}function t(){return e('nav#pagination .next_page button[type="submit"]')}function o(){return e('nav#pagination .previous_page button[type="submit"]')}function c(){var i=document.querySelector(".result[data-vim-selected]");if(i!==null){var f=document.documentElement.scrollTop||document.body.scrollTop,M=document.documentElement.clientHeight,E=i.offsetTop,A=E+i.clientHeight,y=120;if(i.previousElementSibling===null&&A<M){window.scroll(window.scrollX,0);return}if(f>E-y)window.scroll(window.scrollX,E-y);else{var w=f+M;w<A+y&&window.scroll(window.scrollX,A-M+y)}}}function s(i){return function(){window.scrollBy(0,i),a("visible")()}}function g(i,f){return function(){window.scrollTo(0,i),a(f)()}}function v(){window.scrollTo(0,0);var i=document.querySelector("#q");if(i.focus(),i.setSelectionRange){var f=i.value.length;i.setSelectionRange(f,f)}}function b(i){return function(){var f=document.querySelector(".result[data-vim-selected] h3 a");if(f===null&&(f=document.querySelector(".result[data-vim-selected] > a")),f!==null){var M=f.getAttribute("href");i?window.open(M):window.location.href=M}}}function k(i){var f={};for(var M in r){var E=r[M];f[E.cat]=f[E.cat]||[],f[E.cat].push(E)}var A=Object.keys(f).sort(function(N,D){return f[D].length-f[N].length});if(A.length!==0){var y='<a href="#" class="close" aria-label="close" title="close">×</a>';y+="<h3>How to navigate SearXNG with hotkeys</h3>",y+="<table>";for(var w=0;w<A.length;w++){var T=f[A[w]],x=w===A.length-1,I=w%2===0;I&&(y+="<tr>"),y+="<td>",y+="<h4>"+T[0].cat+"</h4>",y+='<ul class="list-unstyled">';for(var R in T)y+="<li><kbd>"+T[R].key+"</kbd> "+T[R].des+"</li>";y+="</ul>",y+="</td>",(!I||x)&&(y+="</tr>")}y+="</table>",i.innerHTML=y}}function _(){var i=document.querySelector("#vim-hotkeys-help");if(i==null){i=document.createElement("div"),i.id="vim-hotkeys-help",i.className="dialog-modal",k(i);var f=document.getElementsByTagName("body")[0];f.appendChild(i)}else{i.classList.toggle("invisible");return}}function O(){var i=document.querySelector(".result[data-vim-selected] h3 a");if(i===null)return;const f=i.getAttribute("href");navigator.clipboard.writeText(f)}searxng.scrollPageToSelected=c,searxng.selectNext=a("down"),searxng.selectPrevious=a("up")});(function(h,d,u){u.ready(function(){u.on(".searxng_init_map","click",function(p){this.classList.remove("searxng_init_map");var m=this.dataset.leafletTarget,r=parseFloat(this.dataset.mapLon),a=parseFloat(this.dataset.mapLat),l=parseFloat(this.dataset.mapZoom),n=JSON.parse(this.dataset.mapBoundingbox),e=JSON.parse(this.dataset.mapGeojson);u.loadStyle("css/leaflet.css"),u.loadScript("js/leaflet.js",function(){var t=null;if(n){var o=L.latLng(n[0],n[2]),c=L.latLng(n[1],n[3]);t=L.latLngBounds(o,c)}var s=L.map(m),g="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",v='Map data © <a href="https://openstreetmap.org">OpenStreetMap</a> contributors',b=new L.TileLayer(g,{minZoom:1,maxZoom:19,attribution:v}),k="https://maps.wikimedia.org/osm-intl/{z}/{x}/{y}.png",_='Wikimedia maps | Maps data © <a href="https://openstreetmap.org">OpenStreetMap contributors</a>',O=new L.TileLayer(k,{minZoom:1,maxZoom:19,attribution:_});t?setTimeout(function(){s.fitBounds(t,{maxZoom:17})},0):r&&a&&(l?s.setView(new L.latLng(a,r),l):s.setView(new L.latLng(a,r),8)),s.addLayer(b);var i={"OSM Mapnik":b,"OSM Wikimedia":O};L.control.layers(i).addTo(s),e&&L.geoJson(e).addTo(s)}),p.preventDefault()})})})(window,document,window.searxng);(function(h,d,u){u.endpoint==="preferences"&&u.ready(function(){let p=null;function m(){p==null&&u.http("GET","engine_descriptions.json").then(function(t){p=JSON.parse(t);for(const[o,c]of Object.entries(p)){let s=d.querySelectorAll('[data-engine-name="'+o+'"] .engine-description');for(const g of s){let v=" (<i>"+u.settings.translations.Source+": "+c[1]+"</i>)";g.innerHTML=c[0]+v}}})}for(const t of d.querySelectorAll("[data-engine-name]"))u.on(t,"mouseenter",m);const r=d.querySelectorAll(".enable-all-engines"),a=d.querySelectorAll(".disable-all-engines"),l=d.querySelectorAll("tbody input[type=checkbox][class~=checkbox-onoff]"),n=t=>{for(const o of l)o.offsetParent!==null&&(o.checked=!t)};for(const t of r)u.on(t,"click",()=>n(!0));for(const t of a)u.on(t,"click",()=>n(!1));const e=d.querySelector("#copy-hash");u.on(e,"click",t=>{t.preventDefault(),navigator.clipboard.writeText(e.dataset.hash),e.innerText=e.dataset.copiedText})})})(window,document,window.searxng);/*!
|
||
* swiped-events.js - v@version@
|
||
* Pure JavaScript swipe events
|
||
* https://github.com/john-doherty/swiped-events
|
||
* @inspiration https://stackoverflow.com/questions/16348031/disable-scrolling-when-touch-moving-certain-element
|
||
* @author John Doherty <www.johndoherty.info>
|
||
* @license MIT
|
||
*/(function(h,d){typeof h.CustomEvent!="function"&&(h.CustomEvent=function(s,g){g=g||{bubbles:!1,cancelable:!1,detail:void 0};var v=d.createEvent("CustomEvent");return v.initCustomEvent(s,g.bubbles,g.cancelable,g.detail),v},h.CustomEvent.prototype=h.Event.prototype),d.addEventListener("touchstart",t,!1),d.addEventListener("touchmove",o,!1),d.addEventListener("touchend",e,!1);var u=null,p=null,m=null,r=null,a=null,l=null,n=0;function e(s){if(l===s.target){var g=parseInt(c(l,"data-swipe-threshold","20"),10),v=c(l,"data-swipe-unit","px"),b=parseInt(c(l,"data-swipe-timeout","500"),10),k=Date.now()-a,_="",O=s.changedTouches||s.touches||[];if(v==="vh"&&(g=Math.round(g/100*d.documentElement.clientHeight)),v==="vw"&&(g=Math.round(g/100*d.documentElement.clientWidth)),Math.abs(m)>Math.abs(r)?Math.abs(m)>g&&k<b&&(m>0?_="swiped-left":_="swiped-right"):Math.abs(r)>g&&k<b&&(r>0?_="swiped-up":_="swiped-down"),_!==""){var i={dir:_.replace(/swiped-/,""),touchType:(O[0]||{}).touchType||"direct",fingers:n,xStart:parseInt(u,10),xEnd:parseInt((O[0]||{}).clientX||-1,10),yStart:parseInt(p,10),yEnd:parseInt((O[0]||{}).clientY||-1,10)};l.dispatchEvent(new CustomEvent("swiped",{bubbles:!0,cancelable:!0,detail:i})),l.dispatchEvent(new CustomEvent(_,{bubbles:!0,cancelable:!0,detail:i}))}u=null,p=null,a=null}}function t(s){s.target.getAttribute("data-swipe-ignore")!=="true"&&(l=s.target,a=Date.now(),u=s.touches[0].clientX,p=s.touches[0].clientY,m=0,r=0,n=s.touches.length)}function o(s){if(!(!u||!p)){var g=s.touches[0].clientX,v=s.touches[0].clientY;m=u-g,r=p-v}}function c(s,g,v){for(;s&&s!==d.documentElement;){var b=s.getAttribute(g);if(b)return b;s=s.parentNode}return v}})(window,document);(function(h,d,u){u.endpoint==="results"&&u.ready(function(){d.querySelectorAll("#urls img").forEach(l=>l.addEventListener("error",()=>{l.src=window.searxng.settings.theme_static_path+"/img/img_load_error.svg"},{once:!0})),d.querySelector("#search_url button#copy_url")&&(d.querySelector("#search_url button#copy_url").style.display="block"),u.on(".btn-collapse","click",function(){var l=this.getAttribute("data-btn-text-collapsed"),n=this.getAttribute("data-btn-text-not-collapsed"),e=this.getAttribute("data-target"),t=d.querySelector(e),o=this.innerHTML;this.classList.contains("collapsed")?o=o.replace(l,n):o=o.replace(n,l),this.innerHTML=o,this.classList.toggle("collapsed"),t.classList.toggle("invisible")}),u.on(".media-loader","click",function(){var l=this.getAttribute("data-target"),n=d.querySelector(l+" > iframe"),e=n.getAttribute("src");(e==null||e===!1)&&n.setAttribute("src",n.getAttribute("data-src"))}),u.on("#copy_url","click",function(){var l=this.parentElement.querySelector("pre");navigator.clipboard.writeText(l.innerText),this.innerText=this.dataset.copiedText});let p;const m=d.createElement("div");m.classList.add("loader");const r=new Image,a=(l,n)=>{p&&clearTimeout(p),p=setTimeout(()=>{r.src=l},1e3),r.onload=()=>{n(),m.remove()},r.onerror=()=>{m.remove()}};u.selectImage=l=>{if(d.getElementById("results").classList.add("image-detail-open"),window.location.hash="#image-viewer",u.scrollPageToSelected(),!l)return;const n=l.querySelector(".result-images-source img");if(!n)return;const e=n.getAttribute("data-src");if(!e)return;const t=l.querySelector(".image_thumbnail");n.src=t.src,l.querySelector(".detail").appendChild(m),a(e,()=>{n.src=e,n.removeAttribute("data-src")})},u.closeDetail=function(){d.getElementById("results").classList.remove("image-detail-open"),window.location.hash=="#image-viewer"&&window.history.back(),u.scrollPageToSelected()},u.on(".result-detail-close","click",l=>{l.preventDefault(),u.closeDetail()}),u.on(".result-detail-previous","click",l=>{l.preventDefault(),u.selectPrevious(!1)}),u.on(".result-detail-next","click",l=>{l.preventDefault(),u.selectNext(!1)}),window.addEventListener("hashchange",()=>{window.location.hash!="#image-viewer"&&u.closeDetail()}),d.querySelectorAll(".swipe-horizontal").forEach(l=>{l.addEventListener("swiped-left",function(){u.selectNext(!1)}),l.addEventListener("swiped-right",function(){u.selectPrevious(!1)})}),h.addEventListener("scroll",function(){var l=d.getElementById("backToTop"),n=document.documentElement.scrollTop||document.body.scrollTop,e=d.getElementById("results");l!==null&&(n>=100?e.classList.add("scrolling"):e.classList.remove("scrolling"))},!0)})})(window,document,window.searxng);function P(h){return h&&h.__esModule&&Object.prototype.hasOwnProperty.call(h,"default")?h.default:h}function C(h){throw new Error('Could not dynamically require "'+h+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var q={exports:{}},H;function B(){return H||(H=1,function(h,d){(function(u){h.exports=u()})(function(){return function(){function u(p,m,r){function a(e,t){if(!m[e]){if(!p[e]){var o=typeof C=="function"&&C;if(!t&&o)return o(e,!0);if(l)return l(e,!0);var c=new Error("Cannot find module '"+e+"'");throw c.code="MODULE_NOT_FOUND",c}var s=m[e]={exports:{}};p[e][0].call(s.exports,function(g){var v=p[e][1][g];return a(v||g)},s,s.exports,u,p,m,r)}return m[e].exports}for(var l=typeof C=="function"&&C,n=0;n<r.length;n++)a(r[n]);return a}return u}()({1:[function(u,p,m){var r;(function(n){n[n.AND=0]="AND",n[n.OR=1]="OR"})(r||(r={}));var a;(function(n){n[n.KEYDOWN=0]="KEYDOWN",n[n.KEYUP=1]="KEYUP"})(a||(a={}));var l=function(){function n(e,t){if(e===void 0&&(e={}),t===void 0&&(t="[data-autocomplete]"),Array.isArray(t))t.forEach(function(s){new n(e,s)});else if(typeof t=="string"){var o=document.querySelectorAll(t);Array.prototype.forEach.call(o,function(s){new n(e,s)})}else{var c=n.merge(n.defaults,e,{DOMResults:document.createElement("div")});return n.prototype.create(c,t),c}}return n.prototype.create=function(e,t){if(e.Input=t,e.Input.nodeName.match(/^INPUT$/i)&&(e.Input.hasAttribute("type")===!1||e.Input.getAttribute("type").match(/^TEXT|SEARCH$/i))){e.Input.setAttribute("autocomplete","off"),e._Position(e),e.Input.parentNode.appendChild(e.DOMResults),e.$Listeners={blur:e._Blur.bind(e),destroy:n.prototype.destroy.bind(null,e),focus:e._Focus.bind(e),keyup:n.prototype.event.bind(null,e,a.KEYUP),keydown:n.prototype.event.bind(null,e,a.KEYDOWN),position:e._Position.bind(e)};for(var o in e.$Listeners)e.Input.addEventListener(o,e.$Listeners[o])}},n.prototype.getEventsByType=function(e,t){var o={};for(var c in e.KeyboardMappings){var s=a.KEYUP;e.KeyboardMappings[c].Event!==void 0&&(s=e.KeyboardMappings[c].Event),s==t&&(o[c]=e.KeyboardMappings[c])}return o},n.prototype.event=function(e,t,o){var c=function(b){(v===!0&&g.Operator==r.AND||v===!1&&g.Operator==r.OR)&&(b=n.merge({Not:!1},b),b.hasOwnProperty("Is")?b.Is==o.keyCode?v=!b.Not:v=b.Not:b.hasOwnProperty("From")&&b.hasOwnProperty("To")&&(o.keyCode>=b.From&&o.keyCode<=b.To?v=!b.Not:v=b.Not))};for(var s in n.prototype.getEventsByType(e,t)){var g=n.merge({Operator:r.AND},e.KeyboardMappings[s]),v=r.AND==g.Operator;g.Conditions.forEach(c),v===!0&&g.Callback.call(e,o)}},n.prototype.makeRequest=function(e,t,o){var c=Object.getOwnPropertyNames(e.HttpHeaders),s=new XMLHttpRequest,g=e._HttpMethod(),v=e._Url(),b=e._Pre(),k=encodeURIComponent(e._QueryArg())+"="+encodeURIComponent(b);g.match(/^GET$/i)&&(v.indexOf("?")!==-1?v+="&"+k:v+="?"+k),s.open(g,v,!0);for(var _=c.length-1;_>=0;_--)s.setRequestHeader(c[_],e.HttpHeaders[c[_]]);return s.onreadystatechange=function(){s.readyState==4&&s.status==200?(e.$Cache[b]=s.response,t(s.response)):s.status>=400&&o()},s},n.prototype.ajax=function(e,t,o){o===void 0&&(o=!0),e.$AjaxTimer&&window.clearTimeout(e.$AjaxTimer),o===!0?e.$AjaxTimer=window.setTimeout(n.prototype.ajax.bind(null,e,t,!1),e.Delay):(e.Request&&e.Request.abort(),e.Request=t,e.Request.send(e._QueryArg()+"="+e._Pre()))},n.prototype.cache=function(e,t,o){var c=e._Cache(e._Pre());if(c===void 0){var s=n.prototype.makeRequest(e,t,o);n.prototype.ajax(e,s)}else t(c)},n.prototype.destroy=function(e){for(var t in e.$Listeners)e.Input.removeEventListener(t,e.$Listeners[t]);e.DOMResults.parentNode.removeChild(e.DOMResults)},n.merge=function(){for(var e={},t,o=0;o<arguments.length;o++)for(t in arguments[o])e[t]=arguments[o][t];return e},n.defaults={Delay:150,EmptyMessage:"No result here",Highlight:{getRegex:function(e){return new RegExp(e,"ig")},transform:function(e){return"<strong>"+e+"</strong>"}},HttpHeaders:{"Content-type":"application/x-www-form-urlencoded"},Limit:0,MinChars:0,HttpMethod:"GET",QueryArg:"q",Url:null,KeyboardMappings:{Enter:{Conditions:[{Is:13,Not:!1}],Callback:function(e){if(this.DOMResults.getAttribute("class").indexOf("open")!=-1){var t=this.DOMResults.querySelector("li.active");t!==null&&(e.preventDefault(),this._Select(t),this.DOMResults.setAttribute("class","autocomplete"))}},Operator:r.AND,Event:a.KEYDOWN},KeyUpAndDown_down:{Conditions:[{Is:38,Not:!1},{Is:40,Not:!1}],Callback:function(e){e.preventDefault()},Operator:r.OR,Event:a.KEYDOWN},KeyUpAndDown_up:{Conditions:[{Is:38,Not:!1},{Is:40,Not:!1}],Callback:function(e){e.preventDefault();var t=this.DOMResults.querySelector("li:first-child:not(.locked)"),o=this.DOMResults.querySelector("li:last-child:not(.locked)"),c=this.DOMResults.querySelector("li.active");if(c){var s=Array.prototype.indexOf.call(c.parentNode.children,c),g=s+(e.keyCode-39),v=this.DOMResults.getElementsByTagName("li").length;g<0?g=v-1:g>=v&&(g=0),c.classList.remove("active"),c.parentElement.children.item(g).classList.add("active")}else o&&e.keyCode==38?o.classList.add("active"):t&&t.classList.add("active")},Operator:r.OR,Event:a.KEYUP},AlphaNum:{Conditions:[{Is:13,Not:!0},{From:35,To:40,Not:!0}],Callback:function(){var e=this.Input.getAttribute("data-autocomplete-old-value"),t=this._Pre();t!==""&&t.length>=this._MinChars()?((!e||t!=e)&&this.DOMResults.setAttribute("class","autocomplete open"),n.prototype.cache(this,(function(o){this._Render(this._Post(o)),this._Open()}).bind(this),this._Error)):this._Close()},Operator:r.AND,Event:a.KEYUP}},DOMResults:null,Request:null,Input:null,_EmptyMessage:function(){var e="";return this.Input.hasAttribute("data-autocomplete-empty-message")?e=this.Input.getAttribute("data-autocomplete-empty-message"):this.EmptyMessage!==!1?e=this.EmptyMessage:e="",e},_Limit:function(){var e=this.Input.getAttribute("data-autocomplete-limit");return isNaN(e)||e===null?this.Limit:parseInt(e,10)},_MinChars:function(){var e=this.Input.getAttribute("data-autocomplete-minchars");return isNaN(e)||e===null?this.MinChars:parseInt(e,10)},_Highlight:function(e){return e.replace(this.Highlight.getRegex(this._Pre()),this.Highlight.transform)},_HttpMethod:function(){return this.Input.hasAttribute("data-autocomplete-method")?this.Input.getAttribute("data-autocomplete-method"):this.HttpMethod},_QueryArg:function(){return this.Input.hasAttribute("data-autocomplete-param-name")?this.Input.getAttribute("data-autocomplete-param-name"):this.QueryArg},_Url:function(){return this.Input.hasAttribute("data-autocomplete")?this.Input.getAttribute("data-autocomplete"):this.Url},_Blur:function(e){if(e===void 0&&(e=!1),e)this._Close();else{var t=this;setTimeout(function(){t._Blur(!0)},150)}},_Cache:function(e){return this.$Cache[e]},_Focus:function(){var e=this.Input.getAttribute("data-autocomplete-old-value");(!e||this.Input.value!=e)&&this._MinChars()<=this.Input.value.length&&this.DOMResults.setAttribute("class","autocomplete open")},_Open:function(){var e=this;Array.prototype.forEach.call(this.DOMResults.getElementsByTagName("li"),function(t){t.getAttribute("class")!="locked"&&(t.onclick=function(){e._Select(t)})})},_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;typeof e=="string"?t=this._RenderRaw(e):t=this._RenderResponseItems(e),this.DOMResults.hasChildNodes()&&this.DOMResults.removeChild(this.DOMResults.childNodes[0]),this.DOMResults.appendChild(t)},_RenderResponseItems:function(e){var t=document.createElement("ul"),o=document.createElement("li"),c=this._Limit();c<0?e=e.reverse():c===0&&(c=e.length);for(var s=0;s<Math.min(Math.abs(c),e.length);s++)o.innerHTML=e[s].Label,o.setAttribute("data-autocomplete-value",e[s].Value),t.appendChild(o),o=document.createElement("li");return t},_RenderRaw:function(e){var t=document.createElement("ul"),o=document.createElement("li");if(e.length>0)this.DOMResults.innerHTML=e;else{var c=this._EmptyMessage();c!==""&&(o.innerHTML=c,o.setAttribute("class","locked"),t.appendChild(o))}return t},_Post:function(e){try{var t=[],o=JSON.parse(e);if(Object.keys(o).length===0)return"";if(Array.isArray(o))for(var c=0;c<Object.keys(o).length;c++)t[t.length]={Value:o[c],Label:this._Highlight(o[c])};else for(var s in o)t.push({Value:s,Label:this._Highlight(o[s])});return t}catch{return e}},_Pre:function(){return this.Input.value},_Select:function(e){e.hasAttribute("data-autocomplete-value")?this.Input.value=e.getAttribute("data-autocomplete-value"):this.Input.value=e.innerHTML,this.Input.setAttribute("data-autocomplete-old-value",this.Input.value)},_Error:function(){},$AjaxTimer:null,$Cache:{},$Listeners:{}},n}();p.exports=l},{}]},{},[1])(1)})}(q)),q.exports}var K=B();const S=P(K);(function(h,d,u){var p="q",m;const r=window.matchMedia("only screen and (max-width: 50em)").matches;function a(){if(m.value.length>0){var n=document.getElementById("search");setTimeout(n.submit.bind(n),0)}}function l(n){var e=document.getElementById("clear_search"),t=function(){n.value.length===0?e.classList.add("empty"):e.classList.remove("empty")};t(),e.addEventListener("click",function(o){n.value="",n.focus(),t(),o.preventDefault()}),n.addEventListener("input",t,!1)}u.ready(function(){m=d.getElementById(p),m!==null&&(l(m),u.settings.autocomplete&&(u.autocomplete=S.call(h,{Url:"./autocompleter",EmptyMessage:u.settings.translations.no_item_found,HttpMethod:u.settings.method,HttpHeaders:{"Content-type":"application/x-www-form-urlencoded","X-Requested-With":"XMLHttpRequest"},MinChars:u.settings.autocomplete_min,Delay:300,_Position:function(){},_Open:function(){var t=this;Array.prototype.forEach.call(this.DOMResults.getElementsByTagName("li"),function(o){o.getAttribute("class")!="locked"&&(o.onmousedown=function(){t._Select(o)})})},_Select:function(t){S.defaults._Select.call(this,t);var o=t.closest("form");o&&o.submit()},_MinChars:function(){return this.Input.value.indexOf("!")>-1?0:S.defaults._MinChars.call(this)},KeyboardMappings:Object.assign({},S.defaults.KeyboardMappings,{KeyUpAndDown_up:Object.assign({},S.defaults.KeyboardMappings.KeyUpAndDown_up,{Callback:function(t){S.defaults.KeyboardMappings.KeyUpAndDown_up.Callback.call(this,t);var o=this.DOMResults.querySelector("li.active");o&&S.defaults._Select.call(this,o)}}),Tab:Object.assign({},S.defaults.KeyboardMappings.Enter,{Conditions:[{Is:9,Not:!1}],Callback:function(t){if(this.DOMResults.getAttribute("class").indexOf("open")!=-1){var o=this.DOMResults.querySelector("li.active");o!==null&&(S.defaults._Select.call(this,o),t.preventDefault())}}})})},"#"+p)),S.prototype.ajax=function(t,o,c){c===void 0&&(c=!0),t.$AjaxTimer&&window.clearTimeout(t.$AjaxTimer),c===!0?t.$AjaxTimer=window.setTimeout(S.prototype.ajax.bind(null,t,o,!1),t.Delay):(t.Request&&t.Request.abort(),t.Request=o,t.Request.send(encodeURIComponent(t._QueryArg())+"="+encodeURIComponent(t._Pre())))},!r&&document.querySelector(".index_endpoint")&&m.focus()),m!==null&&u.settings.search_on_category_select&&d.querySelector(".search_filters")!=null&&(u.on(d.getElementById("safesearch"),"change",a),u.on(d.getElementById("time_range"),"change",a),u.on(d.getElementById("language"),"change",a));const n=d.querySelectorAll("button.category_button");for(let t of n)u.on(t,"click",o=>{if(o.shiftKey){o.preventDefault(),t.classList.toggle("selected");return}const c=d.querySelectorAll("button.category_button.selected");for(let s of c)s.classList.remove("selected");t.classList.add("selected")});const e=d.querySelector("#search");e!=null&&u.on(e,"submit",t=>{t.preventDefault();const o=d.querySelector("#selected-categories");if(o){let c=[];for(let s of n)s.classList.contains("selected")&&c.push(s.name.replace("category_",""));o.value=c.join(",")}e.submit()})})})(window,document,window.searxng);
|
||
//# sourceMappingURL=searxng.min.js.map
|