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 1 commit
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
Next Next commit
make lightbox compatible with a3 lazy load plugin
  • Loading branch information
aledesma-godaddy committed Feb 27, 2024
commit 72f4162b58b9f2829d29d83e83b36eac82e82ab7
10 changes: 9 additions & 1 deletion src/js/coblocks-lightbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,15 @@
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' ) ) {
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