1
0
mirror of https://github.com/searxng/searxng.git synced 2024-11-19 10:50:09 +01:00
searxng/searx/static/themes/simple/js/searx.min.js

23 lines
22 KiB
JavaScript
Raw Normal View History

/*! simple/searx.min.js | 03-12-2017 | https://github.com/asciimoo/searx */
2017-02-12 15:06:01 +01:00
!function(t,e,n){"use strict";function o(t,e,n){try{t.call(e,n)}catch(t){console.log(t)}}t.Element&&function(t){t.matches=t.matches||t.matchesSelector||t.webkitMatchesSelector||t.msMatchesSelector||function(t){for(var e=this,n=(e.parentNode||e.document).querySelectorAll(t),o=-1;n[++o]&&n[o]!=e;);return!!n[o]}}(Element.prototype),n=n||{},n.on=function(t,n,a,i){i=i||!1,"string"!=typeof t?t.addEventListener(n,a,i):e.addEventListener(n,function(n){for(var i=n.target||n.srcElement,r=!1;i&&i.matches&&i!==e&&!(r=i.matches(t));)i=i.parentElement;r&&o(a,i,n)},i)},n.ready=function(e){"loading"!=document.readyState?e.call(t):t.addEventListener("DOMContentLoaded",e.bind(t))},n.http=function(t,e,n){var o=new XMLHttpRequest,a=function(){},i=function(){},r={then:function(t){return a=t,r},catch:function(t){return i=t,r}};try{o.open(t,e,!0),o.onload=function(){200==o.status?a(o.response,o.responseType):i(Error(o.statusText))},o.onerror=function(){i(Error("Network Error"))},o.onabort=function(){i(Error("Transaction is aborted"))},o.send()}catch(t){i(t)}return r},n.loadStyle=function(t){var o=n.staticPath+t,a="style_"+t.replace(".","_"),i=e.getElementById(a);null===i&&((i=e.createElement("link")).setAttribute("id",a),i.setAttribute("rel","stylesheet"),i.setAttribute("type","text/css"),i.setAttribute("href",o),e.body.appendChild(i))},n.loadScript=function(t,o){var a=n.staticPath+t,i="script_"+t.replace(".","_"),r=e.getElementById(i);if(null===r)(r=e.createElement("script")).setAttribute("id",i),r.setAttribute("src",a),r.onload=o,r.onerror=function(){r.setAttribute("error","1")},e.body.appendChild(r);else if(r.hasAttribute("error"))console.log("callback not executed : script '"+a+"' not loaded.");else try{o.apply(r,[])}catch(t){console.log(t)}},n.on(".close","click",function(t){t.target||t.srcElement;this.parentNode.style.display="None"})}(window,document,window.searx),function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).AutoComplete=t()}}(function(){return function t(e,n,o){function a(r,s){if(!n[r]){if(!e[r]){var l="function"==typeof require&&require;if(!s&&l)return l(r,!0);if(i)return i(r,!0);var u=new Error("Cannot find module '"+r+"'");throw u.code="MODULE_NOT_FOUND",u}var c=n[r]={exports:{}};e[r][0].call(c.exports,function(t){var n=e[r][1][t];return a(n||t)},c,c.exports,t,e,n,o)}return n[r].exports}for(var i="function"==typeof require&&require,r=0;r<o.length;r++)a(o[r]);return a}({1:[function(t,e,n){/*
* @license MIT
*
* Autocomplete.js v2.6.3
* Developed by Baptiste Donaux
* http://autocomplete-js.com
*
* (c) 2017, Baptiste Donaux
*/
"use strict";var o;!function(t){t[t.AND=0]="AND",t[t.OR=1]="OR"}(o||(o={}));var a;!function(t){t[t.KEYDOWN=0]="KEYDOWN",t[t.KEYUP=1]="KEYUP"}(a||(a={}));var i=function(){function t(e,n){if(void 0===e&&(e={}),void 0===n&&(n="[data-autocomplete]"),Array.isArray(n))n.forEach(function(n){new t(e,n)});else{if("string"!=typeof n){var o=t.merge(t.defaults,e,{DOMResults:document.createElement("div")});return t.prototype.create(o,n),o}var a=document.querySelectorAll(n);Array.prototype.forEach.call(a,function(n){new t(e,n)})}}return t.prototype.create=function(e,n){if(e.Input=n,e.Input.nodeName.match(/^INPUT$/i)&&(!1===e.Input.hasAttribute("type")||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:t.prototype.destroy.bind(null,e),focus:e._Focus.bind(e),keyup:t.prototype.event.bind(null,e,a.KEYUP),keydown:t.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])}},t.prototype.getEventsByType=function(t,e){var n={};for(var o in t.KeyboardMappings){var i=a.KEYUP;void 0!==t.KeyboardMappings[o].Event&&(i=t.KeyboardMappings[o].Event),i==e&&(n[o]=t.KeyboardMappings[o])}return n},t.prototype.event=function(e,n,a){for(var i in t.prototype.getEventsByType(e,n)){var r=t.merge({Operator:o.AND},e.KeyboardMappings[i]),s=o.AND==r.Operator;r.Conditions.forEach(function(e){(!0===s&&r.Operator==o.AND||!1===s&&r.Operator==o.OR)&&((e=t.merge({Not:!1},e)).hasOwnProperty("Is")?s=e.Is==a.keyCode?!e.Not:e.Not:e.hasOwnProperty("From")&&e.hasOwnProperty("To")&&(s=a.keyCode>=e.From&&a.keyCode<=e.To?!e.Not:e.Not))}),!0===s&&r.Callback.call(e,a)}},t.prototype.makeRequest=function(t,e){var n=Object.getOwnPropertyNames(t.HttpHeaders),o=new XMLHttpRequest,a=t._HttpMethod(),i=t._Url(),r=t._Pre(),s=encodeURIComponent(t._QueryArg())+"="+encodeURIComponent(r);a.match(/^GET$/i)&&(-1!==i.indexOf("?")?i+="&"+s:i+="?"+s),o.open(a,i,!0);for(var l=n.length-1;l>=0;l--)o.setRequestHeader(n[l],t.HttpHeaders[n[l]]);return o.onreadystatechange=function(){4==o.readyState&&200==o.status&&(t.$Cache[r]=o.response,e(o.response))},o},t.prototype.ajax=function(e,n,o){void 0===o&&(o=!0),e.$AjaxTimer&&window.clearTimeout(e.$AjaxTimer),!0===o?e.$AjaxTimer=window.setTimeout(t.prototype.ajax.bind(null,e,n,!1),e.Delay):(e.Request&&e.Request.abort(),e.Request=n,e.Request.send(e._QueryArg()+"="+e._Pre()))},t.prototype.cache=function(e,n){var o=e._Cache(e._Pre());if(void 0===o){var a=t.prototype.makeRequest(e,n);t.prototype.ajax(e,a)}else n(o)},t.prototype.destroy=function(t){for(var e in t.$Listeners)t.Input.removeEventListener(e,t.$Listeners[e]);t.DOMResults.parentNode.removeChild(t.DOMResults)},t}();i.merge=function(){for(var t,e={},n=0;n<arguments.length;n++)for(t in arguments[n])e[t]=arguments[n][t];return e},i.defaults={Delay:150,EmptyMessage:"No result here",Highlight:{getRegex:function(t){return new RegExp(t,"ig")},transform:function(t){return"<strong>"+t+"</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(t){if(-1!=this.DOMResults.getAttribute("class").indexOf("open")){var e=this.DOMResults.querySelector("li.active");null!==e&&(t.preventDefault(),this._Select(e),this.DOMResults.setAttribute("class","autocomplete"))}},Operator:o.AND,Event:a.KEYDOWN},KeyUpAndDown_down:{Conditions:[{Is:38,Not:!1},{Is:40,Not:!1}],Callback:function(t){t.preventDefault()},Operator:o.OR,Event:a.KEYDOWN},KeyUpAndDown_up:{Conditions:[{Is:38,Not:!1},{Is:40,Not:!1}],Callback:function(t){t.preventDefault();var e=this.DOMResults.querySelector("li:first-child:not(.locked)"),n=this.DOMResults.querySelector("li:last-child:not(.locked)"),o=this.DOMResults.querySelector("li.active");if(o){var a=Array.prototype.indexOf.call(o.parentNode.children,o)+(t.keyCode-39),i=this.DOMResults.getElementsByTagName("li").length;a<0?a=i-1:a>=i&&(a=0)
*
* 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(t,e){"use strict";function n(t,e,n,o){this.container_selector=t,this.results_selector=e,this.img_selector=n,this.margin=10,this.maxHeight=o,this._alignAllDone=!0}n.prototype._getHeigth=function(t,e){var n,o=0;e-=t.length*this.margin;for(var a=0;a<t.length;a++)(n=t[a]).naturalWidth>0&&n.naturalHeight>0?o+=n.naturalWidth/n.naturalHeight:o+=1;return e/o},n.prototype._setSize=function(t,e){for(var n,o,a=t.length,i=0;i<a;i++)o=(n=t[i]).naturalWidth>0&&n.naturalHeight>0?e*n.naturalWidth/n.naturalHeight:e,n.style.width=o+"px",n.style.height=e+"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(t){var n,o,a=e.querySelector(this.container_selector).clientWidth;t:for(;t.length>0;){for(var i=1;i<=t.length;i++)if(n=t.slice(0,i),(o=this._getHeigth(n,a))<this.maxHeight){this._setSize(n,o),t=t.slice(i);continue t}this._setSize(n,Math.min(this.maxHeight,o));break}},n.prototype.align=function(t){for(var n=e.querySelectorAll(this.results_selector),o=n.length,a=null,i=null,r=[],s=0;s<o;s++)(i=n[s]).previousElementSibling!==a&&r.length>0&&(this._alignImgs(r),r=[]),r.push(i.querySelector(this.img_selector)),a=i;r.length>0&&this._alignImgs(r)},n.prototype.watch=function(){function n(t){i._alignAllDone&&(i._alignAllDone=!1,setTimeout(function(){i.align(),i._alignAllDone=!0},100))}var o,a,i=this,r=e.querySelectorAll(this.results_selector),s=r.length;for(t.addEventListener("resize",n),t.addEventListener("pageshow",function(t){i.align()}),o=0;o<s;o++)void 0!==(a=r[o].querySelector(this.img_selector))&&(a.addEventListener("load",n),a.addEventListener("error",n))},t.searx.ImageLayout=n}(window,document),searx.ready(function(){function t(t){return function(e){var o=document.querySelector(".result[data-vim-selected]"),a=t;if(null===o){if(null===(o=document.querySelector(".result")))return;"down"!==t&&"up"!==t||(a=o)}var i,r=document.querySelectorAll(".result");if("string"!=typeof a)i=a;else switch(a){case"visible":for(var s=document.documentElement.scrollTop||document.body.scrollTop,l=s+document.documentElement.clientHeight,u=0;u<r.length;u++){var c=(i=r[u]).offsetTop;if(c+i.clientHeight<=l&&c>s)break}break;case"down":null===(i=o.nextElementSibling)&&(i=r[0]);break;case"up":null===(i=o.previousElementSibling)&&(i=r[r.length-1]);break;case"bottom":i=r[r.length-1];break;case"top":default:i=r[0]}if(i){o.removeAttribute("data-vim-selected"),i.setAttribute("data-vim-selected","true");var d=i.querySelector("h3 a")||i.querySelector("a");null!==d&&d.focus(),e||n()}}}function e(t){return function(){var e=$('div#pagination button[type="submit"]');2===e.length?t>=0&&t<e.length?e[t].click():console.log("pageButtonClick(): invalid argument"):console.log("page navigation with this theme is not supported")}}function n(){var t=document.querySelector(".result[data-vim-selected]");if(null!==t){var e=document.documentElement.scrollTop||document.body.scrollTop,n=document.documentElement.clientHeight,o=t.offsetTop,a=o+t.clientHeight;null===t.previousElementSibling&&a<n?window.scroll(window.scrollX,0):e>o-120?window.scroll(window.scrollX,o-120):e+n<a+120&&window.scroll(window.scrollX,a-n+120)}}function o(e){return function(){window.scrollBy(0,e),t("visible")()}}function a(e,n){return function(){window.scrollTo(0,e),t(n)()}}function i(t){return function(){var e=document.querySelector(".result[data-vim-selected] h3 a");if(null!==e){var n=e.getAttribute("href");t?window.open(n):window.location.href=n}}}searx.on(".result","click",function(){t(this)(!0)}),searx.on(".result a","focus",function(e){for(var n=e.target;void 0!==n;){if(n.classList.contains("result")){null===n.getAttribute("data-vim-selected")&&t(n)(!0);break}n=n.parentNode}},!0);var r={27:{key:"Escape",fun:function(){document.activeElement&&document.activeElement.blur()},des:"remove focus from the focused input",cat:"Control"},73:{key:"i",fun:function(){window.scrollTo(0,0),document.querySelector("#q").focus()},des:"focus on the search input",cat:"Control"},66:{key:"b",fun:o(-window.innerHeight
2017-02-12 15:06:01 +01:00
//# sourceMappingURL=searx.min.js.map