summaryrefslogtreecommitdiffstats
path: root/public/js
diff options
context:
space:
mode:
Diffstat (limited to 'public/js')
-rw-r--r--public/js/album.js18
1 files changed, 11 insertions, 7 deletions
diff --git a/public/js/album.js b/public/js/album.js
index d83cb5f..a2301c9 100644
--- a/public/js/album.js
+++ b/public/js/album.js
@@ -18,7 +18,10 @@ function closeLightbox() {
const el = document.getElementById(id);
el.pause && el.pause();
});
- history.replaceState(null, '', location.pathname + location.search);
+ const closeUrl = new URL(location.href);
+ closeUrl.searchParams.delete('photo');
+ const closeQs = closeUrl.searchParams.toString();
+ history.replaceState(null, '', closeUrl.pathname + (closeQs ? '?' + closeQs : ''));
}
function lbNav(delta) {
@@ -78,8 +81,10 @@ function renderLightbox() {
dl.href = e.src;
dl.download = e.name;
- // Update URL hash so the address bar is the shareable link
- history.replaceState(null, '', location.pathname + location.search + '#photo=' + encodeURIComponent(e.name));
+ // Update URL so the address bar is the shareable link
+ const photoUrl = new URL(location.href);
+ photoUrl.searchParams.set('photo', e.name);
+ history.replaceState(null, '', photoUrl.pathname + photoUrl.search);
}
function lbCopyLink() {
@@ -107,10 +112,9 @@ function lbKey(ev) {
// Restore lightbox from URL hash on page load
window.addEventListener('DOMContentLoaded', () => {
- const m = location.hash.match(/^#photo=(.+)$/);
- if (m) {
- const name = decodeURIComponent(m[1]);
- const idx = ENTRIES.findIndex(e => e.name === name);
+ const photoName = new URLSearchParams(location.search).get('photo');
+ if (photoName) {
+ const idx = ENTRIES.findIndex(e => e.name === photoName);
if (idx >= 0) openLightbox(idx);
}
});