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); });