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 <noreply@anthropic.com>
This commit is contained in:
+8
-1
@@ -204,6 +204,7 @@
|
||||
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);
|
||||
});
|
||||
|
||||
+8
-1
@@ -204,6 +204,7 @@
|
||||
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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user