Skip to content

Commit b5ae25c

Browse files
TMHSDigitalclaude
andcommitted
site: cards open entry pages; retire the entry dialog
The whole card is now a stretched link to entry/<id>/. Back restores the filtered view and scroll position; old #entry-<id> links redirect to the page. The coarse-pointer rule on the title is gone so the stretched link covers the card on touch screens too. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Wc67NX9MM964uaVGn4bpZJ
1 parent f1045b0 commit b5ae25c

4 files changed

Lines changed: 68 additions & 317 deletions

File tree

‎site/build.mjs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ function entryRowHtml(entry, repo, now) {
210210
<span class="entry-edge" aria-hidden="true"></span>
211211
<div class="entry-body">
212212
<div class="entry-top">
213-
<h3><a class="entry-link" href="#entry-${esc(entry.id)}" data-id="${esc(entry.id)}">${esc(entry.name)}</a></h3>
213+
<h3><a class="entry-link" href="entry/${esc(entry.id)}/" data-id="${esc(entry.id)}">${esc(entry.name)}</a></h3>
214214
<span class="entry-flags">${flags}</span>
215215
</div>
216216
<p>${esc(entry.summary || "")}</p>
@@ -281,7 +281,7 @@ function starterRowsHtml(featured) {
281281
.map(
282282
(e) => `<tr>
283283
<td class="need">${esc(e.need || "")}</td>
284-
<td><a href="${esc(e.url)}" rel="noopener noreferrer">${esc(e.name)}</a></td>
284+
<td><a href="entry/${esc(e.id)}/">${esc(e.name)}</a></td>
285285
<td class="license">${esc(e.license)} &middot; ${esc(commercialLabel(e.commercial))}</td>
286286
</tr>`
287287
)

‎site/public/app.js‎

Lines changed: 43 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@
3030
const categoryLabels = data.categories || {};
3131
const repo = data.site?.repo || "https://github.com/TMHSDigital/Free-Game-Dev-Assets";
3232
const byId = Object.fromEntries(data.entries.map((e) => [e.id, e]));
33+
34+
// Old permalinks (#entry-<id>) now have real pages.
35+
const legacy = location.hash.match(/^#entry-(.+)$/);
36+
if (legacy && byId[decodeURIComponent(legacy[1])]) {
37+
location.replace(`entry/${encodeURIComponent(decodeURIComponent(legacy[1]))}/`);
38+
return;
39+
}
3340
const PERSPECTIVE_LABELS = {
3441
top_down: "top-down",
3542
isometric_3_4: "3/4 view",
@@ -195,7 +202,7 @@
195202
<span class="entry-edge" aria-hidden="true"></span>
196203
<div class="entry-body">
197204
<div class="entry-top">
198-
<h3><a class="entry-link" href="#entry-${escapeHtml(entry.id)}" data-id="${escapeHtml(entry.id)}">${escapeHtml(entry.name)}</a></h3>
205+
<h3><a class="entry-link" href="entry/${escapeHtml(entry.id)}/" data-id="${escapeHtml(entry.id)}">${escapeHtml(entry.name)}</a></h3>
199206
<span class="entry-flags">${flags}</span>
200207
</div>
201208
<p>${escapeHtml(entry.summary || "")}</p>
@@ -322,25 +329,21 @@
322329
grid.innerHTML = "";
323330
empty.hidden = false;
324331
groupHeadings = [];
325-
displayOrder = [];
326332
return;
327333
}
328334
empty.hidden = true;
329335

330336
if (!shouldGroup()) {
331337
grid.innerHTML = list.map(cardHtml).join("");
332338
groupHeadings = [];
333-
displayOrder = list;
334339
syncSpy();
335340
return;
336341
}
337342

338343
const out = [];
339-
displayOrder = [];
340344
for (const cat of Object.keys(categoryLabels)) {
341345
const group = list.filter((e) => e.category === cat);
342346
if (!group.length) continue;
343-
displayOrder.push(...group);
344347
const label = categoryLabels[cat]?.label || cat;
345348
out.push(
346349
`<h3 class="group-heading" id="group-${escapeHtml(cat)}" data-cat="${escapeHtml(cat)}">` +
@@ -419,7 +422,7 @@
419422
if (!entry || !byId[entry.id]) return "";
420423
return `<tr>
421424
<td class="need">${escapeHtml(entry.need || "")}</td>
422-
<td><a href="${escapeHtml(entry.url)}" rel="noopener noreferrer">${escapeHtml(entry.name)}</a></td>
425+
<td><a href="entry/${escapeHtml(entry.id)}/">${escapeHtml(entry.name)}</a></td>
423426
<td class="license">${escapeHtml(entry.license)} &middot; ${escapeHtml(commercialLabel(entry.commercial))}</td>
424427
</tr>`;
425428
})
@@ -435,144 +438,41 @@
435438
.join("");
436439
}
437440

438-
/* ------------------------------------------------------------- dialog */
441+
/* ------------------------------------------------------ scroll memory */
439442

440-
let lastTrigger = null;
441-
let currentEntryId = null;
442-
/** Entries in the order they are on screen, so prev/next matches the list. */
443-
let displayOrder = [];
443+
// Back from an entry page should land where you were, even when the
444+
// browser reloads this page instead of restoring it from its cache.
445+
const scrollKey = () => `fgda:scroll:${location.pathname}${location.search}`;
444446

445-
function stepEntry(delta) {
446-
const i = displayOrder.findIndex((e) => e.id === currentEntryId);
447-
if (i === -1) return;
448-
const next = displayOrder[i + delta];
449-
if (next) openEntry(next.id, null, delta);
450-
}
451-
452-
/** `stepping` is the direction (1 or -1) when paging, otherwise false. */
453-
function openEntry(id, trigger, stepping = false) {
454-
const entry = byId[id];
455-
if (!entry) return;
456-
if (!stepping) lastTrigger = trigger || null;
457-
currentEntryId = entry.id;
458-
const pos = displayOrder.findIndex((e) => e.id === entry.id);
459-
const prev = pos > 0 ? displayOrder[pos - 1] : null;
460-
const next = pos !== -1 && pos < displayOrder.length - 1 ? displayOrder[pos + 1] : null;
461-
// An entry opened from a permalink can be filtered out of the current
462-
// list; there is no honest "next" for it, so the pager is omitted.
463-
const pager =
464-
pos === -1
465-
? ""
466-
: `<nav class="dialog-pager" aria-label="Browse entries">
467-
<button type="button" class="btn-ghost" data-step="-1"${prev ? ` title="${escapeHtml(prev.name)}"` : " disabled"}><span aria-hidden="true">&larr;</span> Previous</button>
468-
<span class="dialog-position">${pos + 1} of ${displayOrder.length}</span>
469-
<button type="button" class="btn-ghost" data-step="1"${next ? ` title="${escapeHtml(next.name)}"` : " disabled"}>Next <span aria-hidden="true">&rarr;</span></button>
470-
</nav>`;
471-
const cat = categoryLabels[entry.category]?.label || entry.category;
472-
const age = verifiedAge(entry.verified);
473-
const attribution = entry.attribution_string
474-
? `<div class="attribution">
475-
<p class="attribution-label">Credit line</p>
476-
<p class="attribution-string" id="attribution-string">${escapeHtml(entry.attribution_string)}</p>
477-
<button type="button" class="btn-ghost" id="copy-attribution" data-copy="${escapeHtml(entry.attribution_string)}">Copy credit line</button>
478-
<span class="copy-status" id="copy-status" role="status" aria-live="polite"></span>
479-
</div>`
480-
: entry.attribution_required === true
481-
? `<p class="attribution-note">Attribution is required and no canned credit line is recorded. Read the entry for what the source asks for.</p>`
482-
: "";
483-
484-
$("#dialog-body").innerHTML = `
485-
<h2 id="dialog-title">${escapeHtml(entry.name)}</h2>
486-
<p class="dialog-flags">${escapeHtml(entry.status)} &middot; ${escapeHtml(commercialLabel(entry.commercial))} &middot; ${escapeHtml(entry.license)}</p>
487-
<p class="lead">${escapeHtml(entry.summary || "")}</p>
488-
<dl class="dialog-meta">
489-
<div><dt>Category</dt><dd>${escapeHtml(cat)}</dd></div>
490-
${entry.publisher ? `<div><dt>Publisher</dt><dd>${escapeHtml(entry.publisher)}</dd></div>` : ""}
491-
${entry.license_spdx ? `<div><dt>SPDX</dt><dd>${escapeHtml(entry.license_spdx)}</dd></div>` : ""}
492-
<div><dt>Attribution</dt><dd>${escapeHtml(String(entry.attribution_required))}</dd></div>
493-
${entry.camera_perspective ? `<div><dt>Perspective</dt><dd>${escapeHtml(PERSPECTIVE_LABELS[entry.camera_perspective] || entry.camera_perspective)}</dd></div>` : ""}
494-
${entry.grid_dimensions ? `<div><dt>Grid</dt><dd>${escapeHtml(entry.grid_dimensions)}</dd></div>` : ""}
495-
<div><dt>Formats</dt><dd>${escapeHtml((entry.formats || []).join(", ") || "—")}</dd></div>
496-
<div><dt>Tags</dt><dd>${escapeHtml((entry.tags || []).join(", ") || "—")}</dd></div>
497-
<div><dt>Verified</dt><dd class="verified is-${age.bucket}">${escapeHtml(age.text)}</dd></div>
498-
</dl>
499-
${attribution}
500-
<div class="dialog-actions">
501-
<a class="btn" href="${escapeHtml(entry.url)}" rel="noopener noreferrer">Open source</a>
502-
<a class="btn-ghost" href="${escapeHtml(`${repo}/blob/main/${entry.path}`)}" rel="noopener noreferrer">Entry and evidence</a>
503-
</div>
504-
${pager}`;
505-
506-
const copy = $("#copy-attribution");
507-
if (copy) {
508-
copy.addEventListener("click", async () => {
509-
const status = $("#copy-status");
510-
try {
511-
await navigator.clipboard.writeText(copy.getAttribute("data-copy"));
512-
status.textContent = "Copied";
513-
} catch {
514-
// Clipboard access can be refused; select the text so it can be
515-
// copied by hand rather than failing silently.
516-
const range = document.createRange();
517-
range.selectNodeContents($("#attribution-string"));
518-
const sel = getSelection();
519-
sel.removeAllRanges();
520-
sel.addRange(range);
521-
status.textContent = "Select and copy";
522-
}
523-
});
447+
function rememberScroll() {
448+
try {
449+
sessionStorage.setItem(scrollKey(), String(Math.round(window.scrollY)));
450+
} catch {
451+
// Storage can be unavailable; scrolling back is a convenience.
524452
}
453+
}
525454

526-
history.replaceState(null, "", `${location.pathname}${location.search}#entry-${entry.id}`);
527-
const dialog = $("#entry-dialog");
528-
// showModal() throws on a dialog that is already open, which is exactly
529-
// the state stepping leaves it in.
530-
if (!dialog.open) dialog.showModal();
531-
if (stepping) {
532-
// Keep focus on the pager so repeated Enter keeps paging; at the end of
533-
// the list the same-direction button is disabled, so fall back to the
534-
// other one rather than dropping focus to the document.
535-
const same = $(`#dialog-body [data-step="${stepping}"]`);
536-
const other = $(`#dialog-body [data-step="${-stepping}"]`);
537-
const target = same && !same.disabled ? same : other;
538-
if (target) target.focus();
455+
function restoreScroll() {
456+
let y = null;
457+
try {
458+
y = sessionStorage.getItem(scrollKey());
459+
sessionStorage.removeItem(scrollKey());
460+
} catch {
461+
return;
539462
}
463+
if (y !== null) requestAnimationFrame(() => window.scrollTo(0, Number(y)));
540464
}
541465

542-
function bindDialog() {
543-
const dialog = $("#entry-dialog");
544-
dialog.addEventListener("close", () => {
545-
history.replaceState(null, "", `${location.pathname}${location.search}`);
546-
// After paging, return to the entry you ended on, not the one you
547-
// opened; otherwise closing throws you back up the list.
548-
const endedOn = currentEntryId && document.querySelector(`#entry-${CSS.escape(currentEntryId)} .entry-link`);
549-
const target = endedOn || (lastTrigger && document.contains(lastTrigger) ? lastTrigger : null);
550-
if (target) {
551-
target.closest(".entry-card")?.scrollIntoView({ block: "nearest" });
552-
target.focus();
553-
}
554-
lastTrigger = null;
555-
currentEntryId = null;
556-
});
557-
dialog.addEventListener("click", (e) => {
558-
// Clicking the backdrop closes, matching the Escape affordance.
559-
if (e.target === dialog) {
560-
dialog.close();
561-
return;
562-
}
563-
const step = e.target.closest("[data-step]");
564-
if (step && !step.disabled) stepEntry(Number(step.getAttribute("data-step")));
565-
});
566-
dialog.addEventListener("keydown", (e) => {
567-
if (e.key === "ArrowRight") {
568-
e.preventDefault();
569-
stepEntry(1);
570-
} else if (e.key === "ArrowLeft") {
571-
e.preventDefault();
572-
stepEntry(-1);
573-
}
574-
});
575-
}
466+
// Restored from the back/forward cache: the page kept its own position,
467+
// so drop the saved one before a later visit can reuse it.
468+
window.addEventListener("pageshow", (e) => {
469+
if (!e.persisted) return;
470+
try {
471+
sessionStorage.removeItem(scrollKey());
472+
} catch {
473+
// Nothing to clear.
474+
}
475+
});
576476

577477
/* ----------------------------------------------------------- controls */
578478

@@ -614,11 +514,10 @@
614514
apply();
615515
});
616516

517+
// The whole card is the title link (a stretched ::after), so every click
518+
// that leaves for an entry page lands here.
617519
$("#entry-grid").addEventListener("click", (e) => {
618-
const link = e.target.closest(".entry-link");
619-
if (!link) return;
620-
e.preventDefault();
621-
openEntry(link.getAttribute("data-id"), link);
520+
if (e.target.closest("a.entry-link")) rememberScroll();
622521
});
623522

624523
$("#active-filters").addEventListener("click", (e) => {
@@ -651,7 +550,7 @@
651550
window.addEventListener("resize", onScroll, { passive: true });
652551

653552
// "/" focuses search, Escape leaves it. Suppressed whenever the user is
654-
// already typing somewhere or the entry dialog has focus.
553+
// already typing somewhere.
655554
document.addEventListener("keydown", (e) => {
656555
const el = document.activeElement;
657556
const typing =
@@ -660,7 +559,7 @@
660559
el.tagName === "TEXTAREA" ||
661560
el.tagName === "SELECT" ||
662561
el.isContentEditable);
663-
if (e.key === "/" && !typing && !$("#entry-dialog").open) {
562+
if (e.key === "/" && !typing) {
664563
e.preventDefault();
665564
search.focus();
666565
search.select();
@@ -695,15 +594,8 @@
695594
renderStarters();
696595
renderGuides();
697596
bindControls();
698-
bindDialog();
699597
syncControls();
700598
apply();
599+
restoreScroll();
701600

702-
// A shared link may point at one entry. Open it once the grid exists.
703-
const hash = location.hash.match(/^#entry-(.+)$/);
704-
if (hash && byId[hash[1]]) {
705-
const card = document.getElementById(`entry-${hash[1]}`);
706-
card?.scrollIntoView({ block: "center" });
707-
openEntry(hash[1], card?.querySelector(".entry-link") || null);
708-
}
709601
})();

‎site/public/index.html‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,6 @@ <h2 id="guides-title">Guides</h2>
173173
<span aria-hidden="true">↑</span> Search
174174
</button>
175175

176-
<dialog class="entry-dialog" id="entry-dialog" aria-labelledby="dialog-title">
177-
<form method="dialog" class="dialog-chrome">
178-
<button value="close" class="dialog-close" aria-label="Close">Close</button>
179-
</form>
180-
<div class="dialog-body" id="dialog-body"></div>
181-
</dialog>
182-
183176
<script src="./data.js"></script>
184177
<script src="./app.js"></script>
185178
</body>

0 commit comments

Comments
 (0)