Files
meshero.fr/en.search-dialog.min.fda123910557b5b3a328696105af51f85abc3cfc6784387c49b11b5b857b256f.js
2026-11-08 15:17:21 +01:00

1 line
7.3 KiB
JavaScript

(function(){const S="%d results found",k="No results found.",C=["INPUT","SELECT","BUTTON","TEXTAREA"],A=/iPad|iPhone|Macintosh/.test(navigator.userAgent);let e,t,n,i,a,h,g,s=null,o=null,l=null;document.addEventListener("DOMContentLoaded",T);function T(){if(e=document.getElementById("hextra-search-dialog"),!e)return;t=e.querySelector(".hextra-search-input"),n=e.querySelector(".hextra-search-results"),i=e.querySelector("[data-search-empty]"),a=e.querySelector(".hextra-search-status"),h=e.querySelector("[data-search-viewport]"),g=e.querySelector("[data-search-inner]"),A&&document.querySelectorAll(".hextra-search-trigger-kbd").forEach(e=>{for(;e.firstChild;)e.removeChild(e.firstChild);const t=document.createElement("span");t.style.fontSize="0.75rem",t.textContent="⌘",e.appendChild(t),e.appendChild(document.createTextNode("K"))}),document.querySelectorAll("[data-search-open]").forEach(e=>{e.addEventListener("click",()=>b())});const s=e.querySelector("[data-search-close]");s&&s.addEventListener("click",()=>r()),document.addEventListener("keydown",E),t.addEventListener("input",F),e.addEventListener("keydown",x),e.addEventListener("click",t=>{t.target===e&&r()}),e.addEventListener("close",()=>{t.setAttribute("aria-expanded","false")}),e.addEventListener("cancel",e=>{e.preventDefault(),r()}),n.addEventListener("click",e=>{const t=e.target.closest('a[role="option"]');t&&r()}),n.addEventListener("mousemove",e=>{const t=e.target.closest('a[role="option"]');t&&d(t,{scroll:!1})}),n.addEventListener("focusin",e=>{const t=e.target.closest('a[role="option"]');t&&d(t,{scroll:!1})})}function O(e){const t=e&&e.tagName;return!!e&&(C.includes(t)||e.isContentEditable)}function c(e){e?t.setAttribute("aria-activedescendant",e):t.removeAttribute("aria-activedescendant")}function E(t){const n=O(document.activeElement);if(t.key==="k"&&(t.metaKey||t.ctrlKey)){if(n)return;t.preventDefault();const s=e.dataset.state==="closing";e.open&&!s?r():b();return}if(e.open)return;if(t.key==="/"){if(n)return;t.preventDefault(),b()}}function b(){if(e.open&&e.dataset.state==="closing"){M(),t.focus(),t.select();return}if(e.open)return;e.showModal(),t.setAttribute("aria-expanded","true"),requestAnimationFrame(()=>{t.focus(),t.select()}),window.hextraSearch&&window.hextraSearch.preload().catch(()=>{})}function M(){s&&(e.removeEventListener("animationend",s),s=null),o!==null&&(clearTimeout(o),o=null),delete e.dataset.state}function r(){if(!e.open||e.dataset.state==="closing")return;v();const n=window.matchMedia("(prefers-reduced-motion: reduce)").matches;if(n){e.close();return}e.dataset.state="closing";const t=()=>{o!==null&&(clearTimeout(o),o=null),s&&(e.removeEventListener("animationend",s),s=null),e.dataset.state==="closing"&&(delete e.dataset.state,e.close())};s=e=>{if(e.animationName!=="hextra-search-backdrop-out")return;t()},e.addEventListener("animationend",s),o=setTimeout(t,400)}function m(e){if(!h)return;h.dataset.expanded=e?"true":"false"}function v(){l!==null&&(clearTimeout(l),l=null)}function j(){for(;n.firstChild;)n.removeChild(n.firstChild)}function x(e){const n=e.target.closest('a[role="option"]'),o=e.target===t;if(!o&&!n)return;if(o&&(e.isComposing||e.keyCode===229))return;const s=!!n;switch(e.key){case"ArrowDown":e.preventDefault(),_(1,{current:n,focus:s});break;case"ArrowUp":e.preventDefault(),_(-1,{current:n,focus:s});break;case"Home":{const t=u();if(!t.length)return;e.preventDefault(),p(t[0],{focus:s});break}case"End":{const t=u();if(!t.length)return;e.preventDefault(),p(t[t.length-1],{focus:s});break}case"Enter":{if(!o)return;const t=y();if(!t)return;e.preventDefault(),t.click();break}case"Escape":e.preventDefault(),r();break}}function u(){return Array.from(n.querySelectorAll('a[role="option"]'))}function y(){return n.querySelector('a[aria-selected="true"]')}function d(e,t){const n=!t||t.scroll!==!1;u().forEach(t=>{t.setAttribute("aria-selected",t===e?"true":"false")}),e?(c(e.id),n&&e.scrollIntoView({block:"nearest"})):c()}function w(e){d(e,{scroll:!1}),e.focus({preventScroll:!0}),e.scrollIntoView({block:"nearest"})}function p(e,t){t&&t.focus?w(e):d(e)}function _(e,t){const n=u();if(!n.length)return;const o=t&&t.current||y();let s=n.indexOf(o);s===-1?s=e>0?0:n.length-1:s=(s+e+n.length)%n.length,p(n[s],t)}async function F(e){if(e&&e.isComposing)return;const n=t.value.trim();if(!n){c(),a&&(a.textContent=""),m(!1),v(),l=setTimeout(()=>{l=null,j(),i&&(i.hidden=!0)},250);return}if(!window.hextraSearch)return;let s;try{s=await window.hextraSearch.search(n)}catch(e){if(t.value.trim()!==n)return;console.warn("[hextra-search]",e),s=[]}if(t.value.trim()!==n)return;N(s,n)}function f(e,t,n){if(!t)return;if(!n){e.textContent=t;return}const i=n.replace(/[-\\^$*+?.()|[\]{}]/g,"\\$&");if(!i){e.textContent=t;return}const a=new RegExp(i,"gi");let o=0,s;for(;(s=a.exec(t))!==null;){s.index>o&&e.appendChild(document.createTextNode(t.slice(o,s.index)));const n=document.createElement("span");n.className="hextra-search-match",n.textContent=s[0],e.appendChild(n),o=s.index+s[0].length}o<t.length&&e.appendChild(document.createTextNode(t.slice(o)))}function z(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.classList.add("hextra-search-crumb-separator"),e.setAttribute("viewBox","0 0 24 24"),e.setAttribute("fill","none"),e.setAttribute("stroke","currentColor"),e.setAttribute("stroke-width","2"),e.setAttribute("stroke-linecap","round"),e.setAttribute("stroke-linejoin","round"),e.setAttribute("aria-hidden","true"),e.setAttribute("focusable","false");const t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d","m9 18 6-6-6-6"),e.appendChild(t),e}function D(e,t){for(let n=0;n<t.length;n++){n>0&&e.appendChild(z());const s=document.createElement("span");s.textContent=t[n],e.appendChild(s)}}function N(e,t){if(v(),j(),g&&(g.scrollTop=0),!e.length){i&&(i.hidden=!1),a&&(a.textContent=k),c(),m(!0);return}i&&(i.hidden=!0);const o=document.createDocumentFragment();let s=!0,r=0;for(let a=0;a<e.length;a++){const n=e[a],c=document.createElement("li");c.setAttribute("role","presentation");const i=document.createElement("a");if(i.id=n.id,i.href=n.route,i.setAttribute("role","option"),i.setAttribute("aria-selected",s?"true":"false"),s=!1,r++,n.breadcrumbs&&n.breadcrumbs.length){const e=document.createElement("div");e.className="hextra-search-crumb",e.setAttribute("aria-label",n.breadcrumbs.join(" > ")),D(e,n.breadcrumbs),i.appendChild(e)}const l=document.createElement("div");l.className="hextra-search-title",f(l,n.title,t),i.appendChild(l),c.appendChild(i),o.appendChild(c);for(let c=0;c<n.matches.length;c++){const e=n.matches[c],l=e.content&&e.content!==e.title;if(e.title===n.title&&!l)continue;const a=document.createElement("li");a.setAttribute("role","presentation"),a.classList.add("hextra-search-child");const i=document.createElement("a");i.id=e.id,i.href=e.route,i.setAttribute("role","option"),i.setAttribute("aria-selected",s?"true":"false"),s=!1,r++;const d=l?`${e.title} - ${e.content}`:e.title;if(d&&i.setAttribute("aria-label",d),e.title&&e.title!==n.title){const n=document.createElement("div");n.className="hextra-search-title",f(n,e.title,t),i.appendChild(n)}if(l){const n=document.createElement("div");n.className="hextra-search-excerpt",f(n,e.content,t),i.appendChild(n)}a.appendChild(i),o.appendChild(a)}}n.appendChild(o);const l=n.querySelector('a[role="option"]');c(l&&l.id),a&&(a.textContent=S.replace("%d",r.toString())),m(!0)}})()