// Enhanced fix for Elementor lightbox lazy loading with slideshow preservation
document.addEventListener('DOMContentLoaded', function() {
// Function to force load all lazy images without breaking slideshow
function forceLoadLazyImages() {
console.log('Attempting to force load lazy images...');
const lazyImages = document.querySelectorAll('.elementor-lightbox-image.swiper-lazy:not(.swiper-lazy-loaded)');
console.log('Found', lazyImages.length, 'lazy images to load');
lazyImages.forEach(function(img) {
if (img.dataset.src) {
console.log('Loading image:', img.dataset.src);
// Create a temporary image to preload
const tempImg = new Image();
tempImg.onload = function() {
// Only set src after image is loaded to prevent flicker
img.src = img.dataset.src;
img.classList.add('swiper-lazy-loaded');
};
tempImg.src = img.dataset.src;
}
});
}
// Wait for Elementor frontend to be ready
if (typeof elementorFrontend !== 'undefined') {
console.log('Elementor frontend detected');
// Hook into lightbox open event
elementorFrontend.on('components:init', function() {
console.log('Elementor components initialized');
if (elementorFrontend.utils && elementorFrontend.utils.lightbox) {
console.log('Lightbox utility detected');
// Preserve original slideshow:show handler
const originalShowHandler = elementorFrontend.utils.lightbox.getSettings('slideshow').show;
// Hook into slideshow show event
elementorFrontend.utils.lightbox.on('slideshow:show', function() {
console.log('Slideshow show event triggered');
// Force load immediately
forceLoadLazyImages();
// Also try again after a short delay
setTimeout(forceLoadLazyImages, 300);
setTimeout(forceLoadLazyImages, 800);
});
// Also hook into slide change event
elementorFrontend.utils.lightbox.on('slideChange', function() {
console.log('Slide change event triggered');
forceLoadLazyImages();
});
}
});
}
// Backup approach: monitor DOM for lightbox opening
const observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.addedNodes && mutation.addedNodes.length > 0) {
for (let i = 0; i < mutation.addedNodes.length; i++) {
const node = mutation.addedNodes[i];
if (node.classList && node.classList.contains('dialog-lightbox-widget')) {
console.log('Lightbox detected via DOM mutation');
// Wait a moment for the lightbox to fully initialize
setTimeout(function() {
// Check if Swiper is initialized
const swiperElement = document.querySelector('.elementor-lightbox .swiper-container');
if (swiperElement && swiperElement.swiper) {
console.log('Swiper found, ensuring all slides are loaded');
// Force update Swiper to recognize all slides
swiperElement.swiper.update();
}
forceLoadLazyImages();
}, 200);
}
}
}
});
});
observer.observe(document.body, { childList: true, subtree: true });
});
Skip to content