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

40 lines
28 KiB
JavaScript
Raw Normal View History

2021-10-01 18:07:27 +02: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
*/
2022-02-20 19:46:51 +01: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(r,i,o=null){return new Promise(function(e,t){try{var n=new XMLHttpRequest;n.open(r,i,true);n.timeout=2e4;n.onload=function(){if(n.status==200){e(n.response,n.responseType)}else{t(Error(n.statusText))}};n.onerror=function(){t(Error("Network Error"))};n.onabort=function(){t(Error("Transaction is aborted"))};n.ontimeout=function(){t(Error("Timeout"))};if(o){n.send(o)}else{n.send()}}catch(e){t(e)}})};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")});function e(){for(var e of o.getElementsByTagName("body")[0].classList.values()){if(e.endsWith("_endpoint")){return e.split("_")[0]}}return""}s.endpoint=e();return s}(window,document);searxng.ready(function(){"use strict";searxng.infinite_scroll_supported="IntersectionObserver"in window&&"IntersectionObserverEntry"in window&&"intersectionRatio"in window.IntersectionObserverEntry.prototype;if(searxng.endpoint!=="results"){return}if(!searxng.infinite_scroll_supported){console.log("IntersectionObserver not supported");return}let o=document;var a=o.getElementById("results").classList.contains("only_template_images");function n(){var e=o.createElement("div");e.classList.add("loader");return e}function r(t,e){t.textContent="";e.forEach(e=>t.appendChild(e))}function i(i){var e=o.querySelector("#pagination form.next_page");if(!e){return}r(o.querySelector("#pagination"),[n()]);var t=new FormData(e);searxng.http("POST",o.querySelector("#search").getAttribute("action"),t).then(function(e){var t=(new DOMParser).parseFromString(e,"text/html");var n=t.querySelectorAll("#urls article");var r=t.querySelector("#pagination");o.querySelector("#pagination").remove();if(n.length>0&&!a){o.querySelector("#urls").appendChild(o.createElement("hr"))}n.forEach(e=>{o.querySelector("#urls").appendChild(e)});if(r){o.querySelector("#results").appendChild(r);i()}}).catch(function(e){console.log(e);var t=o.createElement("div");t.textContent=searxng.translations.error_loading_next_page;t.classList.add("dialog-error");t.setAttribute("role","alert");r(o.querySelector("#pagination"),[t])})}if(searxng.infinite_scroll&&searxng.infinite_scroll_supported){const s={rootMargin:"20rem"};const l="article.result:last-child";const u=new IntersectionObserver(e=>{const t=e[0];if(t.isIntersecting){u.unobserve(t.target);i(()=>u.observe(o.querySelector(l),s))}});u.observe(o.querySelector(l),s)}});searxng.ready(function(){function e(e){while(e!==undefined){if(e.classList.contains("detail")){return true}if(e.classList.contains("result")){return false
2021-10-01 18:07:27 +02: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 12:43:18 +01: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 18:07:27 +02:00
*/
2022-02-20 19:46:51 +01:00
(function(a,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.trottleCallToAlign=null;this.alignAfterThrotteling=false}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.setAttribute("width",Math.round(i));r.setAttribute("height",Math.round(t));r.style.marginLeft=Math.round(this.horizontalMargin)+"px";r.style.marginTop=Math.round(this.horizontalMargin)+"px";r.style.marginRight=Math.round(this.verticalMargin-7)+"px";r.style.marginBottom=Math.round(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.throttleAlign=function(){var e=this;if(e.trottleCallToAlign){e.alignAfterThrotteling=true}else{e.alignAfterThrotteling=false;e.align();e.trottleCallToAlign=setTimeout(function(){if(e.alignAfterThrotteling){e.align()}e.alignAfterThrotteling=false;e.trottleCallToAlign=null},20)}};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._monitorImages=function(){var e,t;var n=this.throttleAlign.bind(this);var r=c.querySelectorAll(this.results_selector);var i=r.length;function o(e){e.originalTarget.src=a.searxng.static_path+a.searxng.theme.img_load_error}for(e=0;e<i;e++){t=r[e].querySelector(this.img_selector);if(t!==null&&t!==undefined&&!t.classList.contains("aligned")){t.addEventListener("load",n);t.addEventListener("error",n);t.addEventListener("timeout",n);if(a.searxng.theme.img_load_error){t.addEventListener("error",o,{once:true})}t.classList.add("aligned")}}};e.prototype.watch=function(){var e=this.throttleAlign.bind(this);a.addEventListener("pageshow",e);a.addEventListener("load",e);a.addEventListener("resize",e);this._monitorImages();var r=this;let t=new MutationObserver(t=>{let n=false;for(let e=0;e<t.length;e++){if(t[e].addedNodes.length>0&&t[e].addedNodes[0].classList.contains("result")){n=true;break}}if(n){r._monitorImages()}});t.observe(c.querySelector(this.container_selector),{childList:true,subtree:true,attributes:false,characterData:false})};a.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 18:07:27 +02:00
/*
* @license MIT
*
* Autocomplete.js v2.7.1
* Developed by Baptiste Donaux
* http://autocomplete-js.com
*
* (c) 2017, Baptiste Donaux
*/
2022-02-20 19:46:51 +01: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 18:07:27 +02:00
//# sourceMappingURL=searxng.min.js.map