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

23 lines
23 KiB
JavaScript
Raw Normal View History

/*! simple/searx.min.js | 14-08-2018 | https://github.com/asciimoo/searx */
2017-02-12 15:06:01 +01:00
(function(e,t,n){"use strict";if(e.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 i(e,t,n){try{e.call(t,n)}catch(e){console.log(e)}}n=n||{};n.on=function(e,n,r,a){a=a||false;if(typeof e!=="string"){e.addEventListener(n,r,a)}else{t.addEventListener(n,function(n){var a=n.target||n.srcElement,o=false;while(a&&a.matches&&a!==t&&!(o=a.matches(e)))a=a.parentElement;if(o)i(r,a,n)},a)}};n.ready=function(t){if(document.readyState!="loading"){t.call(e)}else{e.addEventListener("DOMContentLoaded",t.bind(e))}};n.http=function(e,t,n){var i=new XMLHttpRequest,r=function(){},a=function(){},o={then:function(e){r=e;return o},catch:function(e){a=e;return o}};try{i.open(e,t,true);i.onload=function(){if(i.status==200){r(i.response,i.responseType)}else{a(Error(i.statusText))}};i.onerror=function(){a(Error("Network Error"))};i.onabort=function(){a(Error("Transaction is aborted"))};i.send()}catch(e){a(e)}return o};n.loadStyle=function(e){var i=n.staticPath+e,r="style_"+e.replace(".","_"),a=t.getElementById(r);if(a===null){a=t.createElement("link");a.setAttribute("id",r);a.setAttribute("rel","stylesheet");a.setAttribute("type","text/css");a.setAttribute("href",i);t.body.appendChild(a)}};n.loadScript=function(e,i){var r=n.staticPath+e,a="script_"+e.replace(".","_"),o=t.getElementById(a);if(o===null){o=t.createElement("script");o.setAttribute("id",a);o.setAttribute("src",r);o.onload=i;o.onerror=function(){o.setAttribute("error","1")};t.body.appendChild(o)}else if(!o.hasAttribute("error")){try{i.apply(o,[])}catch(e){console.log(e)}}else{console.log("callback not executed : script '"+r+"' not loaded.")}};n.insertBefore=function(e,t){element.parentNode.insertBefore(e,t)};n.insertAfter=function(e,t){t.parentNode.insertBefore(e,t.nextSibling)};n.on(".close","click",function(e){var t=e.target||e.srcElement;this.parentNode.classList.add("invisible")});return n})(window,document,window.searx);(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 e(t,n,i){function r(o,s){if(!n[o]){if(!t[o]){var l=typeof require=="function"&&require;if(!s&&l)return l(o,!0);if(a)return a(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var c=n[o]={exports:{}};t[o][0].call(c.exports,function(e){var n=t[o][1][e];return r(n?n:e)},c,c.exports,e,t,n,i)}return n[o].exports}var a=typeof require=="function"&&require;for(var o=0;o<i.length;o++)r(i[o]);return r}({1:[function(e,t,n){/*
* @license MIT
*
* Autocomplete.js v2.6.3
* Developed by Baptiste Donaux
* http://autocomplete-js.com
*
* (c) 2017, Baptiste Donaux
*/
"use strict";var i;(function(e){e[e["AND"]=0]="AND";e[e["OR"]=1]="OR"})(i||(i={}));var r;(function(e){e[e["KEYDOWN"]=0]="KEYDOWN";e[e["KEYUP"]=1]="KEYUP"})(r||(r={}));var a=function(){function e(t,n){if(t===void 0){t={}}if(n===void 0){n="[data-autocomplete]"}if(Array.isArray(n)){n.forEach(function(n){new e(t,n)})}else if(typeof n=="string"){var i=document.querySelectorAll(n);Array.prototype.forEach.call(i,function(n){new e(t,n)})}else{var r=e.merge(e.defaults,t,{DOMResults:document.createElement("div")});e.prototype.create(r,n);return r}}e.prototype.create=function(t,n){t.Input=n;if(t.Input.nodeName.match(/^INPUT$/i)&&(t.Input.hasAttribute("type")===false||t.Input.getAttribute("type").match(/^TEXT|SEARCH$/i))){t.Input.setAttribute("autocomplete","off");t._Position(t);t.Input.parentNode.appendChild(t.DOMResults);t.$Listeners={blur:t._Blur.bind(t),destroy:e.prototype.destroy.bind(null,t),focus:t._Focus.bind(t),keyup:e.prototype.event.bind(null,t,r.KEYUP),keydown:e.prototype.event.bind(null,t,r.KEYDOWN),position:t._Position.bind(t)};for(var i in t.$Listeners){t.Input.addEventListener(i,t.$Listeners[i])}}};e.prototype.getEventsByType=function(e,t){var n={};for(var i in e.KeyboardMappings){var a=r.KEYUP;if(e.KeyboardMappings[i].Event!==undefined){a=e.KeyboardMappings[i].Event}if(a==t){n[i]=e.KeyboardMappings[i]}}return n};e.prototype.event=function(t,n,r){var a=function(t){if(l===true&&s.Operator==i.AND||l===false&&s.Operator==i.OR){t=e.merge({Not:false},t);if(t.hasOwnProperty("Is")){if(t.Is==r.keyCode){l=!t.Not}else{l=t.Not}}else if(t.hasOwnProperty("From")&&t.hasOwnProperty("To")){if(r.keyCode>=t.From&&r.keyCode<=t.To){l=!t.Not}else{l=t.Not}}}};for(var o in e.prototype.getEventsByType(t,n)){var s=e.merge({Operator:i.AND},t.KeyboardMappings[o]),l=i.AND==s.Operator;s.Conditions.forEach(a);if(l===true){s.Callback.call(t,r)}}};e.prototype.makeRequest=function(e,t){var n=Object.getOwnPropertyNames(e.HttpHeaders),i=new XMLHttpRequest,r=e._HttpMethod(),a=e._Url(),o=e._Pre(),s=encodeURIComponent(e._QueryArg())+"="+encodeURIComponent(o);if(r.match(/^GET$/i)){if(a.indexOf("?")!==-1){a+="&"+s}else{a+="?"+s}}i.open(r,a,true);for(var l=n.length-1;l>=0;l--){i.setRequestHeader(n[l],e.HttpHeaders[n[l]])}i.onreadystatechange=function(){if(i.readyState==4&&i.status==200){e.$Cache[o]=i.response;t(i.response)}};return i};e.prototype.ajax=function(t,n,i){if(i===void 0){i=true}if(t.$AjaxTimer){window.clearTimeout(t.$AjaxTimer)}if(i===true){t.$AjaxTimer=window.setTimeout(e.prototype.ajax.bind(null,t,n,false),t.Delay)}else{if(t.Request){t.Request.abort()}t.Request=n;t.Request.send(t._QueryArg()+"="+t._Pre())}};e.prototype.cache=function(t,n){var i=t._Cache(t._Pre());if(i===undefined){var r=e.prototype.makeRequest(t,n);e.prototype.ajax(t,r)}else{n(i)}};e.prototype.destroy=function(e){for(var t in e.$Listeners){e.Input.removeEventListener(t,e.$Listeners[t])}e.DOMResults.parentNode.removeChild(e.DOMResults)};return e}();a.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};a.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:i.AND,Event:r.KEYDOWN},KeyUpAndDown_down:{Conditions:[{Is:38,Not:false},{Is:40,Not:false}],Callback:function(e){e.preventDefault()},Operator:i.OR,Event:r.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
*
* Google Image Layout v0.0.1
* Description, by Anh Trinh.
* Heavily modified for searx
* http://trinhtrunganh.com
*
* @license Free to use under the MIT License.
*
*/
(function(e,t){"use strict";function n(e,t,n,i){this.container_selector=e;this.results_selector=t;this.img_selector=n;this.margin=10;this.maxHeight=i;this._alignAllDone=true}n.prototype._getHeigth=function(e,t){var n=0,i;t-=e.length*this.margin;for(var r=0;r<e.length;r++){i=e[r];if(i.naturalWidth>0&&i.naturalHeight>0){n+=i.naturalWidth/i.naturalHeight}else{n+=1}}return t/n};n.prototype._setSize=function(e,t){var n,i,r=e.length;for(var a=0;a<r;a++){n=e[a];if(n.naturalWidth>0&&n.naturalHeight>0){i=t*n.naturalWidth/n.naturalHeight}else{i=t}n.style.width=i+"px";n.style.height=t+"px";n.style.marginLeft="3px";n.style.marginTop="3px";n.style.marginRight=this.margin-7+"px";n.style.marginBottom=this.margin-7+"px"}};n.prototype._alignImgs=function(e){var n,i,r=t.querySelector(this.container_selector).clientWidth;e:while(e.length>0){for(var a=1;a<=e.length;a++){n=e.slice(0,a);i=this._getHeigth(n,r);if(i<this.maxHeight){this._setSize(n,i);e=e.slice(a);continue e}}this._setSize(n,Math.min(this.maxHeight,i));break}};n.prototype.align=function(e){var n=t.querySelectorAll(this.results_selector),i=n.length,r=null,a=null,o=[];for(var s=0;s<i;s++){a=n[s];if(a.previousElementSibling!==r&&o.length>0){this._alignImgs(o);o=[]}o.push(a.querySelector(this.img_selector));r=a}if(o.length>0){this._alignImgs(o)}};n.prototype.watch=function(){var n,i,r,a,o=this,s=t.querySelectorAll(this.results_selector),l=s.length;function u(e){o.align()}function c(e){if(o._alignAllDone){o._alignAllDone=false;setTimeout(function(){o.align();o._alignAllDone=true},100)}}e.addEventListener("resize",c);e.addEventListener("pageshow",u);for(n=0;n<l;n++){i=s[n].querySelector(this.img_selector);if(typeof i!=="undefined"){i.addEventListener("load",c);i.addEventListener("error",c)}}};e.searx.ImageLayout=n})(window,document);searx.ready(function(){searx.on(".result","click",function(){t(this)(true)});searx.on(".result a","focus",function(e){var n=e.target;while(n!==undefined){if(n.classList.contains("result")){if(n.getAttribute("data-vim-selected")===null){t(n)(true)}break}n=n.parentNode}},true);var e={27:{key:"Escape",fun:i,des:"remove focus from the focused input",cat:"Control"},73:{key:"i",fun:l,des:"focus on the search input",cat:"Control"},66:{key:"b",fun:o(-window.innerHeight),des:"scroll one page up",cat:"Navigation"},70:{key:"f",fun:o(window.innerHeight),des:"scroll one page down",cat:"Navigation"},85:{key:"u",fun:o(-window.innerHeight/2),des:"scroll half a page up",cat:"Navigation"},68:{key:"d",fun:o(window.innerHeight/2),des:"scroll half a page down",cat:"Navigation"},71:{key:"g",fun:s(-document.body.scrollHeight,"top"),des:"scroll to the top of the page",cat:"Navigation"},86:{key:"v",fun:s(document.body.scrollHeight,"bottom"),des:"scroll to the bottom of the page",cat:"Navigation"},75:{key:"k",fun:t("up"),des:"select previous search result",cat:"Results"},74:{key:"j",fun:t("down"),des:"select next search result",cat:"Results"},80:{key:"p",fun:r(0),des:"go to previous page",cat:"Results"},78:{key:"n",fun:r(1),des:"go to next page",cat:"Results"},79:{key:"o",fun:u(false),des:"open search result",cat:"Results"},84:{key:"t",fun:u(true),des:"open the result in a new tab",cat:"Results"},82:{key:"r",fun:n,des:"reload page from the server",cat:"Control"},72:{key:"h",fun:d,des:"toggle help window",cat:"Other"}};searx.on(document,"keydown",function(t){if(e.hasOwnProperty(t.keyCode)&&!t.ctrlKey&&!t.altKey&&!t.shiftKey&&!t.metaKey){var n=t.target.tagName.toLowerCase();if(t.keyCode===27){if(n==="input"||n==="select"||n==="textarea"){e[t.keyCode].fun()}}else{if(t.target===document.body||n==="a"||n==="button"){t.preventDefault();e[t.keyCode].fun()}}}});function t(e){return function(t){var n=document.querySelector(".result[data-vim-selected]"),i=e;if(n===null){n=document.querySelector(".result");if(n===null){return}if(e==="down"||e==="up"){i=n}}var r,o=document.querySelectorAll(".result");if(typeof i!=="string"){r=i}else{switch(i){case"visible":var s=document.documentElement.scrollTop||document.body.scrollTop;var l=s+document.documentElement.clientHeight;for(var u=0;u<o.length;u++
2017-02-12 15:06:01 +01:00
//# sourceMappingURL=searx.min.js.map