@dreher-media/dm-js-lib 0.5.2 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/dm-js-lib.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! dm-js-lib v0.5.
|
|
1
|
+
/*! dm-js-lib v0.5.3 */
|
|
2
2
|
!function(){"use strict";function t(){document.addEventListener("DOMContentLoaded",()=>{document.querySelectorAll("[data-download-href]").forEach(t=>{t.addEventListener("click",e=>{e.preventDefault(),e.stopPropagation();const a=t.getAttribute("data-download-href"),n=t.getAttribute("data-download-filename");a&&((t,e)=>{const a=document.createElement("a");a.href=t,a.download=e||t.split("/").pop()||"download",document.body.appendChild(a),a.click(),document.body.removeChild(a)})(a,n)})})})}function e(t){const e=t.dataset.tabTarget;if(e)return e;const a=t.dataset.tabLink;if(a)return a;const n=t.getAttribute("href");return n?.startsWith("#")?n.slice(1):null}function a(t){return Array.from(document.querySelectorAll(`[data-tab-content="${t}"]`))}function n(t){const a=[];return document.querySelectorAll(`.tab-link[data-tab-group="${t}"]:not([data-lang-link]):not([data-lang]), [data-tab-link][data-tab-group="${t}"]`).forEach(t=>{const n=e(t);n&&a.push(n)}),a}function o(t){const a=[];return t.querySelectorAll(".tab-link:not([data-lang-link]):not([data-lang]), [data-tab-link]").forEach(t=>{const n=e(t);n&&a.push(n)}),a}function l(t){const l=t.dataset.tabGroup,r=e(t),i=r?a(r):[];if(l){document.querySelectorAll(`.tab-link[data-tab-group="${l}"]:not([data-lang-link]):not([data-lang]), [data-tab-link][data-tab-group="${l}"]`).forEach(t=>{t.classList.remove("active")}),document.querySelectorAll(`[data-tab-content][data-tab-group="${l}"]`).forEach(t=>{t.style.display="none",t.classList.remove("active")});n(l).forEach(t=>{a(t).forEach(t=>{t.style.display="none",t.classList.remove("active")})})}else{const e=t.parentNode;if(e){e.querySelectorAll(".tab-link:not([data-lang-link]):not([data-lang]), [data-tab-link]").forEach(t=>{t.classList.remove("active")});o(e).forEach(t=>{a(t).forEach(t=>{t.style.display="none",t.classList.remove("active")})})}}t.classList.add("active"),i.forEach(t=>{t.style.display="block",t.classList.add("active")})}function r(t){const e=t.dataset.langLink;if(e)return e;const a=t.textContent?.trim().toLowerCase();return a||null}function i(t){const e=t.match(/^([a-z]{2})(?:-|$)/i);return e?e[1].toLowerCase():null}function c(t){if(document.querySelector(`[data-lang-link="${t}"]`))return!0;if(document.querySelector(`[data-lang-content="${t}"]`))return!0;if(document.querySelector(`.biography-lang-links .tab-link[data-lang]:not([data-lang-link])[data-lang="${t}"]`))return!0;return!!document.querySelector(`.biography-text.${t}`)}function d(t){sessionStorage.setItem("selected_lang",t),document.querySelectorAll("[data-lang-content]").forEach(e=>{const a=e;a.dataset.langContent===t?(a.style.display="",a.classList.add("lang-active")):(a.style.display="none",a.classList.remove("lang-active"))}),document.querySelectorAll(`.biography-text:not([data-lang-content]):not(.${t})`).forEach(t=>{t.style.display="none"}),document.querySelectorAll(`.biography-text:not([data-lang-content]).${t}`).forEach(t=>{t.style.display="block"}),document.querySelectorAll("[data-lang-link]").forEach(e=>{const a=e;r(a)===t?a.classList.add("active"):a.classList.remove("active")}),document.querySelectorAll(`.biography-lang-links .tab-link[data-lang]:not([data-lang-link]):not([data-lang="${t}"])`).forEach(t=>{t.classList.remove("active")}),document.querySelectorAll(`.biography-lang-links .tab-link[data-lang]:not([data-lang-link])[data-lang="${t}"]`).forEach(t=>{t.classList.add("active")})}function s(){let t=sessionStorage.getItem("selected_lang");if(!t){const e=function(){if(navigator.languages&&navigator.languages.length>0)for(const t of navigator.languages){const e=i(t);if(e)return e}return navigator.language?i(navigator.language):null}();if(e&&c(e))t=e;else{if(!c("en"))return;t="en"}}if(t){const e=document.querySelector(`[data-lang-link="${t}"]`);if(e)return void e.click();const a=document.querySelector(`.biography-lang-links .tab-link[data-lang]:not([data-lang-link])[data-lang="${t}"]`);if(a)return void a.click();d(t)}}function u(t,e="script"){return new Promise((a,n)=>{const o="script"===e?`script[src="${t}"]`:`link[rel="stylesheet"][href="${t}"]`;if(document.querySelector(o))a();else if("script"===e){const e=document.createElement("script");e.src=t,e.async=!0,e.onload=()=>a(),e.onerror=()=>n(new Error(`Failed to load script: ${t}`)),document.head.appendChild(e)}else if("stylesheet"===e){const e=document.createElement("link");e.rel="stylesheet",e.href=t,e.onload=()=>a(),e.onerror=()=>n(new Error(`Failed to load stylesheet: ${t}`)),document.head.appendChild(e)}else n(new Error(`Unsupported resource type: ${e}`))})}function y(t){return u(t,"script")}function f(t){const e=document.querySelectorAll(".youtube");return Array.from(e).some(e=>e.dataset.type===t)}"undefined"!=typeof window&&void 0===window.videoSwipers&&(window.videoSwipers=[]);const p=()=>"undefined"!=typeof window?window.videoSwipers:void 0;function g(t){if(void 0!==window.Plyr){const e=window.Plyr.setup("._init-plyr");t.push(...e),e.forEach(e=>{e.on("play",()=>{m(null,t,{});const e=p();e&&e.forEach(t=>{t.autoplay.stop()})}),e.on("pause",()=>{const t=p();t&&t.forEach(t=>{t.autoplay.start()})})})}}function m(t=null,e,a){e.forEach(t=>{t.pause()});for(const[e,n]of Object.entries(a))if(t!==e)if("youtube"===n.type){n.player.pauseVideo()}else if("vimeo"===n.type){n.player.pause()}else if("dailymotion"===n.type){n.player.pause()}}function h(t,e,a){m(t,e,a);const n=p();n&&n.forEach(t=>{t.autoplay.stop()})}function w(t){const e=p();e&&e.forEach(t=>{t.autoplay.start()})}!function(){let t=!1;const e=()=>{window.FsCC?(t||(window.FsCC.consentController.on("updateconsents",()=>{e()}),t=!0),document.querySelectorAll("[fs-cc-reject]").forEach(t=>{const e=t.getAttribute("fs-cc-reject");if(!e)return;const a=window.FsCC?.store.consents[e]??!1,n=document.querySelector(`[fs-cc="${e}"]`);a?(t.style.display="none",n&&(n.style.display="block")):(t.style.display="block",n&&(n.style.display="none"))})):setTimeout(e,200)};document.addEventListener("DOMContentLoaded",e)}(),function(){const t=t=>{const e=(t||"").replace(/\/+$/,"").replace(/\.html?$/i,"");return""===e?"/":e};window.addEventListener("load",()=>{const e=t(window.location.pathname);document.querySelectorAll("a[href]").forEach(a=>{const n=a.getAttribute("href");if(!n)return;if(n.startsWith("#")||n.toLowerCase().startsWith("javascript:"))return;let o;try{o=new URL(n,window.location.href)}catch{return}o.origin===window.location.origin&&t(o.pathname)===e&&a.classList.add("w--current")})})}(),t(),document.addEventListener("DOMContentLoaded",()=>{document.querySelectorAll("[data-separator]").forEach(t=>{const e=t.getAttribute("data-separator");if(!e)return;const a=Array.from(t.children);a.forEach((t,n)=>{if(n<a.length-1){const a=document.createElement("span");a.innerHTML=` ${e} `,t.insertAdjacentElement("afterend",a)}})})}),void 0!==window.Webflow&&window.Webflow.push(()=>{document.querySelectorAll(".copyright-year").forEach(t=>{t.textContent=(new Date).getFullYear().toString()})}),document.addEventListener("DOMContentLoaded",()=>{const t=new URLSearchParams(window.location.search),r=t.get("tab"),i=t.get("tabGroup");if(r){let t=null;i?(document.querySelectorAll(`.tab-link[data-tab-group="${i}"]:not([data-lang-link]):not([data-lang]), [data-tab-link][data-tab-group="${i}"]`).forEach(a=>{e(a)===r&&(t=a)}),document.querySelectorAll(`.tab-link[data-tab-group="${i}"]:not([data-lang-link]):not([data-lang]), [data-tab-link][data-tab-group="${i}"]`).forEach(t=>{t.classList.remove("active")}),document.querySelectorAll(`[data-tab-content][data-tab-group="${i}"]`).forEach(t=>{t.style.display="none",t.classList.remove("active")}),n(i).forEach(t=>{a(t).forEach(t=>{t.style.display="none",t.classList.remove("active")})})):document.querySelectorAll(".tab-link:not([data-lang-link]):not([data-lang]), [data-tab-link]").forEach(a=>{e(a)===r&&(t=a)}),t&&l(t)}if(document.querySelectorAll(".tab-link:not([data-lang-link]):not([data-lang]), [data-tab-link]").forEach(t=>{t.addEventListener("click",t=>{t.preventDefault(),l(t.currentTarget)})}),r||document.querySelectorAll(".tab-link.active:not([data-lang-link]):not([data-lang]), [data-tab-link].active").forEach(t=>{const l=t,r=l.dataset.tabGroup,i=e(l),c=i?a(i):[];if(c.length>0){if(r)document.querySelectorAll(`[data-tab-content][data-tab-group="${r}"]`).forEach(t=>{c.includes(t)||(t.style.display="none",t.classList.remove("active"))}),n(r).forEach(t=>{a(t).forEach(t=>{c.includes(t)||(t.style.display="none",t.classList.remove("active"))})});else{const t=l.parentNode;t&&o(t).forEach(t=>{a(t).forEach(t=>{c.includes(t)||(t.style.display="none",t.classList.remove("active"))})})}c.forEach(t=>{t.style.display="block",t.classList.add("active")})}}),!r){const t=new Set;document.querySelectorAll(".tab-link[data-tab-first-active]:not([data-lang-link]):not([data-lang]), [data-tab-link][data-tab-first-active]").forEach(e=>{const a=e,n=a.dataset.tabGroup;if(!(i&&n===i||a.classList.contains("active")))if(n){if(t.has(n))return;if(null!==document.querySelector(`.tab-link.active[data-tab-group="${n}"]:not([data-lang-link]):not([data-lang]), [data-tab-link].active[data-tab-group="${n}"]`))return void t.add(n);t.add(n);const e=document.querySelector(`.tab-link[data-tab-group="${n}"]:not([data-lang-link]):not([data-lang]), [data-tab-link][data-tab-group="${n}"]`);e&&l(e)}else{const t=a.parentNode;t&&null!==t.querySelector(".tab-link.active:not([data-lang-link]):not([data-lang]), [data-tab-link].active")||l(a)}}),document.querySelectorAll("[data-tab-first-active][data-tab-group]").forEach(e=>{const a=e.dataset.tabGroup;if(!a)return;if(i&&a===i)return;if(t.has(a))return;if(null!==document.querySelector(`.tab-link.active[data-tab-group="${a}"]:not([data-lang-link]):not([data-lang]), [data-tab-link].active[data-tab-group="${a}"]`))return void t.add(a);t.add(a);const n=document.querySelector(`.tab-link[data-tab-group="${a}"]:not([data-lang-link]):not([data-lang]), [data-tab-link][data-tab-group="${a}"]`);n&&l(n)})}}),document.addEventListener("DOMContentLoaded",()=>{document.querySelectorAll("[data-lang-link]").forEach(t=>{t.addEventListener("click",t=>{t.preventDefault();const e=r(t.currentTarget);e&&d(e)})}),document.querySelectorAll(".biography-lang-links .tab-link[data-lang]:not([data-lang-link])[data-lang]").forEach(t=>{t.addEventListener("click",t=>{t.preventDefault();const e=t.currentTarget,a=e.dataset?.lang;a&&d(a)})}),s()}),"interactive"!==document.readyState&&"complete"!==document.readyState||s(),document.addEventListener("DOMContentLoaded",()=>{const t=["maxresdefault","sddefault","hqdefault","mqdefault","default"],e=(a,n=0)=>{if(a.naturalWidth>120)return;if(n>=t.length)return;const o=t[n],l=a.src,r=new Image;r.onload=()=>{r.naturalWidth>120?a.src=r.src:e(a,n+1)},r.onerror=()=>{e(a,n+1)},r.src=l.replace(/maxresdefault/,o)};document.querySelectorAll(".youtube img").forEach(t=>{e(t)})}),document.addEventListener("DOMContentLoaded",()=>{let t=[];const e=document.querySelectorAll(".youtube"),a={};let n=!1;const o=document.querySelectorAll("._init-plyr").length>0,l=f("youtube"),r=f("vimeo"),i=f("dailymotion"),c=()=>{n||(n=!0,function(t,e,a){t.forEach(t=>{t.addEventListener("click",()=>{const n=t.querySelector("[data-custom-embed]");n&&(t.innerHTML=n.innerHTML);const o=t,l=`player_${o.dataset.id}`,r=o.dataset.type,i=o.dataset.videoId,c=parseInt(o.dataset.time||"0",10);if(i&&r)if(h(l,a,e),"youtube"===r&&window.YT){const t=new window.YT.Player(l,{videoId:i,playerVars:{start:c},events:{onReady:t=>{t.target.playVideo()},onStateChange:t=>{t.data===window.YT.PlayerState.PLAYING?h(l,a,e):t.data!==window.YT.PlayerState.PAUSED&&t.data!==window.YT.PlayerState.ENDED||w()}}});e[l]={type:r,player:t}}else if("vimeo"===r&&window.Vimeo){const t=document.getElementById(l);t&&(t.innerHTML="");const n=new window.Vimeo.Player(l,{id:i,autoplay:!0,start:c});n.on("play",()=>h(l,a,e)),n.on("pause",()=>w()),e[l]={type:r,player:n}}else"dailymotion"===r&&window.dailymotion&&window.dailymotion.createPlayer(l,{video:i,params:{autoplay:1,start:c,mute:!1}}).then(t=>{t.on("play",()=>h(l,a,e)),t.on("pause",()=>w()),t.on("ended",()=>w()),e[l]={type:"dailymotion",player:t}}).catch(t=>{console.error("Error initializing Dailymotion player:",t)})})})}(e,a,t))};l&&(window.onYouTubeIframeAPIReady=()=>{c()});const d=[];var s;o&&d.push(window.Plyr&&"function"==typeof window.Plyr.setup?Promise.resolve():Promise.all([(s="https://cdn.plyr.io/3.7.8/plyr.css",u(s,"stylesheet")),y("https://cdn.plyr.io/3.7.8/plyr.polyfilled.js")]).then(()=>{}).catch(t=>{throw console.error("Failed to load Plyr resources:",t),t})),l&&d.push(window.YT&&"function"==typeof window.YT.Player?Promise.resolve():y("https://www.youtube.com/iframe_api").catch(t=>{console.error("Failed to load YouTube API:",t)})),r&&d.push(window.Vimeo&&"function"==typeof window.Vimeo.Player?Promise.resolve():y("https://player.vimeo.com/api/player.js").catch(t=>{console.error("Failed to load Vimeo API:",t)})),i&&d.push(window.dailymotion&&"function"==typeof window.dailymotion.createPlayer?Promise.resolve():y("https://api.dmcdn.net/all.js").catch(t=>{console.error("Failed to load Dailymotion API:",t)})),d.length>0?Promise.all(d).then(()=>{o&&g(t),l?setTimeout(()=>{n||c()},1e3):setTimeout(()=>{c()},100)}).catch(e=>{console.error("Error loading video player APIs:",e),o&&void 0!==window.Plyr&&g(t),setTimeout(()=>{c()},500)}):(o&&void 0!==window.Plyr&&g(t),c());const p="undefined"!=typeof window?window.videoSwipers:void 0;p&&p.forEach(e=>{e.on("slideChange",()=>{m(null,t,a)})})})}();
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! dm-js-lib/filter v0.5.
|
|
2
|
-
var Filter=function(t){"use strict";function e(t){let e=t;for(;e;){const t=e.dataset.filterInstance;if(t)return t;e=e.parentElement}return null}function a(t,e){const a=`[data-filter-field="${t}"]`,n=e?`[data-filter-instance="${e}"] ${a}, ${a}[data-filter-instance="${e}"]`:`${a}:not([data-filter-instance])`,i=document.querySelector(n);if(!i)return!1;if("input"===i.tagName.toLowerCase()){const t=i.type;return"text"===t||"search"===t}return!1}function n(t){const e={},a={},n="[data-filter-field]",i=t?`[data-filter-instance="${t}"] ${n}, ${n}[data-filter-instance="${t}"]`:`${n}:not([data-filter-instance])`;return document.querySelectorAll(i).forEach(t=>{const n=t,i=n.dataset.filterField;if(i){const t=function(t){const e=t.tagName.toLowerCase();if("input"===e){const e=t.type;return"checkbox"===e||"radio"===e?t.checked?t.value||"true":null:"text"===e||"search"===e?t.value.trim()||null:t.value||null}if("select"===e)return t.value||null;return t.dataset.filterValue||null}(n);if(t&&t.trim().length>0){const l=function(t){return t?t.split(",").map(t=>t.trim()).filter(t=>t.length>0):[]}(n.dataset.filterSearch);l.length>0&&(a[i]=l),e[i]||(e[i]=[]),e[i].push(t.toLowerCase())}}}),{filters:e,multifieldSearches:a}}function i(t,e){if(t.dataset.filterField===e){return(t.dataset.filterValue||t.textContent?.trim()||"").split(",").map(t=>t.trim().toLowerCase()).filter(Boolean)}const a=t.querySelector(`[data-filter-field="${e}"]`);if(a){return(a.dataset.filterValue||a.textContent?.trim()||a.getAttribute("value")||"").split(",").map(t=>t.trim().toLowerCase()).filter(Boolean)}const n=t.dataset.filterValue;if(n){return n.split(",").map(t=>t.trim().toLowerCase()).filter(Boolean)}return[]}function l(t){const e=[],a=t.dataset.filterValue;return a&&e.push(...a.split(",").map(t=>t.trim().toLowerCase()).filter(Boolean)),e}const r=new Map;function o(t){return t||"default"}function c(t,e){const a=o(t),n="[data-filter-count], [data-filter-results]",i=t?`[data-filter-instance="${t}"] ${n}, ${n}[data-filter-instance="${t}"]`:`${n}:not([data-filter-instance])`,l=t?`[data-filter-instance="${t}"] [data-filter-empty], [data-filter-empty][data-filter-instance="${t}"]`:"[data-filter-empty]:not([data-filter-instance])",c=t?`[data-filter-instance="${t}"] [data-filter-loading], [data-filter-loading][data-filter-instance="${t}"]`:"[data-filter-loading]:not([data-filter-instance])";let s=[];const d=e.querySelectorAll("[data-filter-item]");if(d.length>0)s=Array.from(d);else if(Array.from(e.children).forEach(t=>{t instanceof HTMLElement&&s.push(t)}),0===s.length){const t=e.querySelectorAll("[data-filter-field]");s=Array.from(t)}const f={listElement:e,items:s,controls:Array.from(document.querySelectorAll(t?`[data-filter-instance="${t}"] [data-filter-field], [data-filter-field][data-filter-instance="${t}"]`:"[data-filter-field]:not([data-filter-instance])")),countElements:Array.from(document.querySelectorAll(i)),emptyElement:document.querySelector(l)||null,loadingElement:document.querySelector(c)||null,lastUpdate:Date.now()};return r.set(a,f),f}function s(t,e){const a=o(t),n=r.get(a);return n&&n.listElement===e?n:c(t,e)}function d(t){const r=e(t),{filters:o,multifieldSearches:c}=n(r),d=s(r,t),f=d.items;d.loadingElement&&(d.loadingElement.style.display="",d.loadingElement.classList.add("filter-loading-active")),requestAnimationFrame(()=>{let e=0;if(f.forEach(t=>{const n=function(t,e,n,r){const o={};for(const[t,a]of Object.entries(e))a.length>0&&(o[t]=a);if(0===Object.keys(o).length)return!0;for(const[e,c]of Object.entries(o)){const o=n[e];if(o&&o.length>0){if(!c.some(e=>{const a=o.some(a=>i(t,a).some(t=>t.includes(e)||e.includes(t)));return a||l(t).some(t=>t.includes(e)||e.includes(t))}))return!1}else{let n=i(t,e);if(0===n.length&&(n=l(t)),0===n.length)return!1;const o=a(e,r);if(!c.some(t=>n.some(e=>o?e.includes(t)||t.includes(e):e===t)))return!1}}return!0}(t,o,c,r);n?(t.style.display="",t.classList.add("filter-active"),t.classList.remove("filter-hidden"),e++):(t.style.display="none",t.classList.add("filter-hidden"),t.classList.remove("filter-active"))}),function(t,e,a,n,i){const l=i?.countElements||[];if(0===l.length){const t="[data-filter-count], [data-filter-results]",e=n?`[data-filter-instance="${n}"] ${t}, ${t}[data-filter-instance="${n}"]`:`${t}:not([data-filter-instance])`;l.push(...Array.from(document.querySelectorAll(e)))}l.forEach(t=>{const n=t;void 0!==n.dataset.filterCount&&(n.textContent=e.toString(),n.setAttribute("aria-label",`Total items: ${e}`)),void 0!==n.dataset.filterResults&&(n.textContent=a.toString(),n.setAttribute("aria-label",`Showing ${a} of ${e} items`))})}(0,f.length,e,r,d),d.emptyElement)if(0===e){d.emptyElement.style.display="",d.emptyElement.classList.add("filter-empty-active");const t=d.emptyElement.dataset.filterEmptyText;if(t){(d.emptyElement.querySelector("[data-filter-empty-text-content]")||d.emptyElement).textContent=t}}else d.emptyElement.style.display="none",d.emptyElement.classList.remove("filter-empty-active");d.loadingElement&&(d.loadingElement.style.display="none",d.loadingElement.classList.remove("filter-loading-active"));const n=new CustomEvent("filter:change",{detail:{instance:r,filters:o,visibleCount:e,total:f.length}});if(t.dispatchEvent(n),0===e){const e=new CustomEvent("filter:empty",{detail:{instance:r,filters:o}});t.dispatchEvent(e)}const s=document.querySelector(`#filter-live-${r||"default"}`);s&&(s.textContent=0===e?"No results found":`Showing ${e} of ${f.length} items`);const u=t.dataset.filterScroll;u&&requestAnimationFrame(()=>{if("top"===u)window.scrollTo({top:0,behavior:"smooth"});else if("anchor"===u){const e=t.dataset.filterScrollAnchor,a=e?document.querySelector(e):t;a?.scrollIntoView({behavior:"smooth",block:"start"})}else{const t=document.querySelector(u);t?.scrollIntoView({behavior:"smooth",block:"start"})}});"true"===t.dataset.filterUrl&&function(t,e){const a=new URLSearchParams(window.location.search),n=t?`filter_${t}_`:"filter_";Array.from(a.keys()).forEach(t=>{t.startsWith(n)&&a.delete(t)}),Object.entries(e).forEach(([t,e])=>{e.length>0&&a.set(`${n}${t}`,e.join(","))});const i=`${window.location.pathname}${a.toString()?`?${a.toString()}`:""}${window.location.hash}`;window.history.pushState({},"",i)}(r,o);const m=t.dataset.filterPersist;m&&function(t,e,a){try{const n=`filter_${t}_${e||"default"}`;localStorage.setItem(n,JSON.stringify(a))}catch(t){console.warn("Failed to save filter state to localStorage",t)}}(m,r,o)})}function f(t){const a=e(t),n="[data-filter-list]",i=a?`[data-filter-instance="${a}"] ${n}, ${n}[data-filter-instance="${a}"]`:`${n}:not([data-filter-instance])`,l=document.querySelector(i);l&&d(l)}function u(t){const a=t.dataset.filterField;if(!a)return;if(!("true"===t.dataset.filterAutofill))return;const n=t.options.length>0,l="true"===t.dataset.filterAutofillRefresh;if(n&&!l){const e=t.options[0];if(!("true"===e?.dataset.filterAutofillOption))return;if(!l)return;Array.from(t.options).forEach(t=>{"true"===t.dataset.filterAutofillOption&&t.remove()})}const r=e(t),o="[data-filter-list]",c=r?`[data-filter-instance="${r}"] ${o}, ${o}[data-filter-instance="${r}"]`:`${o}:not([data-filter-instance])`,d=document.querySelector(c);if(!d)return;const f=function(t,e,a){const n=s(a,t),l=new Set;return n.items.forEach(t=>{i(t,e).forEach(t=>{t&&l.add(t)})}),Array.from(l).sort()}(d,a,r);if(0===f.length)return;const u=t.dataset.filterAllValue||"",m=t.dataset.filterAllText||"All",h="false"!==t.dataset.filterAutofillAll;if(n?Array.from(t.options).forEach(t=>{"true"===t.dataset.filterAutofillOption&&t.remove()}):t.innerHTML="",h){const e=document.createElement("option");e.value=u,e.textContent=m,e.dataset.filterAutofillOption="true",t.appendChild(e)}f.forEach(e=>{const a=document.createElement("option");a.value=e,a.textContent=e.split(" ").map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" "),a.dataset.filterAutofillOption="true",t.appendChild(a)})}function m(t){const e="select[data-filter-field]",a=t?`[data-filter-instance="${t}"] ${e}, ${e}[data-filter-instance="${t}"]`:`${e}:not([data-filter-instance])`;document.querySelectorAll(a).forEach(t=>{const e=t;"true"===e.dataset.filterAutofill&&u(e)})}const h={setFilter:(t,e,a)=>{const n=`[data-filter-field="${e}"]`,i=t?`[data-filter-instance="${t}"] ${n}, ${n}[data-filter-instance="${t}"]`:`${n}:not([data-filter-instance])`;document.querySelectorAll(i).forEach(t=>{const e=t,n=e.tagName.toLowerCase();if("input"===n){const t=e;"checkbox"===t.type||"radio"===t.type?t.checked=t.value.toLowerCase()===a.toLowerCase():t.value=a}else"select"===n&&(e.value=a)});const l="[data-filter-list]",r=t?`[data-filter-instance="${t}"] ${l}, ${l}[data-filter-instance="${t}"]`:`${l}:not([data-filter-instance])`,o=document.querySelector(r);o&&d(o)},clear:t=>{const e="[data-filter-list]",a=t?`[data-filter-instance="${t}"] ${e}, ${e}[data-filter-instance="${t}"]`:`${e}:not([data-filter-instance])`,n=document.querySelector(a);if(n){const e="[data-filter-field]",a=t?`[data-filter-instance="${t}"] ${e}, ${e}[data-filter-instance="${t}"]`:`${e}:not([data-filter-instance])`;document.querySelectorAll(a).forEach(t=>{const e=t,a=e.tagName.toLowerCase();if("input"===a){const t=e;"checkbox"===t.type||"radio"===t.type?t.checked=!1:t.value=""}else"select"===a?e.selectedIndex=0:e.classList.remove("active")}),d(n)}},getActiveFilters:t=>{const{filters:e}=n(t);return e},refresh:t=>{const e="[data-filter-list]",a=t?`[data-filter-instance="${t}"] ${e}, ${e}[data-filter-instance="${t}"]`:`${e}:not([data-filter-instance])`,n=document.querySelector(a);n&&(c(t,n),m(t),d(n))}};let p=!1,$=!1,y=!1,E=!1;function v(){if(p||(window.filterAPI=h),$||(document.querySelectorAll('input[type="checkbox"][data-filter-field]').forEach(t=>{t.addEventListener("change",()=>{f(t)})}),document.querySelectorAll('input[type="radio"][data-filter-field]').forEach(t=>{t.addEventListener("change",()=>{const a=t.dataset.filterField,n=e(t),i=t.name;if(i)document.querySelectorAll(`input[type="radio"][name="${i}"]`).forEach(e=>{e!==t&&(e.checked=!1)});else if(a){const e=n?`input[type="radio"][data-filter-field="${a}"][data-filter-instance="${n}"], input[type="radio"][data-filter-field="${a}"][data-filter-instance="${n}"]`:`input[type="radio"][data-filter-field="${a}"]:not([data-filter-instance])`;document.querySelectorAll(e).forEach(e=>{e!==t&&(e.checked=!1)})}f(t)})}),document.querySelectorAll("select[data-filter-field]").forEach(t=>{t.addEventListener("change",()=>{f(t)})}),document.querySelectorAll('input[type="text"][data-filter-field], input[type="search"][data-filter-field]').forEach(t=>{let e;const a=t,n=a.dataset.filterDebounce&&parseInt(a.dataset.filterDebounce,10)||300;t.addEventListener("input",()=>{clearTimeout(e),e=setTimeout(()=>{f(a)},n)})}),document.querySelectorAll("[data-filter-field]:not(input):not(select)").forEach(t=>{const e=t;e.setAttribute("role","button"),e.setAttribute("tabindex","0");const a=t=>{t.preventDefault();const a=e.querySelector('input[type="checkbox"], input[type="radio"]');a?(a.checked=!a.checked,f(a)):(e.classList.toggle("active"),f(e))};e.addEventListener("click",a),e.addEventListener("keydown",t=>{"Enter"!==t.key&&" "!==t.key||a(t)})}),$=!0),document.querySelectorAll("select[data-filter-field]").forEach(t=>{const e=t;"true"===e.dataset.filterAutofill&&u(e)}),y||(document.querySelectorAll("[data-filter-clear]").forEach(t=>{t.addEventListener("click",a=>{a.preventDefault();const n=e(t),i="[data-filter-field]",l=n?`[data-filter-instance="${n}"] ${i}, ${i}[data-filter-instance="${n}"]`:`${i}:not([data-filter-instance])`;document.querySelectorAll(l).forEach(t=>{const e=t,a=e.tagName.toLowerCase();if("input"===a){const t=e;"checkbox"===t.type||"radio"===t.type?t.checked=!1:t.value=""}else"select"===a?e.selectedIndex=0:e.classList.remove("active")});const r="[data-filter-list]",o=n?`[data-filter-instance="${n}"] ${r}, ${r}[data-filter-instance="${n}"]`:`${r}:not([data-filter-instance])`,c=document.querySelector(o);if(c){if("true"===c.dataset.filterUrl){const t=new URLSearchParams(window.location.search),e=n?`filter_${n}_`:"filter_";Array.from(t.keys()).forEach(a=>{a.startsWith(e)&&t.delete(a)});const a=`${window.location.pathname}${t.toString()?`?${t.toString()}`:""}${window.location.hash}`;window.history.pushState({},"",a)}const t=c.dataset.filterPersist;if(t)try{const e=`filter_${t}_${n||"default"}`;localStorage.removeItem(e)}catch(t){}d(c);const e=new CustomEvent("filter:clear",{detail:{instance:n}});c.dispatchEvent(e)}})}),y=!0),document.querySelectorAll("[data-filter-list]").forEach(t=>{const a=t,n=e(a),i=a.dataset.filterPersist;i&&function(t,e){try{const a=`filter_${t}_${e||"default"}`,n=localStorage.getItem(a);if(n){const t=JSON.parse(n);Object.entries(t).forEach(([t,a])=>{const n=`[data-filter-field="${t}"]`,i=e?`[data-filter-instance="${e}"] ${n}, ${n}[data-filter-instance="${e}"]`:`${n}:not([data-filter-instance])`;document.querySelectorAll(i).forEach(t=>{const e=t,n=e.tagName.toLowerCase();if("input"===n){const t=e,n=t.value.toLowerCase();"checkbox"===t.type||"radio"===t.type?t.checked=a.includes(n):"text"!==t.type&&"search"!==t.type||(t.value=a[0]||"")}else if("select"===n){const t=e;a.length>0&&(t.value=a[0])}})})}}catch(t){console.warn("Failed to restore filter state from localStorage",t)}}(i,n),"true"===a.dataset.filterUrl&&function(t){const e=new URLSearchParams(window.location.search),a=t?`filter_${t}_`:"filter_";e.forEach((e,n)=>{if(n.startsWith(a)){const i=n.replace(a,""),l=e.split(",").map(t=>t.trim()),r=`[data-filter-field="${i}"]`,o=t?`[data-filter-instance="${t}"] ${r}, ${r}[data-filter-instance="${t}"]`:`${r}:not([data-filter-instance])`;document.querySelectorAll(o).forEach(t=>{const e=t,a=e.tagName.toLowerCase();if("input"===a){const t=e,a=t.value.toLowerCase();"checkbox"===t.type||"radio"===t.type?t.checked=l.includes(a):"text"!==t.type&&"search"!==t.type||(t.value=l[0]||"")}else if("select"===a){const t=e;l.length>0&&(t.value=l[0])}})}})}(n),a.setAttribute("role","region"),a.setAttribute("aria-label","Filtered list"),a.id||(a.id=`filter-list-${n||"default"}-${Date.now()}`);let l=document.querySelector(`#filter-live-${n||"default"}`);l||(l=document.createElement("div"),l.id=`filter-live-${n||"default"}`,l.setAttribute("aria-live","polite"),l.setAttribute("aria-atomic","true"),l.className="sr-only",l.style.cssText="position:absolute;left:-10000px;width:1px;height:1px;overflow:hidden;",document.body.appendChild(l)),c(n,a),m(n),d(a)}),!E){new MutationObserver(()=>{document.querySelectorAll("[data-filter-list]").forEach(t=>{const a=t,n=e(a);c(n,a),m(n)})}).observe(document.body,{childList:!0,subtree:!0}),E=!0}p=!0}return"loading"===document.readyState?document.addEventListener("DOMContentLoaded",v):v(),t.filterAPI=h,t.initFilter=function(){"loading"===document.readyState?document.addEventListener("DOMContentLoaded",v):v()},t}({});
|
|
1
|
+
/*! dm-js-lib/filter v0.5.3 */
|
|
2
|
+
var Filter=function(t){"use strict";function e(t){let e=t;for(;e;){const t=e.dataset.filterInstance;if(t)return t;e=e.parentElement}return null}function a(t,e){const a=`[data-filter-field="${t}"]`,n=e?`[data-filter-instance="${e}"] ${a}, ${a}[data-filter-instance="${e}"]`:`${a}:not([data-filter-instance])`,l=document.querySelector(n);if(!l)return!1;if("input"===l.tagName.toLowerCase()){const t=l.type;return"text"===t||"search"===t}return!1}function n(t){const e={},a={},n="[data-filter-field]",l=t?`[data-filter-instance="${t}"] ${n}, ${n}[data-filter-instance="${t}"]`:`${n}:not([data-filter-instance])`;return document.querySelectorAll(l).forEach(t=>{const n=t,l=n.dataset.filterField;if(l){const t=function(t){const e=t.tagName.toLowerCase();if("input"===e){const e=t.type;return"checkbox"===e||"radio"===e?t.checked?t.value||"true":null:"text"===e||"search"===e?t.value.trim()||null:t.value||null}if("select"===e)return t.value||null;return t.dataset.filterValue||null}(n);let i=!1;if("select"===n.tagName.toLowerCase()&&t){const e=n,a=e.dataset.filterAllValue||"",l=e.dataset.filterAllText||"All";t!==a&&t.trim()!==a||(i=!0);const r=e.options[e.selectedIndex];if(r&&!r.hasAttribute("value")){const t=r.textContent?.trim().toLowerCase()||"";(t===l.toLowerCase()||t.startsWith("select")||t.startsWith("choose")||"all"===t||""===t)&&(i=!0)}}if(t&&t.trim().length>0&&!i){const i=function(t){return t?t.split(",").map(t=>t.trim()).filter(t=>t.length>0):[]}(n.dataset.filterSearch);i.length>0&&(a[l]=i),e[l]||(e[l]=[]),e[l].push(t.toLowerCase())}}}),{filters:e,multifieldSearches:a}}function l(t,e){if(t.dataset.filterField===e){return(t.dataset.filterValue||t.textContent?.trim()||"").split(",").map(t=>t.trim().toLowerCase()).filter(Boolean)}const a=t.querySelector(`[data-filter-field="${e}"]`);if(a){return(a.dataset.filterValue||a.textContent?.trim()||a.getAttribute("value")||"").split(",").map(t=>t.trim().toLowerCase()).filter(Boolean)}const n=t.dataset.filterValue;if(n){return n.split(",").map(t=>t.trim().toLowerCase()).filter(Boolean)}return[]}function i(t){const e=[],a=t.dataset.filterValue;return a&&e.push(...a.split(",").map(t=>t.trim().toLowerCase()).filter(Boolean)),e}const r=new Map;function o(t){return t||"default"}function s(t,e){const a=o(t),n="[data-filter-count], [data-filter-results]",l=t?`[data-filter-instance="${t}"] ${n}, ${n}[data-filter-instance="${t}"]`:`${n}:not([data-filter-instance])`,i=t?`[data-filter-instance="${t}"] [data-filter-empty], [data-filter-empty][data-filter-instance="${t}"]`:"[data-filter-empty]:not([data-filter-instance])",s=t?`[data-filter-instance="${t}"] [data-filter-loading], [data-filter-loading][data-filter-instance="${t}"]`:"[data-filter-loading]:not([data-filter-instance])";let c=[];const d=e.querySelectorAll("[data-filter-item]");if(d.length>0)c=Array.from(d);else if(Array.from(e.children).forEach(t=>{t instanceof HTMLElement&&c.push(t)}),0===c.length){const t=e.querySelectorAll("[data-filter-field]");c=Array.from(t)}const f={listElement:e,items:c,controls:Array.from(document.querySelectorAll(t?`[data-filter-instance="${t}"] [data-filter-field], [data-filter-field][data-filter-instance="${t}"]`:"[data-filter-field]:not([data-filter-instance])")),countElements:Array.from(document.querySelectorAll(l)),emptyElement:document.querySelector(i)||null,loadingElement:document.querySelector(s)||null,lastUpdate:Date.now()};return r.set(a,f),f}function c(t,e){const a=o(t),n=r.get(a);return n&&n.listElement===e?n:s(t,e)}function d(t){const r=e(t),{filters:o,multifieldSearches:s}=n(r),d=c(r,t),f=d.items;d.loadingElement&&(d.loadingElement.style.display="",d.loadingElement.classList.add("filter-loading-active")),requestAnimationFrame(()=>{let e=0;if(f.forEach(t=>{const n=function(t,e,n,r){const o={};for(const[t,a]of Object.entries(e))a.length>0&&(o[t]=a);if(0===Object.keys(o).length)return!0;for(const[e,s]of Object.entries(o)){const o=n[e];if(o&&o.length>0){if(!s.some(e=>{const a=o.some(a=>l(t,a).some(t=>t.includes(e)||e.includes(t)));return a||i(t).some(t=>t.includes(e)||e.includes(t))}))return!1}else{let n=l(t,e);if(0===n.length&&(n=i(t)),0===n.length)return!1;const o=a(e,r);if(!s.some(t=>n.some(e=>o?e.includes(t)||t.includes(e):e===t)))return!1}}return!0}(t,o,s,r);n?(t.style.display="",t.classList.add("filter-active"),t.classList.remove("filter-hidden"),e++):(t.style.display="none",t.classList.add("filter-hidden"),t.classList.remove("filter-active"))}),function(t,e,a,n,l){const i=l?.countElements||[];if(0===i.length){const t="[data-filter-count], [data-filter-results]",e=n?`[data-filter-instance="${n}"] ${t}, ${t}[data-filter-instance="${n}"]`:`${t}:not([data-filter-instance])`;i.push(...Array.from(document.querySelectorAll(e)))}i.forEach(t=>{const n=t;void 0!==n.dataset.filterCount&&(n.textContent=e.toString(),n.setAttribute("aria-label",`Total items: ${e}`)),void 0!==n.dataset.filterResults&&(n.textContent=a.toString(),n.setAttribute("aria-label",`Showing ${a} of ${e} items`))})}(0,f.length,e,r,d),d.emptyElement)if(0===e){d.emptyElement.style.display="",d.emptyElement.classList.add("filter-empty-active");const t=d.emptyElement.dataset.filterEmptyText;if(t){(d.emptyElement.querySelector("[data-filter-empty-text-content]")||d.emptyElement).textContent=t}}else d.emptyElement.style.display="none",d.emptyElement.classList.remove("filter-empty-active");d.loadingElement&&(d.loadingElement.style.display="none",d.loadingElement.classList.remove("filter-loading-active"));const n=new CustomEvent("filter:change",{detail:{instance:r,filters:o,visibleCount:e,total:f.length}});if(t.dispatchEvent(n),0===e){const e=new CustomEvent("filter:empty",{detail:{instance:r,filters:o}});t.dispatchEvent(e)}const c=document.querySelector(`#filter-live-${r||"default"}`);c&&(c.textContent=0===e?"No results found":`Showing ${e} of ${f.length} items`);const u=t.dataset.filterScroll;u&&requestAnimationFrame(()=>{if("top"===u)window.scrollTo({top:0,behavior:"smooth"});else if("anchor"===u){const e=t.dataset.filterScrollAnchor,a=e?document.querySelector(e):t;a?.scrollIntoView({behavior:"smooth",block:"start"})}else{const t=document.querySelector(u);t?.scrollIntoView({behavior:"smooth",block:"start"})}});"true"===t.dataset.filterUrl&&function(t,e){const a=new URLSearchParams(window.location.search),n=t?`filter_${t}_`:"filter_";Array.from(a.keys()).forEach(t=>{t.startsWith(n)&&a.delete(t)}),Object.entries(e).forEach(([t,e])=>{e.length>0&&a.set(`${n}${t}`,e.join(","))});const l=`${window.location.pathname}${a.toString()?`?${a.toString()}`:""}${window.location.hash}`;window.history.pushState({},"",l)}(r,o);const m=t.dataset.filterPersist;m&&function(t,e,a){try{const n=`filter_${t}_${e||"default"}`;localStorage.setItem(n,JSON.stringify(a))}catch(t){console.warn("Failed to save filter state to localStorage",t)}}(m,r,o)})}function f(t){const a=e(t),n="[data-filter-list]",l=a?`[data-filter-instance="${a}"] ${n}, ${n}[data-filter-instance="${a}"]`:`${n}:not([data-filter-instance])`,i=document.querySelector(l);i&&d(i)}function u(t){const a=t.dataset.filterField;if(!a)return;if(!("true"===t.dataset.filterAutofill))return;const n=t.options.length>0,i="true"===t.dataset.filterAutofillRefresh;if(n&&!i){const e=t.options[0];if(!("true"===e?.dataset.filterAutofillOption))return;if(!i)return;Array.from(t.options).forEach(t=>{"true"===t.dataset.filterAutofillOption&&t.remove()})}const r=e(t),o="[data-filter-list]",s=r?`[data-filter-instance="${r}"] ${o}, ${o}[data-filter-instance="${r}"]`:`${o}:not([data-filter-instance])`,d=document.querySelector(s);if(!d)return;const f=function(t,e,a){const n=c(a,t),i=new Set;return n.items.forEach(t=>{l(t,e).forEach(t=>{t&&i.add(t)})}),Array.from(i).sort()}(d,a,r);if(0===f.length)return;const u=t.dataset.filterAllValue||"",m=t.dataset.filterAllText||"All",h="false"!==t.dataset.filterAutofillAll;if(n?Array.from(t.options).forEach(t=>{"true"===t.dataset.filterAutofillOption&&t.remove()}):t.innerHTML="",h){const e=document.createElement("option");e.value=u,e.textContent=m,e.dataset.filterAutofillOption="true",t.appendChild(e)}f.forEach(e=>{const a=document.createElement("option");a.value=e,a.textContent=e.split(" ").map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" "),a.dataset.filterAutofillOption="true",t.appendChild(a)})}function m(t){const e="select[data-filter-field]",a=t?`[data-filter-instance="${t}"] ${e}, ${e}[data-filter-instance="${t}"]`:`${e}:not([data-filter-instance])`;document.querySelectorAll(a).forEach(t=>{const e=t;"true"===e.dataset.filterAutofill&&u(e)})}const h={setFilter:(t,e,a)=>{const n=`[data-filter-field="${e}"]`,l=t?`[data-filter-instance="${t}"] ${n}, ${n}[data-filter-instance="${t}"]`:`${n}:not([data-filter-instance])`;document.querySelectorAll(l).forEach(t=>{const e=t,n=e.tagName.toLowerCase();if("input"===n){const t=e;"checkbox"===t.type||"radio"===t.type?t.checked=t.value.toLowerCase()===a.toLowerCase():t.value=a}else"select"===n&&(e.value=a)});const i="[data-filter-list]",r=t?`[data-filter-instance="${t}"] ${i}, ${i}[data-filter-instance="${t}"]`:`${i}:not([data-filter-instance])`,o=document.querySelector(r);o&&d(o)},clear:t=>{const e="[data-filter-list]",a=t?`[data-filter-instance="${t}"] ${e}, ${e}[data-filter-instance="${t}"]`:`${e}:not([data-filter-instance])`,n=document.querySelector(a);if(n){const e="[data-filter-field]",a=t?`[data-filter-instance="${t}"] ${e}, ${e}[data-filter-instance="${t}"]`:`${e}:not([data-filter-instance])`;document.querySelectorAll(a).forEach(t=>{const e=t,a=e.tagName.toLowerCase();if("input"===a){const t=e;"checkbox"===t.type||"radio"===t.type?t.checked=!1:t.value=""}else"select"===a?e.selectedIndex=0:e.classList.remove("active")}),d(n)}},getActiveFilters:t=>{const{filters:e}=n(t);return e},refresh:t=>{const e="[data-filter-list]",a=t?`[data-filter-instance="${t}"] ${e}, ${e}[data-filter-instance="${t}"]`:`${e}:not([data-filter-instance])`,n=document.querySelector(a);n&&(s(t,n),m(t),d(n))}};let p=!1,$=!1,y=!1,E=!1;function v(){if(p||(window.filterAPI=h),$||(document.querySelectorAll('input[type="checkbox"][data-filter-field]').forEach(t=>{t.addEventListener("change",()=>{f(t)})}),document.querySelectorAll('input[type="radio"][data-filter-field]').forEach(t=>{t.addEventListener("change",()=>{const a=t.dataset.filterField,n=e(t),l=t.name;if(l)document.querySelectorAll(`input[type="radio"][name="${l}"]`).forEach(e=>{e!==t&&(e.checked=!1)});else if(a){const e=n?`input[type="radio"][data-filter-field="${a}"][data-filter-instance="${n}"], input[type="radio"][data-filter-field="${a}"][data-filter-instance="${n}"]`:`input[type="radio"][data-filter-field="${a}"]:not([data-filter-instance])`;document.querySelectorAll(e).forEach(e=>{e!==t&&(e.checked=!1)})}f(t)})}),document.querySelectorAll("select[data-filter-field]").forEach(t=>{t.addEventListener("change",()=>{f(t)})}),document.querySelectorAll('input[type="text"][data-filter-field], input[type="search"][data-filter-field]').forEach(t=>{let e;const a=t,n=a.dataset.filterDebounce&&parseInt(a.dataset.filterDebounce,10)||300;t.addEventListener("input",()=>{clearTimeout(e),e=setTimeout(()=>{f(a)},n)})}),document.querySelectorAll("[data-filter-field]:not(input):not(select)").forEach(t=>{const e=t;e.setAttribute("role","button"),e.setAttribute("tabindex","0");const a=t=>{t.preventDefault();const a=e.querySelector('input[type="checkbox"], input[type="radio"]');a?(a.checked=!a.checked,f(a)):(e.classList.toggle("active"),f(e))};e.addEventListener("click",a),e.addEventListener("keydown",t=>{"Enter"!==t.key&&" "!==t.key||a(t)})}),$=!0),document.querySelectorAll("select[data-filter-field]").forEach(t=>{const e=t;"true"===e.dataset.filterAutofill&&u(e)}),y||(document.querySelectorAll("[data-filter-clear]").forEach(t=>{t.addEventListener("click",a=>{a.preventDefault();const n=e(t),l="[data-filter-field]",i=n?`[data-filter-instance="${n}"] ${l}, ${l}[data-filter-instance="${n}"]`:`${l}:not([data-filter-instance])`;document.querySelectorAll(i).forEach(t=>{const e=t,a=e.tagName.toLowerCase();if("input"===a){const t=e;"checkbox"===t.type||"radio"===t.type?t.checked=!1:t.value=""}else"select"===a?e.selectedIndex=0:e.classList.remove("active")});const r="[data-filter-list]",o=n?`[data-filter-instance="${n}"] ${r}, ${r}[data-filter-instance="${n}"]`:`${r}:not([data-filter-instance])`,s=document.querySelector(o);if(s){if("true"===s.dataset.filterUrl){const t=new URLSearchParams(window.location.search),e=n?`filter_${n}_`:"filter_";Array.from(t.keys()).forEach(a=>{a.startsWith(e)&&t.delete(a)});const a=`${window.location.pathname}${t.toString()?`?${t.toString()}`:""}${window.location.hash}`;window.history.pushState({},"",a)}const t=s.dataset.filterPersist;if(t)try{const e=`filter_${t}_${n||"default"}`;localStorage.removeItem(e)}catch(t){}d(s);const e=new CustomEvent("filter:clear",{detail:{instance:n}});s.dispatchEvent(e)}})}),y=!0),document.querySelectorAll("[data-filter-list]").forEach(t=>{const a=t,n=e(a),l=a.dataset.filterPersist;l&&function(t,e){try{const a=`filter_${t}_${e||"default"}`,n=localStorage.getItem(a);if(n){const t=JSON.parse(n);Object.entries(t).forEach(([t,a])=>{const n=`[data-filter-field="${t}"]`,l=e?`[data-filter-instance="${e}"] ${n}, ${n}[data-filter-instance="${e}"]`:`${n}:not([data-filter-instance])`;document.querySelectorAll(l).forEach(t=>{const e=t,n=e.tagName.toLowerCase();if("input"===n){const t=e,n=t.value.toLowerCase();"checkbox"===t.type||"radio"===t.type?t.checked=a.includes(n):"text"!==t.type&&"search"!==t.type||(t.value=a[0]||"")}else if("select"===n){const t=e;a.length>0&&(t.value=a[0])}})})}}catch(t){console.warn("Failed to restore filter state from localStorage",t)}}(l,n),"true"===a.dataset.filterUrl&&function(t){const e=new URLSearchParams(window.location.search),a=t?`filter_${t}_`:"filter_";e.forEach((e,n)=>{if(n.startsWith(a)){const l=n.replace(a,""),i=e.split(",").map(t=>t.trim()),r=`[data-filter-field="${l}"]`,o=t?`[data-filter-instance="${t}"] ${r}, ${r}[data-filter-instance="${t}"]`:`${r}:not([data-filter-instance])`;document.querySelectorAll(o).forEach(t=>{const e=t,a=e.tagName.toLowerCase();if("input"===a){const t=e,a=t.value.toLowerCase();"checkbox"===t.type||"radio"===t.type?t.checked=i.includes(a):"text"!==t.type&&"search"!==t.type||(t.value=i[0]||"")}else if("select"===a){const t=e;i.length>0&&(t.value=i[0])}})}})}(n),a.setAttribute("role","region"),a.setAttribute("aria-label","Filtered list"),a.id||(a.id=`filter-list-${n||"default"}-${Date.now()}`);let i=document.querySelector(`#filter-live-${n||"default"}`);i||(i=document.createElement("div"),i.id=`filter-live-${n||"default"}`,i.setAttribute("aria-live","polite"),i.setAttribute("aria-atomic","true"),i.className="sr-only",i.style.cssText="position:absolute;left:-10000px;width:1px;height:1px;overflow:hidden;",document.body.appendChild(i)),s(n,a),m(n),d(a)}),!E){new MutationObserver(()=>{document.querySelectorAll("[data-filter-list]").forEach(t=>{const a=t,n=e(a);s(n,a),m(n)})}).observe(document.body,{childList:!0,subtree:!0}),E=!0}p=!0}return"loading"===document.readyState?document.addEventListener("DOMContentLoaded",v):v(),t.filterAPI=h,t.initFilter=function(){"loading"===document.readyState?document.addEventListener("DOMContentLoaded",v):v()},t}({});
|