From 073c4b804c885b0669b7b8ecc3905b780054a9f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Kr=C3=BCger?= Date: Mon, 18 May 2026 17:31:57 +0200 Subject: [PATCH] Restore referrer URL on lightbox close Save location.href before pushState when opening lightbox from a grid page, and navigate back to it on close. Direct single-post page loads still return to the issue page. Co-Authored-By: Claude Sonnet 4.6 --- assets/js/app.js | 15 +++++++++++---- static/js/app.js | 15 +++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/assets/js/app.js b/assets/js/app.js index 90b3f78..8c3c529 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -201,9 +201,10 @@ const lbThumbs = document.getElementById('lbThumbs'); const lbIndex = document.getElementById('lbIndex'); - let lbList = []; // current scoped post list - let lbIdx = -1; // index into lbList - let lbBuilt = false; + let lbList = []; // current scoped post list + let lbIdx = -1; // index into lbList + let lbBuilt = false; + let lbReferrer = null; // URL to return to on close function lbOpen(slug, scopedList) { lbList = scopedList || POSTS; @@ -223,9 +224,15 @@ lb.dataset.open = 'false'; document.body.style.overflow = ''; if (window.__ROUX_OPEN_SLUG) { + // Direct load of a single-post URL — go back to the issue page const cur = lbList[lbIdx]; const issueId = (cur && cur.issue) || '01'; navigate(`/issues/${issueId}/`); + } else if (lbReferrer) { + // Opened from a grid page — return to it + const ref = lbReferrer; + lbReferrer = null; + navigate(ref); } } @@ -361,7 +368,7 @@ const clicked = POSTS.find(p => p.slug === slug); const issueId = clicked ? clicked.issue : null; const scopedList = issueId ? POSTS.filter(p => p.issue === issueId) : POSTS; - // Update URL without page reload + lbReferrer = location.href; history.pushState({ slug }, '', card.href); lbOpen(slug, scopedList.length ? scopedList : POSTS); }); diff --git a/static/js/app.js b/static/js/app.js index 90b3f78..8c3c529 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -201,9 +201,10 @@ const lbThumbs = document.getElementById('lbThumbs'); const lbIndex = document.getElementById('lbIndex'); - let lbList = []; // current scoped post list - let lbIdx = -1; // index into lbList - let lbBuilt = false; + let lbList = []; // current scoped post list + let lbIdx = -1; // index into lbList + let lbBuilt = false; + let lbReferrer = null; // URL to return to on close function lbOpen(slug, scopedList) { lbList = scopedList || POSTS; @@ -223,9 +224,15 @@ lb.dataset.open = 'false'; document.body.style.overflow = ''; if (window.__ROUX_OPEN_SLUG) { + // Direct load of a single-post URL — go back to the issue page const cur = lbList[lbIdx]; const issueId = (cur && cur.issue) || '01'; navigate(`/issues/${issueId}/`); + } else if (lbReferrer) { + // Opened from a grid page — return to it + const ref = lbReferrer; + lbReferrer = null; + navigate(ref); } } @@ -361,7 +368,7 @@ const clicked = POSTS.find(p => p.slug === slug); const issueId = clicked ? clicked.issue : null; const scopedList = issueId ? POSTS.filter(p => p.issue === issueId) : POSTS; - // Update URL without page reload + lbReferrer = location.href; history.pushState({ slug }, '', card.href); lbOpen(slug, scopedList.length ? scopedList : POSTS); });