Skip to content

Commit

Permalink
feat(core): add support to loop with slotted elements (#5117)
Browse files Browse the repository at this point in the history
Co-authored-by: David Iglesias Zavala <davidiglesiaszavala@iMac-de-David-Iglesias.local>
  • Loading branch information
davidigza and David Iglesias Zavala authored Oct 25, 2021
1 parent b1c317a commit 33c411e
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/core/loop/loopCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ export default function loopCreate() {
const document = getDocument();
const { params, $wrapperEl } = swiper;
// Remove duplicated slides
$wrapperEl.children(`.${params.slideClass}.${params.slideDuplicateClass}`).remove();
const $selector = $($wrapperEl.children()[0].parentNode);
$selector.children(`.${params.slideClass}.${params.slideDuplicateClass}`).remove();

let slides = $wrapperEl.children(`.${params.slideClass}`);
let slides = $selector.children(`.${params.slideClass}`);

if (params.loopFillGroupWithBlank) {
const blankSlidesNum = params.slidesPerGroup - (slides.length % params.slidesPerGroup);
Expand All @@ -17,9 +18,9 @@ export default function loopCreate() {
const blankNode = $(document.createElement('div')).addClass(
`${params.slideClass} ${params.slideBlankClass}`,
);
$wrapperEl.append(blankNode);
$selector.append(blankNode);
}
slides = $wrapperEl.children(`.${params.slideClass}`);
slides = $selector.children(`.${params.slideClass}`);
}
}

Expand All @@ -44,9 +45,9 @@ export default function loopCreate() {
slide.attr('data-swiper-slide-index', index);
});
for (let i = 0; i < appendSlides.length; i += 1) {
$wrapperEl.append($(appendSlides[i].cloneNode(true)).addClass(params.slideDuplicateClass));
$selector.append($(appendSlides[i].cloneNode(true)).addClass(params.slideDuplicateClass));
}
for (let i = prependSlides.length - 1; i >= 0; i -= 1) {
$wrapperEl.prepend($(prependSlides[i].cloneNode(true)).addClass(params.slideDuplicateClass));
$selector.prepend($(prependSlides[i].cloneNode(true)).addClass(params.slideDuplicateClass));
}
}

0 comments on commit 33c411e

Please sign in to comment.