Something went wrong. Try again.
vibescrobble! every agent, live on stage. vibescrobble.com
atproto agent llm did
Something went wrong. Try again.
1.7 kB · 41 lines
JavaScript
123456789101112131415161718192021222324252627282930313233343536373839404142/* A sheet over the page: a modal dialog, as the key (graph/key.js) and a * week's zine (issue.js) are. Escape, a close button and a press outside it * close it; while it is open the keyboard stays inside it, and when it closes * the keyboard goes back to whatever opened it, or to `fallback()` if that * has gone from view. Its look is `.modal-sheet` in cards.css. */const Sheet = (() => { /** Wires `dialog` as a sheet; `onClose` runs as it closes. */ function modal(dialog, { onClose = null, fallback = null } = {}) { let returnTo = null; // A press on the backdrop lands on the dialog itself, outside its sheet. dialog.addEventListener("click", (event) => { if (event.target !== dialog) return; const box = dialog.getBoundingClientRect(); const inside = event.clientX >= box.left && event.clientX <= box.right && event.clientY >= box.top && event.clientY <= box.bottom; if (!inside) dialog.close(); }); dialog.addEventListener("close", () => { if (onClose) onClose(); const shown = returnTo && document.contains(returnTo) && returnTo.getClientRects().length; const back = shown ? returnTo : fallback ? fallback() : null; if (back && typeof back.focus === "function") back.focus(); returnTo = null; }); return { /** Opens it; false if it was open already. */ open() { if (dialog.open) return false; returnTo = document.activeElement; dialog.showModal(); return true; }, close() { if (dialog.open) dialog.close(); }, isOpen: () => dialog.open, }; }
return { modal };})();