searxngRebrandZaclys/searx/static/themes/simple/js/searxng.min.js

40 lines
25 KiB
JavaScript
Raw Normal View History

2021-10-01 16:07:27 +00:00
/**
* @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
*/
2021-11-30 11:43:18 +00:00
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),r=-1;while(n[++r]&&n[r]!=t);return!!n[r]}})(Element.prototype)}function a(e,t,n){try{e.call(t,n)}catch(e){console.log(e)}}var s=window.searxng||{};s.on=function(r,e,i,t){t=t||false;if(typeof r!=="string"){r.addEventListener(e,i,t)}else{o.addEventListener(e,function(e){var t=e.target||e.srcElement,n=false;while(t&&t.matches&&t!==o&&!(n=t.matches(r)))t=t.parentElement;if(n)a(i,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,r=function(){},i=function(){},o={then:function(e){r=e;return o},catch:function(e){i=e;return o}};try{n.open(e,t,true);n.onload=function(){if(n.status==200){r(n.response,n.responseType)}else{i(Error(n.statusText))}};n.onerror=function(){i(Error("Network Error"))};n.onabort=function(){i(Error("Transaction is aborted"))};n.send()}catch(e){i(e)}return o};s.loadStyle=function(e){var t=s.static_path+e,n="style_"+e.replace(".","_"),r=o.getElementById(n);if(r===null){r=o.createElement("link");r.setAttribute("id",n);r.setAttribute("rel","stylesheet");r.setAttribute("type","text/css");r.setAttribute("href",t);o.body.appendChild(r)}};s.loadScript=function(e,t){var n=s.static_path+e,r="script_"+e.replace(".","_"),i=o.getElementById(r);if(i===null){i=o.createElement("script");i.setAttribute("id",r);i.setAttribute("src",n);i.onload=t;i.onerror=function(){i.setAttribute("error","1")};o.body.appendChild(i)}else if(!i.hasAttribute("error")){try{t.apply(i,[])}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 r(e){return e&&e.classList.contains("result-images")}searxng.on(".result","click",function(t){if(!e(t.target)){i(this)(true);let e=n(t.target);if(r(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){i(e)(true)}if(r(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:i("up"),des:"select previous search result",cat:"Results"},74:{key:"j",fun:i("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.cal
2021-10-01 16:07:27 +00:00
/**
*
* Google Image Layout v0.0.1
* Description, by Anh Trinh.
* Heavily modified for searx
* https://ptgamr.github.io/2014-09-12-google-image-layout/
* https://ptgamr.github.io/google-image-layout/src/google-image-layout.js
*
* @license Free to use under the MIT License.
*
2021-11-30 11:43:18 +00:00
* @example <caption>Example usage of searxng.ImageLayout class.</caption>
* 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();
2021-10-01 16:07:27 +00:00
*/
2021-11-30 11:43:18 +00:00
(function(s,c){function e(e,t,n,r,i,o){this.container_selector=e;this.results_selector=t;this.img_selector=n;this.verticalMargin=r;this.horizontalMargin=i;this.maxHeight=o;this.isAlignDone=true}e.prototype._getHeigth=function(e,t){var n,r;var i=0;for(n=0;n<e.length;n++){r=e[n];if(r.naturalWidth>0&&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;n<o;n++){r=e[n];if(r.naturalWidth>0&&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(i<this.maxHeight){this._setSize(n,i);e=e.slice(r);t=false}}if(t){this._setSize(n,Math.min(this.maxHeight,i));break}}};e.prototype.align=function(){var e;var t=c.querySelectorAll(this.results_selector);var n=t.length;var r=null;var i=null;var o=[];for(e=0;e<n;e++){i=t[e];if(i.previousElementSibling!==r&&o.length>0){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<i;e++){t=r[e].querySelector(this.img_selector);if(t!==null&&t!==undefined){t.addEventListener("load",a);t.addEventListener("error",a);if(s.searxng.theme.img_load_error){t.addEventListener("error",o,{once:true})}}}};s.searxng.ImageLayout=e})(window,document);(function(e){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=e()}else if(typeof define==="function"&&define.amd){define([],e)}else{var t;if(typeof window!=="undefined"){t=window}else if(typeof global!=="undefined"){t=global}else if(typeof self!=="undefined"){t=self}else{t=this}t.AutoComplete=e()}})(function(){var e,t,n;return function(){function c(o,a,s){function l(n,e){if(!a[n]){if(!o[n]){var t="function"==typeof require&&require;if(!e&&t)return t(n,!0);if(u)return u(n,!0);var r=new Error("Cannot find module '"+n+"'");throw r.code="MODULE_NOT_FOUND",r}var i=a[n]={exports:{}};o[n][0].call(i.exports,function(e){var t=o[n][1][e];return l(t||e)},i,i.exports,c,o,a,s)}return a[n].exports}for(var u="function"==typeof require&&require,e=0;e<s.length;e++)l(s[e]);return l}return c}()({1:[function(e,t,n){
2021-10-01 16:07:27 +00:00
/*
* @license MIT
*
* Autocomplete.js v2.7.1
* Developed by Baptiste Donaux
* http://autocomplete-js.com
*
* (c) 2017, Baptiste Donaux
*/
2021-11-30 11:43:18 +00:00
"use strict";var l;(function(e){e[e["AND"]=0]="AND";e[e["OR"]=1]="OR"})(l||(l={}));var o;(function(e){e[e["KEYDOWN"]=0]="KEYDOWN";e[e["KEYUP"]=1]="KEYUP"})(o||(o={}));var r=function(){function s(t,e){if(t===void 0){t={}}if(e===void 0){e="[data-autocomplete]"}if(Array.isArray(e)){e.forEach(function(e){new s(t,e)})}else if(typeof e=="string"){var n=document.querySelectorAll(e);Array.prototype.forEach.call(n,function(e){new s(t,e)})}else{var r=s.merge(s.defaults,t,{DOMResults:document.createElement("div")});s.prototype.create(r,e);return r}}s.prototype.create=function(e,t){e.Input=t;if(e.Input.nodeName.match(/^INPUT$/i)&&(e.Input.hasAttribute("type")===false||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:s.prototype.destroy.bind(null,e),focus:e._Focus.bind(e),keyup:s.prototype.event.bind(null,e,o.KEYUP),keydown:s.prototype.event.bind(null,e,o.KEYDOWN),position:e._Position.bind(e)};for(var n in e.$Listeners){e.Input.addEventListener(n,e.$Listeners[n])}}};s.prototype.getEventsByType=function(e,t){var n={};for(var r in e.KeyboardMappings){var i=o.KEYUP;if(e.KeyboardMappings[r].Event!==undefined){i=e.KeyboardMappings[r].Event}if(i==t){n[r]=e.KeyboardMappings[r]}}return n};s.prototype.event=function(e,t,n){var r=function(e){if(a===true&&o.Operator==l.AND||a===false&&o.Operator==l.OR){e=s.merge({Not:false},e);if(e.hasOwnProperty("Is")){if(e.Is==n.keyCode){a=!e.Not}else{a=e.Not}}else if(e.hasOwnProperty("From")&&e.hasOwnProperty("To")){if(n.keyCode>=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<arguments.length;n++){for(t in arguments[n]){e[t]=arguments[n][t]}}return e};s.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: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.que
2021-10-01 16:07:27 +00:00
//# sourceMappingURL=searxng.min.js.map