first commit
This commit is contained in:
commit
dd6a740645
37 files changed
+5424
No files matched your search
@@ -0,0 +1,33 @@
|
||||
// Live clock for the running timer.
|
||||
function tick() {
|
||||
for (const el of document.querySelectorAll(".clock[data-started]")) {
|
||||
const secs = Math.max(0, Math.floor((Date.now() - Date.parse(el.dataset.started)) / 1000));
|
||||
const h = Math.floor(secs / 3600);
|
||||
const m = String(Math.floor((secs % 3600) / 60)).padStart(2, "0");
|
||||
const s = String(secs % 60).padStart(2, "0");
|
||||
el.textContent = `${h}:${m}:${s}`;
|
||||
}
|
||||
}
|
||||
tick();
|
||||
setInterval(tick, 1000);
|
||||
|
||||
// Show server errors from htmx requests in a toast.
|
||||
let toastTimer;
|
||||
function toast(message) {
|
||||
const el = document.getElementById("toast");
|
||||
el.textContent = message;
|
||||
el.hidden = false;
|
||||
clearTimeout(toastTimer);
|
||||
toastTimer = setTimeout(() => (el.hidden = true), 5000);
|
||||
}
|
||||
document.body.addEventListener("htmx:responseError", (event) => {
|
||||
const html = new DOMParser().parseFromString(event.detail.xhr.responseText, "text/html");
|
||||
toast(html.getElementById("error-message")?.textContent || "Une erreur est survenue");
|
||||
});
|
||||
document.body.addEventListener("htmx:sendError", () => toast("Serveur injoignable"));
|
||||
|
||||
// Confirmation for plain (non-htmx) destructive forms.
|
||||
document.addEventListener("submit", (event) => {
|
||||
const message = event.target.dataset.confirm;
|
||||
if (message && !confirm(message)) event.preventDefault();
|
||||
});
|
||||
Reference in new issue
Block a user