// Theme switch, the list filter and delete confirmations. Event delegation // and no inline handlers: the Content Security Policy allows no inline script. (function () { "use strict"; // ---- theme: , kept in localStorage document.addEventListener("click", function (ev) { var b = ev.target.closest && ev.target.closest("#themeBtn"); if (!b) return; var root = document.documentElement; var next = root.getAttribute("data-theme") === "light" ? "dark" : "light"; root.setAttribute("data-theme", next); try { localStorage.setItem("visa-theme", next); } catch (e) { /* storage blocked */ } }); // ---- forms with data-confirm ask first (archive, delete) document.addEventListener("submit", function (ev) { var f = ev.target; var msg = f && f.getAttribute && f.getAttribute("data-confirm"); if (msg && !window.confirm(msg)) ev.preventDefault(); }); // ---- filter: rows carry data-q (lower case); "/" focuses the box function applyFilter() { var box = document.getElementById("q"); if (!box) return; var q = box.value.trim().toLowerCase(); var rows = document.querySelectorAll("[data-q]"); var shown = 0; rows.forEach(function (el) { var hit = q === "" || el.getAttribute("data-q").indexOf(q) !== -1; el.hidden = !hit; if (hit) shown++; }); document.querySelectorAll("[data-filter-empty]").forEach(function (el) { el.hidden = q === "" || rows.length === 0 || shown > 0; }); } document.addEventListener("input", function (ev) { if (ev.target && ev.target.id === "q") applyFilter(); }); document.addEventListener("keydown", function (ev) { var box = document.getElementById("q"); if (!box) return; var tag = document.activeElement ? document.activeElement.tagName : ""; if (ev.key === "/" && !/^(INPUT|TEXTAREA|SELECT)$/.test(tag)) { ev.preventDefault(); box.focus(); } else if (ev.key === "Escape" && document.activeElement === box) { box.value = ""; applyFilter(); box.blur(); } }); document.addEventListener("DOMContentLoaded", applyFilter); })();