File size: 2,318 Bytes
187ef74 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | // Eventbrite frontend interaction behavior.
// Shared navigation uses ordinary local URLs so Back/Forward and refresh
// stay deterministic; this script only adds progressive enhancements.
(function () {
"use strict";
// Checkout modal: Escape closes the overlay by navigating back to the
// event detail (data-close-href). Focus is captured on open and the
// browser restores scroll/focus context on the ordinary-URL navigation;
// lastFocus keeps a same-page fallback restore.
var modal = document.querySelector('[data-modal="checkout"]');
var lastFocus = null;
if (modal && modal.getAttribute("data-escape-closes") === "true") {
var closeHref = modal.getAttribute("data-close-href");
lastFocus = document.activeElement;
modal.focus();
document.addEventListener("keydown", function (event) {
if (event.key === "Escape" && closeHref) {
event.preventDefault();
if (lastFocus && lastFocus.focus) { lastFocus.focus(); }
window.location.assign(closeHref);
}
});
}
// History support: every state is a stable URL, so browser
// Back/Forward (popstate) always lands on a deterministic server render.
window.addEventListener("popstate", function () {
// Server-rendered pages are the source of truth; nothing to hydrate.
});
// Quantity cap enforcement (client hint only; the server re-validates and
// is authoritative for caps, capacity, and pricing).
var qty = document.getElementById("qty");
if (qty) {
var totals = document.querySelectorAll("[data-order-total]");
var unitCents = parseInt(qty.getAttribute("data-unit-price-cents"), 10);
// Preview the total for the chosen quantity. The server re-prices the
// order from its own ticket class, so this never decides what is paid.
function previewTotal() {
if (isNaN(unitCents)) return;
var cents = unitCents * parseInt(qty.value, 10);
var text = "$" + (cents / 100).toFixed(2);
for (var i = 0; i < totals.length; i++) totals[i].textContent = text;
}
qty.addEventListener("change", function () {
var max = qty.options.length;
var value = parseInt(qty.value, 10);
if (isNaN(value) || value < 1) qty.value = "1";
if (value > max) qty.value = String(max);
previewTotal();
});
}
})();
|