Skip to content

Commit

Permalink
fix(element): fixed issue with incorrect lookup for lazy prelader and…
Browse files Browse the repository at this point in the history
… images

fixes #6901
  • Loading branch information
nolimits4web committed Aug 8, 2023
1 parent 2dcb802 commit 64513ac
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion scripts/utils/get-element-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const proceedSlideReplacements = (content) => {
if (line === '.swiper-lazy-preloader {') {
return line.replace(
'.swiper-lazy-preloader {',
'::slotted(.swiper-lazy-preloader) {animation: swiper-preloader-spin 1s infinite linear;',
'.swiper-lazy-preloader {animation: swiper-preloader-spin 1s infinite linear;',
);
}
if (line.includes('animation: swiper-preloader-spin 1s infinite linear;')) {
Expand Down
7 changes: 5 additions & 2 deletions src/core/core.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,11 @@ class Swiper {

// Attach events
swiper.attachEvents();

[...swiper.el.querySelectorAll('[loading="lazy"]')].forEach((imageEl) => {
const lazyElements = [...swiper.el.querySelectorAll('[loading="lazy"]')];
if (swiper.isElement) {
lazyElements.push(...swiper.hostEl.querySelectorAll('[loading="lazy"]'));
}
lazyElements.forEach((imageEl) => {
if (imageEl.complete) {
processLazyPreloader(swiper, imageEl);
} else {
Expand Down
5 changes: 4 additions & 1 deletion src/shared/process-lazy-preloader.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ export const processLazyPreloader = (swiper, imageEl) => {
const slideSelector = () => (swiper.isElement ? `swiper-slide` : `.${swiper.params.slideClass}`);
const slideEl = imageEl.closest(slideSelector());
if (slideEl) {
const lazyEl = slideEl.querySelector(`.${swiper.params.lazyPreloaderClass}`);
let lazyEl = slideEl.querySelector(`.${swiper.params.lazyPreloaderClass}`);
if (!lazyEl && swiper.isElement) {
lazyEl = slideEl.shadowRoot.querySelector(`.${swiper.params.lazyPreloaderClass}`);
}
if (lazyEl) lazyEl.remove();
}
};
Expand Down
3 changes: 2 additions & 1 deletion src/swiper-element.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ class SwiperSlide extends ClassToExtend {
if (lazy) {
const lazyDiv = document.createElement('div');
lazyDiv.classList.add('swiper-lazy-preloader');
this.appendChild(lazyDiv);
lazyDiv.part.add('preloader');
this.shadowRoot.appendChild(lazyDiv);
}
}

Expand Down

0 comments on commit 64513ac

Please sign in to comment.