-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): all new loop mode without slides duplication
The following parameters have been removed: loopAdditionalSlides loopedSlides loopedSlidesLimit loopFillGroupWithBlank loopPreventsSlide slideBlankClass
- Loading branch information
1 parent
329c956
commit f57aa3b
Showing
33 changed files
with
242 additions
and
431 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,16 @@ | ||
import { getDocument } from 'ssr-window'; | ||
import $ from '../../shared/dom.js'; | ||
|
||
export default function loopCreate() { | ||
export default function loopCreate(slideRealIndex) { | ||
const swiper = this; | ||
const document = getDocument(); | ||
const { params, $wrapperEl } = swiper; | ||
// Remove duplicated slides | ||
const $selector = | ||
$wrapperEl.children().length > 0 ? $($wrapperEl.children()[0].parentNode) : $wrapperEl; | ||
$selector | ||
.children( | ||
`.${params.slideClass}.${params.slideDuplicateClass}, swiper-slide.${params.slideDuplicateClass}`, | ||
) | ||
.remove(); | ||
const { params, $slidesEl } = swiper; | ||
if (!params.loop || (swiper.virtual && swiper.params.virtual.enabled)) return; | ||
|
||
let slides = $selector.children(`.${params.slideClass}, swiper-slide`); | ||
|
||
if (params.loopFillGroupWithBlank) { | ||
const blankSlidesNum = params.slidesPerGroup - (slides.length % params.slidesPerGroup); | ||
if (blankSlidesNum !== params.slidesPerGroup) { | ||
for (let i = 0; i < blankSlidesNum; i += 1) { | ||
let blankNode; | ||
if (swiper.isElement) { | ||
blankNode = $(document.createElement('swiper-slide')).addClass( | ||
`${params.slideBlankClass}`, | ||
); | ||
} else { | ||
blankNode = $(document.createElement('div')).addClass( | ||
`${params.slideClass} ${params.slideBlankClass}`, | ||
); | ||
} | ||
$selector.append(blankNode); | ||
} | ||
slides = $selector.children(`.${params.slideClass}, swiper-slide`); | ||
} | ||
} | ||
|
||
if (params.slidesPerView === 'auto' && !params.loopedSlides) params.loopedSlides = slides.length; | ||
|
||
swiper.loopedSlides = Math.ceil(parseFloat(params.loopedSlides || params.slidesPerView, 10)); | ||
swiper.loopedSlides += params.loopAdditionalSlides; | ||
if (swiper.loopedSlides > slides.length && swiper.params.loopedSlidesLimit) { | ||
swiper.loopedSlides = slides.length; | ||
} | ||
|
||
const prependSlides = []; | ||
const appendSlides = []; | ||
const slides = $slidesEl.children(`.${params.slideClass}, swiper-slide`); | ||
|
||
slides.each((el, index) => { | ||
const slide = $(el); | ||
slide.attr('data-swiper-slide-index', index); | ||
}); | ||
|
||
for (let i = 0; i < swiper.loopedSlides; i += 1) { | ||
const index = i - Math.floor(i / slides.length) * slides.length; | ||
appendSlides.push(slides.eq(index)[0]); | ||
prependSlides.unshift(slides.eq(slides.length - index - 1)[0]); | ||
} | ||
|
||
for (let i = 0; i < appendSlides.length; i += 1) { | ||
$selector.append($(appendSlides[i].cloneNode(true)).addClass(params.slideDuplicateClass)); | ||
} | ||
for (let i = prependSlides.length - 1; i >= 0; i -= 1) { | ||
$selector.prepend($(prependSlides[i].cloneNode(true)).addClass(params.slideDuplicateClass)); | ||
} | ||
swiper.loopFix(slideRealIndex); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,21 @@ | ||
export default function loopDestroy() { | ||
const swiper = this; | ||
const { $wrapperEl, params, slides } = swiper; | ||
$wrapperEl | ||
.children( | ||
`.${params.slideClass}.${params.slideDuplicateClass},.${params.slideClass}.${params.slideBlankClass},swiper-slide.${params.slideDuplicateClass},swiper-slide.${params.slideBlankClass}`, | ||
) | ||
.remove(); | ||
const { slides, params, $slidesEl } = swiper; | ||
if (!params.loop || (swiper.virtual && swiper.params.virtual.enabled)) return; | ||
swiper.recalcSlides(); | ||
|
||
const newSlidesOrder = []; | ||
slides.forEach((slideEl) => { | ||
const index = | ||
typeof slideEl.swiperSlideIndex === 'undefined' | ||
? slideEl.getAttribute('data-swiper-slide-index') * 1 | ||
: slideEl.swiperSlideIndex; | ||
newSlidesOrder[index] = slideEl; | ||
}); | ||
slides.removeAttr('data-swiper-slide-index'); | ||
newSlidesOrder.forEach((slideEl) => { | ||
$slidesEl.append(slideEl); | ||
}); | ||
swiper.recalcSlides(); | ||
swiper.slideTo(swiper.realIndex, 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.