lightbox on post body images too

This commit is contained in:
rimu 2024-08-07 17:15:30 +12:00
parent f4ff75f88f
commit 87608686eb

View file

@ -34,6 +34,7 @@ document.addEventListener("DOMContentLoaded", function () {
setupAddPollChoice();
setupShowElementLinks();
setupLightboxTeaser();
setupLightboxPostBody();
});
// All elements with the class "showElement" will show the DOM element referenced by the data-id attribute
@ -143,6 +144,25 @@ function setupLightboxTeaser() {
});
}
function setupLightboxPostBody() {
const images = document.querySelectorAll('.post_body img');
images.forEach(function(img) {
const parent = img.parentNode;
const link = document.createElement('a');
link.href = img.src;
link.setAttribute('data-caption', img.alt);
parent.replaceChild(link, img);
link.appendChild(img);
});
baguetteBox.run('.post_body', {
fullScreen: false,
titleTag: true,
async: true,
preload: 3
});
}
// fires after all resources have loaded, including stylesheets and js files
window.addEventListener("load", function () {
setupHideButtons();