Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Lightbox compatibility with Lazy Loading #2588

Merged
merged 2 commits into from
Feb 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/js/coblocks-lightbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,20 @@
imagePreloader.preloaded = true;
Array.from( images ).forEach( function( img, imgIndex ) {
imagePreloader[ `img-${ imgIndex }` ] = new window.Image();
imagePreloader[ `img-${ imgIndex }` ].src = img.attributes.src.value;

// If the src is lazy loaded, use the data-src attribute.
// Compatibility with A3 Lazy Load plugin and maybe others.
if (
img.attributes.src.value?.includes( 'lazy-load' ) &&
'undefined' !== typeof img.attributes?.[ 'data-src' ]?.value
) {
imagePreloader[ `img-${ imgIndex }` ].src =
img.attributes[ 'data-src' ].value;
} else {
imagePreloader[ `img-${ imgIndex }` ].src =
img.attributes.src.value;
}

imagePreloader[ `img-${ imgIndex }` ][ 'data-caption' ] =
( images[ imgIndex ] && images[ imgIndex ].nextElementSibling )
? getImageCaption( images[ imgIndex ] ) : '';
Expand Down
Loading