From 7c4c1c47765bc7fe2abd01f91a7eb866a2a14112 Mon Sep 17 00:00:00 2001 From: Alan Grainger <16197738+alangrainger@users.noreply.github.com> Date: Mon, 25 May 2026 16:06:16 +0800 Subject: [PATCH] #224 Fix missing caption --- app/public/photoswipe-overrides.css | 23 +++++++++++++++++++++++ app/public/web.js | 28 +++++++++++++++++++++++++++- app/src/functions.ts | 4 +--- 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/app/public/photoswipe-overrides.css b/app/public/photoswipe-overrides.css index 012295c..86e4326 100644 --- a/app/public/photoswipe-overrides.css +++ b/app/public/photoswipe-overrides.css @@ -125,3 +125,26 @@ html.pswp-no-arrows .pswp__button--arrow { .pswp__bg { transition: opacity var(--pswp-transition-duration); } + +/* Image caption (from EXIF description) - centered in the 56px bottom margin + carved out by the lightbox `padding.bottom` setting. */ +.pswp__caption { + position: absolute; + left: 0; + right: 0; + bottom: 0; + height: 56px; + padding: 0 24px; + display: flex; + align-items: center; + justify-content: center; + color: #fff; + font-size: 14px; + line-height: 1.4; + text-align: center; + pointer-events: none; +} + +.pswp__caption[hidden] { + display: none; +} diff --git a/app/public/web.js b/app/public/web.js index 7c0ef79..cda57f6 100644 --- a/app/public/web.js +++ b/app/public/web.js @@ -303,7 +303,10 @@ function createTile (index) { } const img = document.createElement('img') - img.alt = item.description || '' + // alt left empty: browsers paint alt text over the thumbhash background + // while the thumbnail downloads. Description (if any) is shown in the + // lightbox caption instead. + img.alt = '' img.dataset.src = item.thumbnailUrl img.onerror = onThumbError a.appendChild(img) @@ -683,6 +686,29 @@ function initLightbox () { }) } + // Caption from EXIF description (only present when item.description is set; + // server-side gated on ipp.showMetadata.description). Content is already + // HTML-escaped in render.ts, so innerHTML assignment is safe. + lightbox.on('uiRegister', () => { + lightbox.pswp.ui.registerElement({ + name: 'caption', + order: 9, + isButton: false, + appendTo: 'root', + onInit: (el, pswp) => { + el.classList.add('pswp__caption') + const render = () => { + const item = items[pswp.currIndex] + const text = (item && item.description) || '' + el.innerHTML = text + el.hidden = !text + } + render() + pswp.on('change', render) + } + }) + }) + // Hash navigation: sync window.location.hash with the open slide lightbox.on('uiRegister', () => { const pswp = lightbox.pswp diff --git a/app/src/functions.ts b/app/src/functions.ts index 0868b67..a40ef51 100644 --- a/app/src/functions.ts +++ b/app/src/functions.ts @@ -15,9 +15,7 @@ try { console.log(e) } -// Backward-compat shim: users with a legacy `lightGallery.*` config section -// get the few keys most of them had set mapped onto the current -// `ipp.lightbox.*` schema, with a single startup notice. +// Backward-compatability shim for 1.x users with a legacy `lightGallery.*` config section if (config.lightGallery && typeof config.lightGallery === 'object') { const lg = config.lightGallery as Record const mobile = (lg.mobileSettings || {}) as Record