forked from nolimits4web/swiper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
066ab58
commit 4bc3192
Showing
3 changed files
with
50 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ custom | |
*.log | ||
|
||
.versions | ||
.idea |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import Support from '../../../utils/support'; | ||
|
||
export default function (index, slides) { | ||
const swiper = this; | ||
const { $wrapperEl, params, activeIndex } = swiper; | ||
if (params.loop) { | ||
swiper.loopDestroy(); | ||
swiper.slides = $wrapperEl.children(`.${params.slideClass}`); | ||
} | ||
const baseLength = swiper.slides.length; | ||
if (index <= 0) { | ||
swiper.prependSlide(slides); | ||
return; | ||
} else if (index >= baseLength) { | ||
swiper.appendSlide(slides); | ||
return; | ||
} | ||
let newActiveIndex = activeIndex > index ? activeIndex + 1 : activeIndex; | ||
|
||
const slidesBuffer = []; | ||
for (let i = baseLength - 1; i >= index; i -= 1) { | ||
const currentSlide = swiper.slides.eq(i); | ||
currentSlide.remove(); | ||
slidesBuffer.unshift(currentSlide); | ||
} | ||
|
||
if (typeof slides === 'object' && 'length' in slides) { | ||
for (let i = 0; i < slides.length; i += 1) { | ||
if (slides[i]) $wrapperEl.append(slides[i]); | ||
} | ||
newActiveIndex = activeIndex > index ? activeIndex + slides.length : activeIndex; | ||
} else { | ||
$wrapperEl.append(slides); | ||
} | ||
|
||
for (let i = 0; i < slidesBuffer.length; i += 1) { | ||
$wrapperEl.append(slidesBuffer[i]); | ||
} | ||
|
||
if (params.loop) { | ||
swiper.loopCreate(); | ||
} | ||
if (!(params.observer && Support.observer)) { | ||
swiper.update(); | ||
} | ||
swiper.slideTo(newActiveIndex, 0, false); | ||
} |
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,11 +1,13 @@ | ||
import appendSlide from './appendSlide'; | ||
import prependSlide from './prependSlide'; | ||
import addSlide from './addSlide'; | ||
import removeSlide from './removeSlide'; | ||
import removeAllSlides from './removeAllSlides'; | ||
|
||
export default { | ||
appendSlide, | ||
prependSlide, | ||
addSlide, | ||
removeSlide, | ||
removeAllSlides, | ||
}; |