#224 Fix missing caption

This commit is contained in:
Alan Grainger
2026-05-25 16:06:16 +08:00
parent 5c169af78d
commit 7c4c1c4776
3 changed files with 51 additions and 4 deletions
+27 -1
View File
@@ -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