diff --git a/static/app.js b/static/app.js index 934f093..4207579 100644 --- a/static/app.js +++ b/static/app.js @@ -205,20 +205,41 @@ function renderMain() { } const el = $("#page"); if (!S.me) { - el.innerHTML = registerPage(); + // Only redraw when the form itself changes: replacing the name field under + // a phone's keyboard closes the keyboard. + const html = registerPage(); + if (el.dataset.html !== html) { + el.innerHTML = html; + el.dataset.html = html; + $("#name").value = remember("draftName") || ""; + } return; } if (page === "chat") { seenChat = Math.max(seenChat, ...S.chat.map((m) => m.t), 0); remember("seenChat", seenChat); } + // Never redraw under a focused field (the chat box aside): on a phone that + // closes the keyboard or the open dropdown. The next render catches up. + const focused = document.activeElement; + const typing = focused && el.contains(focused) && focused.matches("input, select, textarea"); + if (page === "chat" && el.querySelector("#say")) { + // The chat box stays put (and keeps the keyboard); only the lists refresh. + const holder = document.createElement("div"); + holder.innerHTML = chatPage(); + for (const id of ["chatlog", "worldlog"]) { + const fresh = holder.querySelector("#" + id).innerHTML; + const old = el.querySelector("#" + id); + if (old.innerHTML !== fresh) old.innerHTML = fresh; + } + return; + } + if (typing) return; const html = { adventure: adventurePage, quests: questsPage, character: characterPage, group: groupPage, chat: chatPage }[page](); - // Keep a half-typed chat message across re-renders. - const typing = document.activeElement?.id === "say" ? document.activeElement.value : null; - if (typing !== null && page === "chat") return; if (el.dataset.html !== html) { el.innerHTML = html; el.dataset.html = html; + animate(); } } @@ -230,7 +251,7 @@ function registerPage() { return `

Create your character

You wake in Northshire Abbey. The Defias Brotherhood stirs in Westfall.

-
+

Class

${Object.entries(C.classes).map(([id, c]) => `
@@ -284,14 +305,13 @@ function statusCard() { const act = me.activity; const t = now(); if (me.dead_until > t) { - return `
๐Ÿ’€ You died. Running back ยท ${clock(me.dead_until - t)}
`; + return `
๐Ÿ’€ You died. Running back ยท
`; } if (!act) return ""; if (act.kind === "travel") { - const done = (t - act.start) / (act.end - act.start); return `
-
๐ŸŽ On the road to ${esc(place(act.to).name)}${clock(act.end - t)}
-
+
๐ŸŽ On the road to ${esc(place(act.to).name)}
+
${act.path.map((p) => esc(place(p).name)).join(" โ†’ ")}
`; } @@ -300,7 +320,7 @@ function statusCard() { const waiting = !S.fight && me.next_pull > t; return `
๐ŸŽฏ Hunting ${esc(mob.name)} - ${waiting ? `resting ยท ${clock(me.next_pull - t)}` : ""} + ${waiting ? `resting ยท ` : ""}
`; } @@ -322,7 +342,7 @@ function dungeonCard() { }).join(""); let status = ""; if (d.state === "rest") { - status = `
${d.last && !d.last.won ? "๐Ÿ’€ Wiped. " : ""}Next pull in ${clock(d.next - t)} + status = `
${d.last && !d.last.won ? "๐Ÿ’€ Wiped. " : ""}Next pull in ${leader ? `` : `the leader can pull early`}
`; } else if (d.state === "done") { status = `
๐Ÿ† ${esc(spec.name)} cleared!
`; @@ -603,8 +623,8 @@ function chatPage() { const events = S.log.slice().reverse().map((l) => `
${esc(l.text)} ยท ${ago(l.t)}
`).join(""); return `

Guild chat

-
${msgs || 'Quiet in here.'}
-

World

${events}
`; +
${msgs || 'Quiet in here.'}
+

World

${events}
`; } // --- the fight ---------------------------------------------------------- @@ -830,6 +850,7 @@ document.addEventListener("click", async (ev) => { if (cls) { remember("draftName", $("#name")?.value || ""); regCls = cls.dataset.cls; + document.activeElement?.blur(); render(); return; } @@ -881,6 +902,10 @@ document.addEventListener("keydown", (ev) => { } }); +document.addEventListener("input", (ev) => { + if (ev.target.id === "name") remember("draftName", ev.target.value); +}); + document.addEventListener("change", (ev) => { if (ev.target.id === "dev-user") { document.cookie = `wog_user=${encodeURIComponent(ev.target.value)}; path=/; max-age=31536000`;