Skip to content

Commit

Permalink
updating how simple lightbox finds captions
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-c-woodard committed Dec 6, 2024
1 parent 049647e commit 9275300
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion includes/assets/js/simplelightbox.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion src/assets/js/simplelightbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,19 @@
if (elements) {
elements.forEach(function (element, index) {
self.items.push(element.getAttribute(options.urlAttribute));
self.captions.push(element.getAttribute(options.captionAttribute));

//look for a caption in various spots
var caption = element.getAttribute(options.captionAttribute);
if (!caption) {
//try to find the title attribute on the underlying image
caption = element.querySelector('img')?.getAttribute(options.captionAttribute);

if (!caption) {
//try to find an attached fig caption
caption = element.parentElement?.querySelector('figcaption')?.textContent;
}
}
self.captions.push(caption);

if (options.bindToItems) {
self.addEvent(
Expand Down

0 comments on commit 9275300

Please sign in to comment.