rowt/static/main.js
2023-07-21 10:48:19 +02:00

2 lines
4.3 KiB
JavaScript

var u=Object.defineProperty;var y=(e,t,s)=>t in e?u(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s;var l=(e,t,s)=>(y(e,typeof t!="symbol"?t+"":t,s),s);class p{constructor(t){l(this,"element");l(this,"trigger");l(this,"contentWrapper");l(this,"closeBtn");l(this,"overlay");l(this,"isOpen");this.trigger=t,this.element=document.getElementById(t),this.contentWrapper=document.querySelector("body"),this.overlay=document.querySelector(".sidebar-overlay[data-trigger="+this.trigger+"]"),this.element&&(this.closeBtn=this.element.querySelector("[data-trigger="+this.trigger+"]")),this.isOpen=!1}toggle(){var t;if(this.isOpen=!this.isOpen,this.trigger&&((t=document.getElementById(this.trigger))==null||t.classList.toggle("open")),this.contentWrapper&&this.contentWrapper.classList.toggle("overlay"),this.overlay&&this.overlay.classList.toggle("show"),this.element&&(this.element.ariaModal=this.element.ariaModal==="true"?"false":"true",this.isOpen)){const s=this.element.querySelector(".focus-js");s?s.focus():this.closeBtn.focus()}}}document.addEventListener("DOMContentLoaded",function(){q(),E(),h()});function h(){const e=document.querySelectorAll(".filter-trips-js");let t=new Map;e&&Array.prototype.forEach.call(e,r=>{t.set(r.dataset.action,r.ariaPressed),r.addEventListener("click",()=>{let o=sessionStorage.getItem("tripsFilter");if(o){let i=new Map(JSON.parse(o));for(let a of i.entries())a[0]===r.dataset.action&&a[1]!=="true"?i.set(a[0],"true"):i.set(a[0],"false");sessionStorage.setItem("tripsFilter",JSON.stringify(Array.from(i.entries())))}g(),r.getAttribute("aria-pressed")==="false"?(Array.prototype.forEach.call(e,i=>{i.setAttribute("aria-pressed","false")}),d(r.dataset.action)):r.setAttribute("aria-pressed","false")})});let s=sessionStorage.getItem("tripsFilter");if(s){let r=new Map(JSON.parse(s));for(let o of r.entries())o[1]==="true"&&d(o[0])}else sessionStorage.setItem("tripsFilter",JSON.stringify(Array.from(t.entries())))}function g(){const e=document.querySelectorAll(".reset-js.hidden");e&&Array.prototype.forEach.call(e,t=>{t.classList.remove("hidden")})}function d(e){const t=document.querySelector('button[data-action="'+e+'"]');t&&(t.setAttribute("aria-pressed","true"),m(e))}function m(e){switch(e){case"filter-days":{S();break}case"filter-coxs":{A();break}case"filter-months":{b(e);break}}}function S(){const e=document.querySelectorAll('div[data-trips="0"]');Array.prototype.forEach.call(e,t=>{t.classList.toggle("hidden")})}function A(){const e=document.querySelectorAll('div[data-coxneeded="false"]');Array.prototype.forEach.call(e,t=>{t.classList.toggle("hidden")})}function b(e){const t=["01","02","03","04","05","06","07","08","09","10","11","12"],s=document.querySelector('button[data-action="'+e+'"]');if(s){const r=s.dataset.month;if(r){const o=t.indexOf(r);o>-1&&t.splice(o,1),Array.prototype.forEach.call(t,i=>{const a=document.querySelectorAll('div[data-month="'+i+'"]');Array.prototype.forEach.call(a,n=>{n.classList.toggle("hidden")})})}}}function q(){const e=document.querySelector("#filter-js");e&&(f(e.value),e.addEventListener("input",()=>{f(e.value)}))}function f(e){const t=document.querySelectorAll('form[data-filterable="true"]');let s=document.querySelector("#filter-result-js"),r=0;Array.prototype.forEach.call(t,o=>{var a;let i=(a=o.dataset.filter)==null?void 0:a.toLocaleLowerCase();o.style.display="none",i!=null&&i.includes(e.toLocaleLowerCase())&&(o.style.display="flex",r++)}),s&&(s.innerHTML=r===0?"Kein Ergebnis gefunden":"<strong>"+r+"</strong>"+(r>1?" Ergebnisse":" Ergebnis")+" gefunden")}function E(){const e=document.querySelectorAll("[data-trigger]");e&&Array.prototype.forEach.call(e,t=>{if(t.dataset.trigger){const s=new p(t.dataset.trigger);t.addEventListener("click",r=>{r.preventDefault(),t.dataset.trigger==="sidebar"&&L(t),s.toggle()})}})}function L(e){const t=document.querySelector("#sidebar");if(t&&e.dataset.body&&e.dataset.header){let r=document.querySelector(e.dataset.body).cloneNode(!0),o=t.querySelector(".body-js");const i=r.querySelectorAll('input[type="checkbox"]');if(Array.prototype.forEach.call(i,n=>{var c;n&&((c=n.parentElement)==null||c.setAttribute("for",n.id+"js"),n.id+="js")}),o&&(o.innerHTML="",o.append(r)),e.dataset.day){let n=r.querySelector(".day-js");n&&(n.value=e.dataset.day)}let a=t.querySelector(".header-js");a&&(a.innerHTML=e.dataset.header)}}