Home: two-window explainer, code settings tucked away; projector: light entrance and exit motion

This commit is contained in:
2026-08-17 01:46:18 +01:00
parent 080f516f53
commit 389572d09e
5 changed files with 119 additions and 49 deletions
+54 -19
View File
@@ -8,22 +8,43 @@ let qr = null; // current code message, qr or ring
let raf = 0;
let entry = null;
let prevBits = null, switchedAt = 0;
let focusView = "";
// shows at once (css plays the entrance), hides after a short exit so blocks don't just vanish
function reveal(el, on) {
if (on) {
clearTimeout(el._leave);
el.classList.remove("leaving");
el.hidden = false;
return;
}
if (el.hidden || el.classList.contains("leaving")) return;
el.classList.add("leaving");
el._leave = setTimeout(() => { el.hidden = true; el.classList.remove("leaving"); }, 220);
}
// restarts a css animation class on an element that stays in the dom
function replay(el, cls) {
el.classList.remove(cls);
void el.offsetWidth;
el.classList.add(cls);
}
function layout() {
if (!st) return;
// qr stays up while enrolling, and during a vote that needs a presence scan
const qrOn = st.enrollment_open || st.presence;
const focus = st.focus;
$("#enroll").hidden = !qrOn;
$("#focus").hidden = !focus;
$("#idle").hidden = qrOn || !!focus;
reveal($("#enroll"), qrOn);
reveal($("#focus"), !!focus);
reveal($("#idle"), !qrOn && !focus);
$(".s-main").classList.toggle("split", qrOn && !!focus);
const ring = st.code_style === "ring";
$("#qr-title").textContent = st.enrollment_open ? "Inscription" : ring ? "Visez le cercle pour voter" : "Scannez pour voter";
$("#qr-steps").hidden = !st.enrollment_open;
// rings can't be opened by the camera app, so a small fixed qr leads to the page
$("#step1").textContent = ring ? "Ouvrez la page de vote" : "Scannez ce code";
$("#entry").hidden = !(ring && st.enrollment_open && entry);
reveal($("#entry"), !!(ring && st.enrollment_open && entry));
$(".qr-wrap").classList.toggle("ring", ring);
}
@@ -31,27 +52,41 @@ function render() {
$("#s-title").textContent = st.title;
$("#idle-title").textContent = st.title;
document.title = st.title;
$("#voters").textContent = st.voters;
if ($("#voters").textContent !== String(st.voters)) {
$("#voters").textContent = st.voters;
replay($("#voters"), "bump");
}
$("#voters-label").textContent =
`inscription${st.voters > 1 ? "s" : ""}` + (st.expected ? ` sur ${st.expected}` : "");
$("#secs").textContent = Math.ceil((st.scans_required * st.interval_ms) / 1000);
const f = st.focus;
const box = $("#focus");
box.replaceChildren();
if (f) {
box.append(h("div", { class: "q-text" }, f.text));
if (f.state === "open") {
box.append(
h("ul", { class: "opts" }, f.options.map((o) => h("li", {}, o))),
h("div", { class: "turnout" },
h("b", {}, f.participants), ` vote${f.participants > 1 ? "s" : ""} sur ${st.voters}`,
h("div", { class: "progress" }, fill(pct(f.participants, st.voters), ""))),
);
} else if (f.results) {
box.append(resultsView(f));
} else {
box.append(h("p", { class: "status" }, `Vote clos, ${f.participants} vote${f.participants > 1 ? "s" : ""}`));
const view = f ? `${f.id}|${f.state}|${f.results ? 1 : 0}|${f.text}` : "";
if (f && view === focusView && f.state === "open") {
// same question still open: only the turnout moves, in place so the bar slides
const t = box.querySelector(".turnout");
t.querySelector("b").textContent = f.participants;
t.querySelector(".t-of").textContent = ` vote${f.participants > 1 ? "s" : ""} sur ${st.voters}`;
t.querySelector(".progress > div").style.width = `${pct(f.participants, st.voters)}%`;
} else if (view !== focusView) {
focusView = view;
if (f) {
// the old question fades with the section when there is no new one
box.replaceChildren(h("div", { class: "q-text" }, f.text));
if (f.state === "open") {
box.append(
h("ul", { class: "opts" }, f.options.map((o) => h("li", {}, o))),
h("div", { class: "turnout" },
h("b", {}, f.participants), h("span", { class: "t-of" }, ` vote${f.participants > 1 ? "s" : ""} sur ${st.voters}`),
h("div", { class: "progress" }, fill(pct(f.participants, st.voters), ""))),
);
} else if (f.results) {
box.append(resultsView(f));
} else {
box.append(h("p", { class: "status" }, `Vote clos, ${f.participants} vote${f.participants > 1 ? "s" : ""}`));
}
replay(box, "enter");
}
}
layout();