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

15 lines
19 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
2025-05-25 11:49:28 +02:00
*/window.searxng=function(h,s){h.Element&&function(n){n.matches=n.matches||n.matchesSelector||n.webkitMatchesSelector||n.msMatchesSelector||function(l){for(var t=this,r=(t.parentNode||t.document).querySelectorAll(l),o=-1;r[++o]&&r[o]!=t;);return!!r[o]}}(Element.prototype);function a(n,l,t){try{n.call(l,t)}catch(r){console.log(r)}}var f=window.searxng||{};f.on=function(n,l,t,r){r=r||!1,typeof n!="string"?n.addEventListener(l,t,r):s.addEventListener(l,function(o){for(var i=o.target||o.srcElement,p=!1;i&&i.matches&&i!==s&&!(p=i.matches(n));)i=i.parentElement;p&&a(t,i,o)},r)},f.ready=function(n){document.readyState!="loading"?n.call(h):h.addEventListener("DOMContentLoaded",n.bind(h))},f.http=function(n,l,t=null){return new Promise(function(r,o){try{var i=new XMLHttpRequest;i.open(n,l,!0),i.timeout=2e4,i.onload=function(){i.status==200?r(i.response,i.responseType):o(Error(i.statusText))},i.onerror=function(){o(Error("Network Error"))},i.onabort=function(){o(Error("Transaction is aborted"))},i.ontimeout=function(){o(Error("Timeout"))},t?i.send(t):i.send()}catch(p){o(p)}})},f.loadStyle=function(n){var l=f.settings.theme_static_path+"/"+n,t="style_"+n.replace(".","_"),r=s.getElementById(t);r===null&&(r=s.createElement("link"),r.setAttribute("id",t),r.setAttribute("rel","stylesheet"),r.setAttribute("type","text/css"),r.setAttribute("href",l),s.body.appendChild(r))},f.loadScript=function(n,l){var t=f.settings.theme_static_path+"/"+n,r="script_"+n.replace(".","_"),o=s.getElementById(r);if(o===null)o=s.createElement("script"),o.setAttribute("id",r),o.setAttribute("src",t),o.onload=l,o.onerror=function(){o.setAttribute("error","1")},s.body.appendChild(o);else if(o.hasAttribute("error"))console.log("callback not executed : script '"+t+"' not loaded.");else try{l.apply(o,[])}catch(i){console.log(i)}},f.insertBefore=function(n,l){l.parentNode.insertBefore(n,l)},f.insertAfter=function(n,l){l.parentNode.insertAfter(n,l.nextSibling)},f.on(".close","click",function(){this.parentNode.classList.add("invisible")});function m(){for(var n of s.getElementsByTagName("body")[0].classList.values())if(n.endsWith("_endpoint"))return n.split("_")[0];return""}return f.endpoint=m(),f}(window,document);searxng.ready(function(){if(searxng.infinite_scroll_supported="IntersectionObserver"in window&&"IntersectionObserverEntry"in window&&"intersectionRatio"in window.IntersectionObserverEntry.prototype,searxng.endpoint!=="results")return;if(!searxng.infinite_scroll_supported){console.log("IntersectionObserver not supported");return}let h=document;var s=h.getElementById("results").classList.contains("only_template_images");function a(){var n=h.createElement("div");return n.classList.add("loader"),n}function f(n,l){n.textContent="",l.forEach(t=>n.appendChild(t))}function m(n){var l=h.querySelector("#pagination form.next_page");if(l){f(h.querySelector("#pagination"),[a()]);var t=new FormData(l);searxng.http("POST",h.querySelector("#search").getAttribute("action"),t).then(function(r){var o=new DOMParser().parseFromString(r,"text/html"),i=o.querySelectorAll("#urls article"),p=o.querySelector("#pagination");h.querySelector("#pagination").remove(),i.length>0&&!s&&h.querySelector("#urls").appendChild(h.createElement("hr")),i.forEach(b=>{h.querySelector("#urls").appendChild(b)}),p&&(h.querySelector("#results").appendChild(p),n())}).catch(function(r){console.log(r);var o=h.createElement("div");o.textContent=searxng.settings.translations.error_loading_next_page,o.classList.add("dialog-error"),o.setAttribute("role","alert"),f(h.querySelector("#pagination"),[o])})}}if(searxng.settings.infinite_scroll&&searxng.infinite_scroll_supported){const n={rootMargin:"20rem"},l="article.result:last-child",t=new IntersectionObserver(r=>{const o=r[0];o.isIntersecting&&(t.unobserve(o.target),m(()=>t.observe(h.querySelector(l),n)))});t.observe(h.querySelector(l),n)}});searxng.ready(function(){function h(e){for(;e!==void 0;){if(e.classList.contains("detail"))return!0;if(e.classList.contains("result"))return!1;e=e.parentNode}return!1}function s(e){for(;e!==void 0;){if(e.classList.contains(
2025-04-02 11:46:47 +02:00
* swiped-events.js - v@version@
* Pure JavaScript swipe events
* https://github.com/john-doherty/swiped-events
* @inspiration https://stackoverflow.com/questions/16348031/disable-scrolling-when-touch-moving-certain-element
* @author John Doherty <www.johndoherty.info>
* @license MIT
2025-05-25 11:49:28 +02:00
*/(function(h,s){typeof h.CustomEvent!="function"&&(h.CustomEvent=function(c,d){d=d||{bubbles:!1,cancelable:!1,detail:void 0};var g=s.createEvent("CustomEvent");return g.initCustomEvent(c,d.bubbles,d.cancelable,d.detail),g},h.CustomEvent.prototype=h.Event.prototype),s.addEventListener("touchstart",i,!1),s.addEventListener("touchmove",p,!1),s.addEventListener("touchend",o,!1);var a=null,f=null,m=null,n=null,l=null,t=null,r=0;function o(c){if(t===c.target){var d=parseInt(b(t,"data-swipe-threshold","20"),10),g=b(t,"data-swipe-unit","px"),v=parseInt(b(t,"data-swipe-timeout","500"),10),E=Date.now()-l,w="",A=c.changedTouches||c.touches||[];if(g==="vh"&&(d=Math.round(d/100*s.documentElement.clientHeight)),g==="vw"&&(d=Math.round(d/100*s.documentElement.clientWidth)),Math.abs(m)>Math.abs(n)?Math.abs(m)>d&&E<v&&(m>0?w="swiped-left":w="swiped-right"):Math.abs(n)>d&&E<v&&(n>0?w="swiped-up":w="swiped-down"),w!==""){var e={dir:w.replace(/swiped-/,""),touchType:(A[0]||{}).touchType||"direct",fingers:r,xStart:parseInt(a,10),xEnd:parseInt((A[0]||{}).clientX||-1,10),yStart:parseInt(f,10),yEnd:parseInt((A[0]||{}).clientY||-1,10)};t.dispatchEvent(new CustomEvent("swiped",{bubbles:!0,cancelable:!0,detail:e})),t.dispatchEvent(new CustomEvent(w,{bubbles:!0,cancelable:!0,detail:e}))}a=null,f=null,l=null}}function i(c){c.target.getAttribute("data-swipe-ignore")!=="true"&&(t=c.target,l=Date.now(),a=c.touches[0].clientX,f=c.touches[0].clientY,m=0,n=0,r=c.touches.length)}function p(c){if(!(!a||!f)){var d=c.touches[0].clientX,g=c.touches[0].clientY;m=a-d,n=f-g}}function b(c,d,g){for(;c&&c!==s.documentElement;){var v=c.getAttribute(d);if(v)return v;c=c.parentNode}return g}})(window,document);(function(h,s,a){a.endpoint==="results"&&a.ready(function(){s.querySelectorAll("#urls img").forEach(t=>t.addEventListener("error",()=>{t.src=window.searxng.settings.theme_static_path+"/img/img_load_error.svg"},{once:!0})),s.querySelector("#search_url button#copy_url")&&(s.querySelector("#search_url button#copy_url").style.display="block"),a.on(".btn-collapse","click",function(){var t=this.getAttribute("data-btn-text-collapsed"),r=this.getAttribute("data-btn-text-not-collapsed"),o=this.getAttribute("data-target"),i=s.querySelector(o),p=this.innerHTML;this.classList.contains("collapsed")?p=p.replace(t,r):p=p.replace(r,t),this.innerHTML=p,this.classList.toggle("collapsed"),i.classList.toggle("invisible")}),a.on(".media-loader","click",function(){var t=this.getAttribute("data-target"),r=s.querySelector(t+" > iframe"),o=r.getAttribute("src");(o==null||o===!1)&&r.setAttribute("src",r.getAttribute("data-src"))}),a.on("#copy_url","click",function(){var t=this.parentElement.querySelector("pre");navigator.clipboard.writeText(t.innerText),this.innerText=this.dataset.copiedText});let f;const m=s.createElement("div");m.classList.add("loader");const n=new Image,l=(t,r)=>{f&&clearTimeout(f),f=setTimeout(()=>{n.src=t},1e3),n.onload=()=>{r(),m.remove()},n.onerror=()=>{m.remove()}};a.selectImage=t=>{if(s.getElementById("results").classList.add("image-detail-open"),window.location.hash="#image-viewer",a.scrollPageToSelected(),!t)return;const r=t.querySelector(".result-images-source img");if(!r)return;const o=r.getAttribute("data-src");if(!o)return;const i=t.querySelector(".image_thumbnail");r.src=i.src,t.querySelector(".detail").appendChild(m),l(o,()=>{r.src=o,r.removeAttribute("data-src")})},a.closeDetail=function(){s.getElementById("results").classList.remove("image-detail-open"),window.location.hash=="#image-viewer"&&window.history.back(),a.scrollPageToSelected()},a.on(".result-detail-close","click",t=>{t.preventDefault(),a.closeDetail()}),a.on(".result-detail-previous","click",t=>{t.preventDefault(),a.selectPrevious(!1)}),a.on(".result-detail-next","click",t=>{t.preventDefault(),a.selectNext(!1)}),window.addEventListener("hashchange",()=>{window.location.hash!="#image-viewer"&&a.closeDetail()}),s.querySelectorAll(".swipe-horizontal").forEach(t=>{t.addEventListener("swiped-left",function(){a.selectNext(!1)}),t.addEventListener("swiped-right",function(){a.selectPrevious(!1)})}
//# sourceMappingURL=searxng.min.js.map