// Digest signup form. Loaded on every page (base.html.j2). // // It degrades: the form is a real
that works with this // file blocked. // // The product-event beacon used to live here; it now lives in track.js, which // also owns the [data-event] click delegation this file used to do. `track` is // re-exported for the pages that import it from here. export { track, trackLegacy } from "./track.js"; import { trackLegacy } from "./track.js"; // --- digest form ------------------------------------------------------------- for (const form of document.querySelectorAll("form[data-digest]")) { const status = form.querySelector(".digest-status"); const button = form.querySelector("button[type=submit]"); form.addEventListener("submit", async (e) => { e.preventDefault(); const email = form.querySelector("input[name=email]")?.value?.trim(); if (!email) return; button.disabled = true; try { const res = await fetch(form.action, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email, place: form.dataset.place || null }), }); const data = await res.json().catch(() => ({})); if (status) { status.textContent = data.message || "Something went wrong. Try again."; status.hidden = false; } if (res.ok) { // Collapse the inputs on success so the confirmation is the only thing // left to read; the form is done either way. form.querySelector(".digest-row")?.setAttribute("hidden", ""); form.querySelector(".digest-note")?.setAttribute("hidden", ""); trackLegacy("home.digest_signup"); } } catch { if (status) { status.textContent = "Couldn't reach the server. Try again."; status.hidden = false; } } finally { button.disabled = false; } }); }