// Info-tooltips (i): tonen bij hover, toetsenbordfocus en als het veld in // hetzelfde label focus heeft (CSS). Op touch opent een tik de uitleg; // tik ernaast of Escape sluit hem. Zichtbare .tip-b blijft in het // viewport (fixed, geklemd of omgeklapt). (function () { var GAP = 8; function closeAll(except) { document.querySelectorAll(".tip.open").forEach(function (t) { if (t !== except) { t.classList.remove("open"); var b = t.querySelector(".tip-i"); if (b) { b.setAttribute("aria-expanded", "false"); } } }); } function placeBody(body, anchor) { body.classList.remove("above"); body.style.position = "fixed"; body.style.left = "0px"; body.style.top = "0px"; body.style.right = "auto"; var rect = anchor.getBoundingClientRect(); var w = body.offsetWidth; var h = body.offsetHeight; var vw = document.documentElement.clientWidth; var vh = document.documentElement.clientHeight; var left = rect.left; var top = rect.bottom + GAP; var above = false; if (top + h > vh - GAP && rect.top - GAP - h >= GAP) { top = rect.top - GAP - h; above = true; } if (left + w > vw - GAP) { left = vw - GAP - w; } if (left < GAP) { left = GAP; } if (top + h > vh - GAP) { top = Math.max(GAP, vh - GAP - h); } if (top < GAP) { top = GAP; } body.classList.toggle("above", above); body.style.left = Math.round(left) + "px"; body.style.top = Math.round(top) + "px"; } function clearBody(body) { body.classList.remove("above"); body.style.position = ""; body.style.left = ""; body.style.top = ""; body.style.right = ""; } function repositionTips() { document.querySelectorAll(".tip-b").forEach(function (body) { if (getComputedStyle(body).display === "none") { clearBody(body); return; } var tip = body.closest(".tip"); var anchor = (tip && tip.querySelector(".tip-i")) || body.parentElement; if (anchor) { placeBody(body, anchor); } }); } function schedulePlace() { requestAnimationFrame(repositionTips); } document.addEventListener("click", function (e) { var btn = e.target.closest && e.target.closest(".tip-i"); if (!btn) { closeAll(null); schedulePlace(); return; } e.preventDefault(); var tip = btn.closest(".tip"); var open = !tip.classList.contains("open"); closeAll(tip); tip.classList.toggle("open", open); btn.setAttribute("aria-expanded", open ? "true" : "false"); schedulePlace(); }); document.addEventListener("keydown", function (e) { if (e.key === "Escape") { closeAll(null); schedulePlace(); return; } var btn = e.target.closest && e.target.closest(".tip-i"); if (btn && (e.key === "Enter" || e.key === " ")) { e.preventDefault(); btn.click(); } }); document.addEventListener("pointerover", function (e) { if (e.target.closest && e.target.closest(".tip, .tiphost")) { schedulePlace(); } }); document.addEventListener("focusin", function (e) { if (e.target.closest && e.target.closest(".tip, .tiphost")) { schedulePlace(); } }); window.addEventListener("scroll", repositionTips, true); window.addEventListener("resize", repositionTips); })();