mirror of
https://github.com/searxng/searxng
synced 2024-01-01 19:24:07 +01:00
122 lines
No EOL
16 KiB
JavaScript
122 lines
No EOL
16 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
|
|
*/
|
|
if(window.searxng=function(t){"use strict";t.getElementsByTagName("html")[0].className="js";var e=t.currentScript||(e=t.getElementsByTagName("script"))[e.length-1];return{autocompleter:"true"===e.getAttribute("data-autocompleter"),method:e.getAttribute("data-method"),translations:JSON.parse(e.getAttribute("data-translations")),plugins:JSON.parse(e.getAttribute("data-plugins"))}}(document),
|
|
/**
|
|
* @license
|
|
* (C) Copyright Contributors to the SearXNG project.
|
|
* (C) Copyright Contributors to the searx project (2014 - 2021).
|
|
* (C) 2014 by Thomas Pointhuber, <thomas.pointhuber@gmx.at>
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
$(document).ready(function(){var t,n="";searxng.autocompleter&&((t=new Bloodhound({datumTokenizer:Bloodhound.tokenizers.obj.whitespace("value"),queryTokenizer:Bloodhound.tokenizers.whitespace,remote:{url:"./autocompleter?q=%QUERY",wildcard:"%QUERY"}})).initialize(),$("#q").on("keydown",function(t){13==t.which&&(n=$("#q").val())}),$("#q").typeahead({name:"search-results",highlight:!1,hint:!0,displayKey:function(t){return t},classNames:{input:"tt-input",hint:"tt-hint",menu:"tt-dropdown-menu",dataset:"tt-dataset-search-results"}},{name:"autocomplete",source:t}),$("#q").bind("typeahead:select",function(t,e){n&&$("#q").val(n),$("#search_form").submit()}))}),
|
|
/**
|
|
* @license
|
|
* (C) Copyright Contributors to the SearXNG project.
|
|
* (C) Copyright Contributors to the searx project (2014 - 2021).
|
|
* (C) 2014 by Thomas Pointhuber, <thomas.pointhuber@gmx.at>
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
$(document).ready(function(){$("#q.autofocus").focus(),$("#clear_search").click(function(){document.getElementById("q").value=""}),$(".select-all-on-click").click(function(){$(this).select()}),$(".btn-collapse").click(function(){var t=$(this).data("btn-text-collapsed"),e=$(this).data("btn-text-not-collapsed");""!==t&&""!==e&&(new_html=$(this).hasClass("collapsed")?$(this).html().replace(t,e):$(this).html().replace(e,t),$(this).html(new_html))}),$(".btn-toggle .btn").click(function(){var t="btn-"+$(this).data("btn-class"),e=$(this).data("btn-label-default"),n=$(this).data("btn-label-toggled");""!==n&&(new_html=$(this).hasClass("btn-default")?$(this).html().replace(e,n):$(this).html().replace(n,e),$(this).html(new_html)),$(this).toggleClass(t),$(this).toggleClass("btn-default")}),$(".media-loader").click(function(){var t=$(this).data("target"),e=$(t+" > iframe"),t=e.attr("src");void 0!==t&&!1!==t||e.attr("src",e.data("src"))}),$(".btn-sm").dblclick(function(){var t="btn-"+$(this).data("btn-class");$(this).hasClass("btn-default")?($(".btn-sm > input").attr("checked","checked"),$(".btn-sm > input").prop("checked",!0),$(".btn-sm").addClass(t),$(".btn-sm").addClass("active"),$(".btn-sm").removeClass("btn-default")):($(".btn-sm > input").attr("checked",""),$(".btn-sm > input").removeAttr("checked"),$(".btn-sm > input").checked=!1,$(".btn-sm").removeClass(t),$(".btn-sm").removeClass("active"),$(".btn-sm").addClass("btn-default"))}),$(".nav-tabs").click(function(t){$(t.target).parents("ul").children().attr("aria-selected","false"),$(t.target).parent().attr("aria-selected","true")}),searxng.image_thumbnail_layout=new searxng.ImageLayout("#main_results","#main_results .result-images","img.img-thumbnail",15,3,200),searxng.image_thumbnail_layout.watch()}),
|
|
/**
|
|
* @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.addEventListener("load",function(){$(".infobox").each(function(){var t=$(this).find(".infobox_body");t.prop("scrollHeight")+t.find("img.infobox_part").height()<=t.css("max-height").replace("px","")&&$(this).find(".infobox_toggle").hide()})}),
|
|
/**
|
|
* @license
|
|
* (C) Copyright Contributors to the SearXNG project.
|
|
* (C) Copyright Contributors to the searx project (2014 - 2021).
|
|
* (C) 2014 by Thomas Pointhuber, <thomas.pointhuber@gmx.at>
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
$(document).ready(function(){$(".searxng_init_map").on("click",function(t){var e=$(this).data("leaflet-target"),n=$(this).data("map-lon"),a=$(this).data("map-lat"),i=$(this).data("map-zoom"),o=$(this).data("map-boundingbox"),s=$(this).data("map-geojson");o&&(southWest=L.latLng(o[0],o[2]),northEast=L.latLng(o[1],o[3]),map_bounds=L.latLngBounds(southWest,northEast)),L.Icon.Default.imagePath="./static/themes/oscar/css/images/";var r=L.map(e),e=new L.TileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",{minZoom:1,maxZoom:19,attribution:'Map data © <a href="https://openstreetmap.org">OpenStreetMap</a> contributors'});new L.TileLayer("https://maps.wikimedia.org/osm-intl/{z}/{x}/{y}.png",{minZoom:1,maxZoom:19,attribution:'Wikimedia maps beta | Maps data © <a href="https://openstreetmap.org">OpenStreetMap</a> contributors'});setTimeout(function(){map_bounds?r.fitBounds(map_bounds,{maxZoom:17}):n&&a&&(i?r.setView(new L.LatLng(a,n),i):r.setView(new L.LatLng(a,n),8))},0),r.addLayer(e),L.control.layers({"OSM Mapnik":e}).addTo(r),s&&L.geoJson(s).addTo(r),$(this).off(t)})}),
|
|
/**
|
|
* @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
|
|
*/
|
|
$(document).ready(function(){let o=null;document.querySelector('body[class="preferences_endpoint"]')&&$("[data-engine-name]").hover(function(){null==o&&$.ajax("engine_descriptions.json",dataType="json").done(function(t){o=t;for(var[e,n]of Object.entries(t))for(const i of $('[data-engine-name="'+e+'"] .description')){var a=" (<i>"+searxng.translations.Source+": "+n[1]+"</i>)";i.innerHTML=n[0]+a}})})}),
|
|
/**
|
|
* @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
|
|
*/
|
|
$(document).ready(function(){$("#allow-all-engines").click(function(){$(".onoffswitch-checkbox").each(function(){this.checked=!1})}),$("#disable-all-engines").click(function(){$(".onoffswitch-checkbox").each(function(){this.checked=!0})})}),
|
|
/**
|
|
*
|
|
* 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.
|
|
*
|
|
* @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();
|
|
*/
|
|
function(r,c){function t(t,e,n,a,i,o){this.container_selector=t,this.results_selector=e,this.img_selector=n,this.verticalMargin=a,this.horizontalMargin=i,this.maxHeight=o,this.isAlignDone=!0}t.prototype._getHeigth=function(t,e){for(var n,a=0,i=0;i<t.length;i++)0<(n=t[i]).naturalWidth&&0<n.naturalHeight?a+=n.naturalWidth/n.naturalHeight:a+=1;return(e-t.length*this.verticalMargin)/a},t.prototype._setSize=function(t,e){for(var n,a,i=t.length,o=0;o<i;o++)n=0<(a=t[o]).naturalWidth&&0<a.naturalHeight?e*a.naturalWidth/a.naturalHeight:e,a.style.width=n+"px",a.style.height=e+"px",a.style.marginLeft=this.horizontalMargin+"px",a.style.marginTop=this.horizontalMargin+"px",a.style.marginRight=this.verticalMargin-7+"px",a.style.marginBottom=this.verticalMargin-7+"px",(a=a.parentNode.parentNode).classList.contains("js")||a.classList.add("js")},t.prototype._alignImgs=function(t){for(var e,n,a,i,o=c.querySelector(this.container_selector),s=window.getComputedStyle(o),r=parseInt(s.getPropertyValue("padding-left"),10),s=parseInt(s.getPropertyValue("padding-right"),10),l=o.clientWidth-r-s;0<t.length;){for(e=!0,a=1;a<=t.length&&e;a++)n=t.slice(0,a),(i=this._getHeigth(n,l))<this.maxHeight&&(this._setSize(n,i),t=t.slice(a),e=!1);if(e){this._setSize(n,Math.min(this.maxHeight,i));break}}},t.prototype.align=function(){for(var t=c.querySelectorAll(this.results_selector),e=t.length,n=null,a=null,i=[],o=0;o<e;o++)(a=t[o]).previousElementSibling!==n&&0<i.length&&(this._alignImgs(i),i=[]),i.push(a.querySelector(this.img_selector)),n=a;0<i.length&&this._alignImgs(i)},t.prototype.watch=function(){var t,e,n=this,a=c.querySelectorAll(this.results_selector),i=a.length;function o(t){t.originalTarget.src=r.searxng.static_path+r.searxng.theme.img_load_error}function s(){n.isAlignDone&&(n.isAlignDone=!1,setTimeout(function(){n.align(),n.isAlignDone=!0},100))}for(r.addEventListener("pageshow",s),r.addEventListener("load",s),r.addEventListener("resize",s),t=0;t<i;t++)null!=(e=a[t].querySelector(this.img_selector))&&(e.addEventListener("load",s),e.addEventListener("error",s),r.searxng.theme.img_load_error&&e.addEventListener("error",o,{once:!0}))},r.searxng.ImageLayout=t}(window,document),searxng.plugins["searx.plugins.infinite_scroll"]){function hasScrollbar(){var t="BackCompat"==document.compatMode?document.body:document.documentElement;return t.scrollHeight>t.clientHeight}function loadNextPage(){var t=$("#pagination form:last").serialize();t&&($("#pagination").html('<div class="loading-spinner"></div>'),$.ajax({type:"POST",url:$("#search_form").prop("action"),data:t,dataType:"html",success:function(t){t=$(t);$("#pagination").remove(),$("#main_results").append("<hr/>"),$("#main_results").append(t.find(".result")),$("#main_results").append(t.find("#pagination")),hasScrollbar()||loadNextPage()}}))}$(document).ready(function(){var t=$(window);hasScrollbar()||loadNextPage(),t.scroll(function(){$("#pagination button").css("visibility","hidden"),$(document).height()-t.height()-t.scrollTop()<150&&loadNextPage()})});const Na=document.createElement("style");Na.textContent=`
|
|
@keyframes rotate-forever {
|
|
0% { transform: rotate(0deg) }
|
|
100% { transform: rotate(360deg) }
|
|
}
|
|
.loading-spinner {
|
|
animation-duration: 0.75s;
|
|
animation-iteration-count: infinite;
|
|
animation-name: rotate-forever;
|
|
animation-timing-function: linear;
|
|
height: 30px;
|
|
width: 30px;
|
|
border: 8px solid #666;
|
|
border-right-color: transparent;
|
|
border-radius: 50% !important;
|
|
margin: 0 auto;
|
|
}
|
|
#pagination button {
|
|
visibility: hidden;
|
|
}
|
|
`,document.head.append(Na)}function getHttpRequest(){return httpRequest="POST",urlParams=new URLSearchParams(window.location.search),urlParams.has("method")&&(httpRequest=urlParams.get("method")),httpRequest}if(searxng.plugins["searx.plugins.search_on_category_select"]&&$(document).ready(function(){$("#q").length&&($("#categories label").click(function(t){return $('#categories input[type="checkbox"]').each(function(t,e){$(e).prop("checked",!1)}),$(document.getElementById($(this).attr("for"))).prop("checked",!0),$("#q").val()&&("GET"==getHttpRequest()&&$("#search_form").attr("action",$("#search_form").serialize()),$("#search_form").submit()),!1}),$("#time-range").change(function(t){$("#q").val()&&("GET"==getHttpRequest()&&$("#search_form").attr("action",$("#search_form").serialize()),$("#search_form").submit())}),$("#language").change(function(t){$("#q").val()&&("GET"==getHttpRequest()&&$("#search_form").attr("action",$("#search_form").serialize()),$("#search_form").submit())}))}),searxng.plugins["searx.plugins.vim_hotkeys"]){$(document).ready(function(){n("top")(),$(".result").on("click",function(){n($(this))()});var u={27:{key:"Escape",fun:function(){document.activeElement&&document.activeElement.blur()},des:"remove focus from the focused input",cat:"Control"},73:{key:"i",fun:function(){$("input#q").focus()},des:"focus on the search input",cat:"Control"},66:{key:"b",fun:e(-window.innerHeight),des:"scroll one page up",cat:"Navigation"},70:{key:"f",fun:e(window.innerHeight),des:"scroll one page down",cat:"Navigation"},85:{key:"u",fun:e(-window.innerHeight/2),des:"scroll half a page up",cat:"Navigation"},68:{key:"d",fun:e(window.innerHeight/2),des:"scroll half a page down",cat:"Navigation"},71:{key:"g",fun:a(-document.body.scrollHeight,"top"),des:"scroll to the top of the page",cat:"Navigation"},86:{key:"v",fun:a(document.body.scrollHeight,"bottom"),des:"scroll to the bottom of the page",cat:"Navigation"},75:{key:"k",fun:n("up"),des:"select previous search result",cat:"Results"},74:{key:"j",fun:n("down"),des:"select next search result",cat:"Results"},80:{key:"p",fun:t(0),des:"go to previous page",cat:"Results"},78:{key:"n",fun:t(1),des:"go to next page",cat:"Results"},79:{key:"o",fun:i(!1),des:"open search result",cat:"Results"},84:{key:"t",fun:i(!0),des:"open the result in a new tab",cat:"Results"},82:{key:"r",fun:function(){document.location.reload(!1)},des:"reload page from the server",cat:"Control"},72:{key:"h",fun:function(){var t=$("#vim-hotkeys-help");if(t.length)t.toggleClass("hidden");else{var e,n={};for(e in u){var a=u[e];n[a.cat]=n[a.cat]||[],n[a.cat].push(a)}var i=Object.keys(n).sort(function(t,e){return n[e].length-n[t].length});if(0!==i.length){var o='<div id="vim-hotkeys-help" class="well vim-hotkeys-help">';o+='<div class="container-fluid">',o+='<div class="row">',o+='<div class="col-sm-12">',o+="<h3>How to navigate searx with Vim-like hotkeys</h3>",o+="</div>",o+="</div>";for(var s=0;s<i.length;s++){var r,l=n[i[s]],c=s===i.length-1,d=s%2==0;for(r in d&&(o+='<div class="row dflex">'),o+='<div class="col-sm-'+(d&&c?12:6)+' dflex">',o+='<div class="panel panel-default iflex">',o+='<div class="panel-heading">'+l[0].cat+"</div>",o+='<div class="panel-body">',o+='<ul class="list-unstyled">',l)o+="<li><kbd>"+l[r].key+"</kbd> "+l[r].des+"</li>";o+="</ul>",o+="</div>",o+="</div>",o+="</div>",d&&!c||(o+="</div>")}o+="</div>",o+="</div>",$("body").append(o)}}},des:"toggle help window",cat:"Other"}};function h(t,e){for(var n=t[e]();!n.is(".result")&&0!==n.length;)n=n[e]();return n}function n(u){return function(){var t,e,n,a,i=$(".result[data-vim-selected]");if(0!==i.length||0!==(i=$(".result:first")).length){if("string"!=typeof u)c=u;else switch(u){case"visible":for(var o=$(window).scrollTop(),s=o+$(window).height(),r=$(".result"),l=0;l<r.length;l++){var c,d=(c=$(r[l])).offset().top;if(d+c.height()<=s&&o<d)break}break;case"down":0===(c=h(i,"next")).length&&(c=$(".result:first"));break;case"up":0===(c=h(i,"prev")).length&&(c=$(".result:last"));break;case"bottom":c=$(".result:last");break;default:c=$(".result:first")}c&&(i.removeAttr("data-vim-selected").removeClass("well well-sm"),c.attr("data-vim-selected","true").addClass("well well-sm"),1===(a=$(".result[data-vim-selected]")).length&&(t=$(window),e=t.scrollTop(),(n=a.offset().top)<e?t.scrollTop(n-30):(a=n+a.height(),e+t.height()<a&&t.scrollTop(a-t.height()+30))))}}}function t(e){return function(){var t=$('div#pagination button[type="submit"]');2===t.length?0<=e&&e<t.length?t[e].click():console.log("pageButtonClick(): invalid argument"):console.log("page navigation with this theme is not supported")}}function e(t){return function(){window.scrollBy(0,t),n("visible")()}}function a(t,e){return function(){window.scrollTo(0,t),n(e)()}}function i(e){return function(){var t=$(".result[data-vim-selected] .result_header a");t.length&&(t=t.attr("href"),e?window.open(t):window.location.href=t)}}$(document).keydown(function(t){!u.hasOwnProperty(t.keyCode)||t.ctrlKey||t.altKey||t.shiftKey||t.metaKey||(27===t.keyCode?"input"===t.target.tagName.toLowerCase()&&u[t.keyCode].fun():t.target===document.body&&(t.preventDefault(),u[t.keyCode].fun()))})});const Ya=document.createElement("style");Ya.textContent=`
|
|
.vim-hotkeys-help {
|
|
position: fixed;
|
|
top: 50%;
|
|
left: 50%;
|
|
transform: translate(-50%, -50%);
|
|
z-index: 9999999;
|
|
overflow-y: auto;
|
|
max-height: 80%;
|
|
box-shadow: 0 0 1em;
|
|
}
|
|
|
|
.dflex {
|
|
display: -webkit-box; /* OLD - iOS 6-, Safari 3.1-6 */
|
|
display: -moz-box; /* OLD - Firefox 19- (buggy but mostly works) */
|
|
display: -ms-flexbox; /* TWEENER - IE 10 */
|
|
display: -webkit-flex; /* NEW - Chrome */
|
|
display: flex; /* NEW, Spec - Opera 12.1, Firefox 20+ */
|
|
}
|
|
|
|
.iflex {
|
|
-webkit-box-flex: 1; /* OLD - iOS 6-, Safari 3.1-6 */
|
|
-moz-box-flex: 1; /* OLD - Firefox 19- */
|
|
-webkit-flex: 1; /* Chrome */
|
|
-ms-flex: 1; /* IE 10 */
|
|
flex: 1; /* NEW, Spec - Opera 12.1, Firefox 20+ */
|
|
}
|
|
`,document.head.append(Ya)}
|
|
//# sourceMappingURL=searxng.min.js.map
|