/*! Fiesta 1.0.0 | MPL-2.0 | https://fiesta.rastrillo.org */ (function () { "use strict"; var HOLD_MS = 650; function busyOff(form) { form.removeAttribute("aria-busy"); document.querySelectorAll('[aria-busy="true"]').forEach(function (b) { if (b.form !== form && !form.contains(b)) return; b.disabled = false; b.removeAttribute("aria-busy"); var spin = b.querySelector("[rst-spin]"); if (spin) spin.remove(); var idle = b.getAttribute("data-idle-label"); if (idle === null) return; if (b.tagName === "INPUT") { b.value = idle; } else { b.textContent = idle; } b.removeAttribute("data-idle-label"); }); } function busySubmit(e) { var form = e.target; if (!form || form.tagName !== "FORM") return; if (form.hasAttribute("data-pow-form") && !form.hasAttribute("data-pow-released")) return; if (form.getAttribute("data-busy") === "false") return; var btn = e.submitter; var to = (btn && btn.getAttribute("formtarget")) || form.getAttribute("target"); if (to && to !== "_self") return; if (/^dialog$/i.test(btn && btn.getAttribute("formmethod") || form.getAttribute("method"))) return; if (form === releasing) return; if (form.getAttribute("aria-busy") === "true") { e.preventDefault(); return; } form.setAttribute("aria-busy", "true"); if (!btn || btn.getAttribute("data-busy") === "false") btn = null; var label = btn && (btn.getAttribute("data-busy-label") || form.getAttribute("data-busy-label")); if (btn) { btn.setAttribute("aria-busy", "true"); if (btn.tagName === "BUTTON") { if (label) { btn.setAttribute("data-idle-label", btn.textContent); btn.textContent = label; } var spin = document.createElement("span"); spin.setAttribute("rst-spin", ""); spin.setAttribute("aria-hidden", "true"); btn.insertBefore(spin, btn.firstChild); } } setTimeout(function () { if (e.defaultPrevented && !held.has(e)) { busyOff(form); return; } if (!btn) return; if (label && btn.tagName === "INPUT") { btn.setAttribute("data-idle-label", btn.value); btn.value = label; } btn.disabled = true; }, 0); } document.addEventListener("submit", busySubmit, true); var held = new WeakSet(); var pending = new Map(); var releasing = null; window.addEventListener("submit", function (e) { var form = e.target; if (!form || form.tagName !== "FORM") return; if (form === releasing) { releasing = null; return; } if (form.hasAttribute("data-pow-form")) return; if (e.defaultPrevented || form.getAttribute("aria-busy") !== "true") return; var btn = e.submitter || null; if (!btn || btn.getAttribute("aria-busy") !== "true") return; e.preventDefault(); held.add(e); pending.set(form, setTimeout(function () { release(form, btn); }, HOLD_MS)); if (pending.size === 1) window.addEventListener("beforeunload", dropHeld); }); function release(form, btn) { pending.delete(form); if (pending.size === 0) window.removeEventListener("beforeunload", dropHeld); if (!form.isConnected) return; var skip = form.hasAttribute("novalidate") || (btn && btn.hasAttribute("formnovalidate")); if (!skip && !form.checkValidity()) { busyOff(form); form.reportValidity(); return; } if (btn && (!btn.isConnected || btn.form !== form)) { busyOff(form); return; } var busyValue = null; var wasDisabled = btn ? btn.disabled : false; if (btn) { btn.disabled = false; var idle = btn.getAttribute("data-idle-label"); if (btn.tagName === "INPUT" && idle !== null) { busyValue = btn.value; btn.value = idle; } } releasing = form; try { form.requestSubmit(btn || undefined); } finally { releasing = null; if (btn) { btn.disabled = wasDisabled; if (busyValue !== null) btn.value = busyValue; } } } function dropHeld() { pending.forEach(function (timer, form) { clearTimeout(timer); busyOff(form); }); pending.clear(); window.removeEventListener("beforeunload", dropHeld); } window.addEventListener("pagehide", function () { dropHeld(); }); window.addEventListener("pageshow", function (e) { if (e.persisted) document.querySelectorAll("form[aria-busy]").forEach(busyOff); }); })();