document.addEventListener("DOMContentLoaded", function() {/* --- OPEN MODAL --- */ document.querySelectorAll('a[href="#search-modal"]').forEach(btn => { btn.addEventListener('click', function(e) { e.preventDefault(); document.getElementById("search-modal").classList.add("active"); document.getElementById("eh-live-search-input").focus(); }); });/* --- CLOSE MODAL --- */ document.querySelector(".eh-search-close").addEventListener("click", function() { document.getElementById("search-modal").classList.remove("active"); });document.getElementById("search-modal").addEventListener("click", function(e) { if (e.target.id === "search-modal") this.classList.remove("active"); });/* --- LIVE SEARCH --- */ const input = document.getElementById("eh-live-search-input"); const results = document.getElementById("eh-live-results");let timer;input.addEventListener("keyup", function() { clearTimeout(timer); const query = this.value.trim();if (query.length < 2) { results.innerHTML = ""; return; }timer = setTimeout(() => { fetch(`/wp-json/wp/v2/search?search=${encodeURIComponent(query)}&per_page=8`) .then(res => res.json()) .then(data => {if (data.length === 0) { results.innerHTML = `
Ingen treff …
`; return; }let html = ""; data.forEach(item => { html += `
${item.title}
`; });results.innerHTML = html; }); }, 250); // léger délai pour fluidité });});