1
Fork 0
modal-dialog/app.js
Leonardo Devai 3a0dc902e5 Review and modernize all 42 projects to the updated standard
Pinned 2026 toolchains (Go 1.26, Rust 1.98/edition 2024, Python 3.14 + uv, Node 24,
Zig 0.16, NixOS 26.05), postgres 18 / mongo 8, lockfiles built from, non-root
runtimes, .dockerignore, per-project LICENSE, READMEs with the git.devai.io clone
line, checkout@v7 CI. Security fixes in the legacy Rust APIs (any-password login,
self-assigned admin, hard-coded JWT secret), JWT alg/exp/sub enforcement across the
blog series, safe markdown links in the frontends, and many smaller bugs — every
project was built, run and exercised end to end.

Adds scripts/publish.sh + a CI publish job that splits every folder into its own
repo at git.devai.io/templates/<folder>.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01128fhuZbgivaSJvtMf4s1G
2026-09-27 21:10:38 +02:00

30 lines
1.3 KiB
JavaScript

const dialog = document.getElementById("dialog");
const openBtn = document.getElementById("open");
const closeBtn = document.getElementById("close");
const okBtn = document.getElementById("ok");
const status = document.getElementById("status");
// showModal() is the whole trick: the browser dims the page behind a
// ::backdrop, makes it inert, moves focus into the dialog, closes it on Escape,
// and hands focus back to this button afterwards. No library needed.
openBtn.addEventListener("click", () => {
dialog.returnValue = ""; // forget why it closed last time
dialog.showModal();
});
// close(value) records WHY it closed in dialog.returnValue.
closeBtn.addEventListener("click", () => dialog.close("dismissed"));
okBtn.addEventListener("click", () => dialog.close("ok"));
// A click on the dimmed backdrop lands on the <dialog> element itself; clicks
// on the content land on its children. The dialog has no padding and the inner
// .dialog-body fills it, so "target is the dialog" means "outside the box".
dialog.addEventListener("click", (event) => {
if (event.target === dialog) dialog.close("backdrop");
});
// "close" fires however it closed. Escape sets no returnValue, so an empty
// one means the user pressed Escape.
dialog.addEventListener("close", () => {
status.textContent = `The dialog is closed (${dialog.returnValue || "escape"}).`;
});