UNPKG

28.3 kBJavaScriptView Raw
1/**
2 * Adopted from Swiper
3 * Most modern mobile touch slider and framework with hardware
4 * accelerated transitions.
5 *
6 * http://www.idangero.us/swiper/
7 *
8 * Copyright 2016, Vladimir Kharlampidi
9 * The iDangero.us
10 * http://www.idangero.us/
11 *
12 * Licensed under MIT
13 */
14import { CLS, addClass, eachChild, inlineStyle, isHorizontal, maxTranslate, minTranslate, removeClass, round, updateSlidesOffset } from './swiper-utils';
15import { setWrapperTransition, setWrapperTranslate } from './swiper-transition';
16import { updateProgress } from './swiper-progress';
17import { updateClasses } from './swiper-classes';
18import { parallaxSetTranslate } from './swiper-parallax';
19import { updateActiveIndex, updateRealIndex } from './swiper-index';
20import { SWIPER_EFFECTS } from './swiper-effects';
21import { updatePagination } from './swiper-pagination';
22import { resetZoomEvents } from './swiper-zoom';
23export function initSwiper(s, plt) {
24 // Classname
25 s._classNames = [];
26 /*=========================
27 Preparation - Define Container, Wrapper and Pagination
28 ===========================*/
29 if (!s.container) {
30 return;
31 }
32 // Save instance in container HTML Element and in data
33 s.container.swiper = s;
34 var containerModifierClass = CLS.containerModifier;
35 s._classNames.push(containerModifierClass + s.direction);
36 if (s.freeMode) {
37 s._classNames.push(containerModifierClass + 'free-mode');
38 }
39 if (s.autoHeight) {
40 s._classNames.push(containerModifierClass + 'autoheight');
41 }
42 // Enable slides progress when required
43 if (s.parallax || s.watchSlidesVisibility) {
44 s.watchSlidesProgress = true;
45 }
46 // Max resistance when touchReleaseOnEdges
47 if (s.touchReleaseOnEdges) {
48 s.resistanceRatio = 0;
49 }
50 var effect = s.effect;
51 // Coverflow / 3D
52 if (['cube', 'coverflow', 'flip'].indexOf(effect) >= 0) {
53 s.watchSlidesProgress = true;
54 s._classNames.push(containerModifierClass + '3d');
55 }
56 if (effect !== 'slide') {
57 s._classNames.push(containerModifierClass + effect);
58 }
59 if (effect === 'cube') {
60 s.resistanceRatio = 0;
61 s.slidesPerView = 1;
62 s.slidesPerColumn = 1;
63 s.slidesPerGroup = 1;
64 s.centeredSlides = false;
65 s.spaceBetween = 0;
66 s.virtualTranslate = true;
67 s.setWrapperSize = false;
68 }
69 if (effect === 'fade' || effect === 'flip') {
70 s.slidesPerView = 1;
71 s.slidesPerColumn = 1;
72 s.slidesPerGroup = 1;
73 s.watchSlidesProgress = true;
74 s.spaceBetween = 0;
75 s.setWrapperSize = false;
76 s.virtualTranslate = true;
77 }
78 // Wrapper
79 s._wrapper = s.container.querySelector('.' + CLS.wrapper);
80 // Pagination
81 if (s.paginationType) {
82 s._paginationContainer = s.container.querySelector('.swiper-pagination');
83 if (s.paginationType === 'bullets') {
84 s._paginationContainer.classList.add(CLS.paginationModifier + 'clickable');
85 }
86 s._paginationContainer.classList.add(CLS.paginationModifier + s.paginationType);
87 }
88 // Next/Prev Buttons
89 // if (s.nextButton || s.prevButton) {
90 // if (s.nextButton) {
91 // s.nextButton = <any>s.container.closest('ion-content').querySelector(s.nextButton);
92 // }
93 // if (s.prevButton) {
94 // s.prevButton = <any>s.container.closest('ion-content').querySelector(s.prevButton);
95 // }
96 // }
97 // RTL
98 s._rtl = isHorizontal(s) && (s.container.dir.toLowerCase() === 'rtl' || s.container.style.direction === 'rtl');
99 if (s._rtl) {
100 s._classNames.push(containerModifierClass + 'rtl');
101 }
102 // Columns
103 if (s.slidesPerColumn > 1) {
104 s._classNames.push(containerModifierClass + 'multirow');
105 }
106 // Check for Android
107 if (plt.is('android')) {
108 s._classNames.push(containerModifierClass + 'android');
109 }
110 // Add classes
111 s._classNames.forEach(function (clsName) {
112 s.container.classList.add(clsName);
113 });
114 // Translate
115 s._translate = 0;
116 // Progress
117 s.progress = 0;
118 // Velocity
119 s.velocity = 0;
120 /*=========================
121 Autoplay
122 ===========================*/
123 s._autoplayTimeoutId = undefined;
124 s._autoplaying = false;
125 s._autoplayPaused = false;
126 s._allowClick = true;
127 // Animating Flag
128 s._animating = false;
129 // Touches information
130 s._touches = {
131 startX: 0,
132 startY: 0,
133 currentX: 0,
134 currentY: 0,
135 diff: 0
136 };
137 if (s.loop) {
138 createLoop(s);
139 }
140 updateContainerSize(s, plt);
141 updateSlidesSize(s, plt);
142 updatePagination(s);
143 if (effect !== 'slide' && SWIPER_EFFECTS[effect]) {
144 if (!s.loop) {
145 updateProgress(s);
146 }
147 SWIPER_EFFECTS[effect].setTranslate(s, plt);
148 }
149 if (s.loop) {
150 slideTo(s, plt, s.initialSlide + s.loopedSlides, 0, s.runCallbacksOnInit);
151 }
152 else {
153 slideTo(s, plt, s.initialSlide, 0, s.runCallbacksOnInit);
154 if (s.initialSlide === 0) {
155 parallaxSetTranslate(s);
156 }
157 }
158 if (s.autoplay) {
159 startAutoplay(s, plt);
160 }
161}
162/*=========================
163 Autoplay
164 ===========================*/
165function autoplay(s, plt) {
166 var autoplayDelay = s.autoplay;
167 var activeSlide = s._slides[s._activeIndex];
168 if (activeSlide.hasAttribute('data-swiper-autoplay')) {
169 autoplayDelay = (activeSlide.getAttribute('data-swiper-autoplay') || s.autoplay);
170 }
171 s._autoplayTimeoutId = plt.timeout(function () {
172 s._zone.run(function () {
173 if (s.loop) {
174 fixLoop(s, plt);
175 slideNext(s, plt, true, undefined, true);
176 s.ionSlideAutoplay.emit(s);
177 }
178 else {
179 if (!s._isEnd) {
180 slideNext(s, plt, true, undefined, true);
181 s.ionSlideAutoplay.emit(s);
182 }
183 else {
184 if (!s.autoplayStopOnLast) {
185 slideTo(s, plt, 0);
186 s.ionSlideAutoplay.emit(s);
187 }
188 else {
189 stopAutoplay(s);
190 }
191 }
192 }
193 });
194 }, autoplayDelay);
195}
196export function startAutoplay(s, plt) {
197 if (typeof s._autoplayTimeoutId !== 'undefined')
198 return false;
199 if (!s.autoplay || s._autoplaying) {
200 return false;
201 }
202 s._autoplaying = true;
203 s._zone.run(function () {
204 s.ionSlideAutoplayStart.emit(s);
205 });
206 autoplay(s, plt);
207}
208export function stopAutoplay(s) {
209 if (!s._autoplayTimeoutId)
210 return;
211 if (s._autoplayTimeoutId)
212 clearTimeout(s._autoplayTimeoutId);
213 s._autoplaying = false;
214 s._autoplayTimeoutId = undefined;
215 s._zone.run(function () {
216 s.ionSlideAutoplayStop.emit(s);
217 });
218}
219export function pauseAutoplay(s, plt, speed) {
220 if (s._autoplayPaused)
221 return;
222 if (s._autoplayTimeoutId)
223 clearTimeout(s._autoplayTimeoutId);
224 s._autoplayPaused = true;
225 if (speed === 0) {
226 s._autoplayPaused = false;
227 autoplay(s, plt);
228 }
229 else {
230 plt.transitionEnd(s._wrapper, function () {
231 if (!s)
232 return;
233 s._autoplayPaused = false;
234 if (!s._autoplaying) {
235 stopAutoplay(s);
236 }
237 else {
238 autoplay(s, plt);
239 }
240 });
241 }
242}
243/*=========================
244 Slider/slides sizes
245 ===========================*/
246export function updateAutoHeight(s) {
247 var activeSlides = [];
248 var newHeight = 0;
249 var i;
250 // Find slides currently in view
251 if (s.slidesPerView !== 'auto' && s.slidesPerView > 1) {
252 for (i = 0; i < Math.ceil(s.slidesPerView); i++) {
253 var index = s._activeIndex + i;
254 if (index > s._slides.length)
255 break;
256 activeSlides.push(s._slides[index]);
257 }
258 }
259 else {
260 activeSlides.push(s._slides[s._activeIndex]);
261 }
262 // Find new height from heighest slide in view
263 for (i = 0; i < activeSlides.length; i++) {
264 if (typeof activeSlides[i] !== 'undefined') {
265 var height = activeSlides[i].offsetHeight;
266 newHeight = height > newHeight ? height : newHeight;
267 }
268 }
269 // Update Height
270 if (newHeight) {
271 s._wrapper.style.height = newHeight + 'px';
272 }
273}
274export function updateContainerSize(s, plt) {
275 var container = s.container;
276 var width;
277 var height;
278 if (typeof s.width !== 'undefined') {
279 // manually assign user width
280 width = s.width;
281 }
282 else {
283 width = container.clientWidth;
284 }
285 if (typeof s.renderedHeight !== 'undefined') {
286 // manually assign user height
287 height = s.renderedHeight;
288 }
289 else {
290 height = container.clientHeight;
291 }
292 if (width === 0 && isHorizontal(s) || height === 0 && !isHorizontal(s)) {
293 return;
294 }
295 // Subtract paddings
296 var containerStyles = plt.getElementComputedStyle(container);
297 width = width - parseInt(containerStyles.paddingLeft, 10) - parseInt(containerStyles.paddingRight, 10);
298 height = height - parseInt(containerStyles.paddingTop, 10) - parseInt(containerStyles.paddingBottom, 10);
299 // Store values
300 s.renderedWidth = width;
301 s.renderedHeight = height;
302 s._renderedSize = isHorizontal(s) ? width : height;
303}
304export function updateSlidesSize(s, plt) {
305 s._slides = s._wrapper.querySelectorAll('.' + CLS.slide);
306 s._snapGrid = [];
307 s._slidesGrid = [];
308 s._slidesSizesGrid = [];
309 var spaceBetween = s.spaceBetween;
310 var slidePosition = -s.slidesOffsetBefore;
311 var i;
312 var prevSlideSize = 0;
313 var index = 0;
314 if (typeof s._renderedSize === 'undefined')
315 return;
316 if (typeof spaceBetween === 'string' && spaceBetween.indexOf('%') >= 0) {
317 spaceBetween = parseFloat(spaceBetween.replace('%', '')) / 100 * s._renderedSize;
318 }
319 s._virtualSize = -spaceBetween;
320 // reset margins
321 if (s._rtl) {
322 inlineStyle(s._slides, { marginLeft: '', marginTop: '' });
323 }
324 else {
325 inlineStyle(s._slides, { marginRight: '', marginBottom: '' });
326 }
327 var slidesNumberEvenToRows;
328 if (s.slidesPerColumn > 1) {
329 if (Math.floor(s._slides.length / s.slidesPerColumn) === s._slides.length / s.slidesPerColumn) {
330 slidesNumberEvenToRows = s._slides.length;
331 }
332 else {
333 slidesNumberEvenToRows = Math.ceil(s._slides.length / s.slidesPerColumn) * s.slidesPerColumn;
334 }
335 if (s.slidesPerView !== 'auto' && s.slidesPerColumnFill === 'row') {
336 slidesNumberEvenToRows = Math.max(slidesNumberEvenToRows, s.slidesPerView * s.slidesPerColumn);
337 }
338 }
339 // Calc slides
340 var slideSize;
341 var slidesPerColumn = s.slidesPerColumn;
342 var slidesPerRow = slidesNumberEvenToRows / slidesPerColumn;
343 var numFullColumns = slidesPerRow - (s.slidesPerColumn * slidesPerRow - s._slides.length);
344 for (i = 0; i < s._slides.length; i++) {
345 slideSize = 0;
346 var slide = s._slides[i];
347 if (s.slidesPerColumn > 1) {
348 // Set slides order
349 var newSlideOrderIndex;
350 var column;
351 var row;
352 if (s.slidesPerColumnFill === 'column') {
353 column = Math.floor(i / slidesPerColumn);
354 row = i - column * slidesPerColumn;
355 if (column > numFullColumns || (column === numFullColumns && row === slidesPerColumn - 1)) {
356 if (++row >= slidesPerColumn) {
357 row = 0;
358 column++;
359 }
360 }
361 newSlideOrderIndex = column + row * slidesNumberEvenToRows / slidesPerColumn;
362 inlineStyle(slide, {
363 '-webkit-box-ordinal-group': newSlideOrderIndex,
364 '-moz-box-ordinal-group': newSlideOrderIndex,
365 '-ms-flex-order': newSlideOrderIndex,
366 '-webkit-order': newSlideOrderIndex,
367 'order': newSlideOrderIndex
368 });
369 }
370 else {
371 row = Math.floor(i / slidesPerRow);
372 column = i - row * slidesPerRow;
373 }
374 var cssVal = (row !== 0 && s.spaceBetween) && (s.spaceBetween + 'px');
375 var cssObj = {};
376 if (isHorizontal(s)) {
377 cssObj['marginTop'] = cssVal;
378 }
379 else {
380 cssObj['marginLeft'] = cssVal;
381 }
382 inlineStyle(slide, cssObj);
383 slide.setAttribute('data-swiper-column', column);
384 slide.setAttribute('data-swiper-row', row);
385 }
386 if (slide.style.display === 'none') {
387 continue;
388 }
389 if (s.slidesPerView === 'auto') {
390 var styles = plt.getElementComputedStyle(slide);
391 if (isHorizontal(s)) {
392 slideSize = slide.offsetWidth + parseFloat(styles.marginRight) + parseFloat(styles.marginLeft);
393 }
394 else {
395 slideSize = slide.offsetHeight + parseFloat(styles.marginTop) + parseFloat(styles.marginBottom);
396 }
397 if (s.roundLengths)
398 slideSize = round(slideSize);
399 }
400 else {
401 slideSize = (s._renderedSize - (s.slidesPerView - 1) * spaceBetween) / s.slidesPerView;
402 if (s.roundLengths)
403 slideSize = round(slideSize);
404 if (isHorizontal(s)) {
405 s._slides[i].style.width = slideSize + 'px';
406 }
407 else {
408 s._slides[i].style.height = slideSize + 'px';
409 }
410 }
411 s._slides[i].swiperSlideSize = slideSize;
412 s._slidesSizesGrid.push(slideSize);
413 if (s.centeredSlides) {
414 slidePosition = slidePosition + slideSize / 2 + prevSlideSize / 2 + spaceBetween;
415 if (i === 0)
416 slidePosition = slidePosition - s._renderedSize / 2 - spaceBetween;
417 if (Math.abs(slidePosition) < 1 / 1000)
418 slidePosition = 0;
419 if ((index) % s.slidesPerGroup === 0)
420 s._snapGrid.push(slidePosition);
421 s._slidesGrid.push(slidePosition);
422 }
423 else {
424 if ((index) % s.slidesPerGroup === 0)
425 s._snapGrid.push(slidePosition);
426 s._slidesGrid.push(slidePosition);
427 slidePosition = slidePosition + slideSize + spaceBetween;
428 }
429 s._virtualSize += slideSize + spaceBetween;
430 prevSlideSize = slideSize;
431 index++;
432 }
433 s._virtualSize = Math.max(s._virtualSize, s._renderedSize) + s.slidesOffsetAfter;
434 var newSlidesGrid;
435 if (s._rtl && (s.effect === 'slide' || s.effect === 'coverflow')) {
436 inlineStyle(s._wrapper, { width: s._virtualSize + s.spaceBetween + 'px' });
437 }
438 if (s.setWrapperSize) {
439 if (isHorizontal(s)) {
440 inlineStyle(s._wrapper, { width: s._virtualSize + s.spaceBetween + 'px' });
441 }
442 else {
443 inlineStyle(s._wrapper, { height: s._virtualSize + s.spaceBetween + 'px' });
444 }
445 }
446 if (s.slidesPerColumn > 1) {
447 s._virtualSize = (slideSize + s.spaceBetween) * slidesNumberEvenToRows;
448 s._virtualSize = Math.ceil(s._virtualSize / s.slidesPerColumn) - s.spaceBetween;
449 if (isHorizontal(s)) {
450 inlineStyle(s._wrapper, { width: s._virtualSize + s.spaceBetween + 'px' });
451 }
452 else {
453 inlineStyle(s._wrapper, { height: s._virtualSize + s.spaceBetween + 'px' });
454 }
455 if (s.centeredSlides) {
456 newSlidesGrid = [];
457 for (i = 0; i < s._snapGrid.length; i++) {
458 if (s._snapGrid[i] < s._virtualSize + s._snapGrid[0])
459 newSlidesGrid.push(s._snapGrid[i]);
460 }
461 s._snapGrid = newSlidesGrid;
462 }
463 }
464 // Remove last grid elements depending on width
465 if (!s.centeredSlides) {
466 newSlidesGrid = [];
467 for (i = 0; i < s._snapGrid.length; i++) {
468 if (s._snapGrid[i] <= s._virtualSize - s._renderedSize) {
469 newSlidesGrid.push(s._snapGrid[i]);
470 }
471 }
472 s._snapGrid = newSlidesGrid;
473 if (Math.floor(s._virtualSize - s._renderedSize) - Math.floor(s._snapGrid[s._snapGrid.length - 1]) > 1) {
474 s._snapGrid.push(s._virtualSize - s._renderedSize);
475 }
476 }
477 if (s._snapGrid.length === 0)
478 s._snapGrid = [0];
479 if (s.spaceBetween !== 0) {
480 if (isHorizontal(s)) {
481 if (s._rtl) {
482 inlineStyle(s._slides, { marginLeft: spaceBetween + 'px' });
483 }
484 else {
485 inlineStyle(s._slides, { marginRight: spaceBetween + 'px' });
486 }
487 }
488 else {
489 inlineStyle(s._slides, { marginBottom: spaceBetween + 'px' });
490 }
491 }
492 if (s.watchSlidesProgress) {
493 updateSlidesOffset(s);
494 }
495}
496/*=========================
497 Dynamic Slides Per View
498 ===========================*/
499export function currentSlidesPerView(s) {
500 var spv = 1;
501 var i;
502 var j;
503 if (s.centeredSlides) {
504 var size = s._slides[s._activeIndex].swiperSlideSize;
505 var breakLoop;
506 for (i = s._activeIndex + 1; i < s._slides.length; i++) {
507 if (s._slides[i] && !breakLoop) {
508 size += s._slides[i].swiperSlideSize;
509 spv++;
510 if (size > s._renderedSize)
511 breakLoop = true;
512 }
513 }
514 for (j = s._activeIndex - 1; j >= 0; j--) {
515 if (s._slides[j] && !breakLoop) {
516 size += s._slides[j].swiperSlideSize;
517 spv++;
518 if (size > s._renderedSize)
519 breakLoop = true;
520 }
521 }
522 }
523 else {
524 for (i = s._activeIndex + 1; i < s._slides.length; i++) {
525 if (s._slidesGrid[i] - s._slidesGrid[s._activeIndex] < s._renderedSize) {
526 spv++;
527 }
528 }
529 }
530 return spv;
531}
532/*=========================
533 Common update method
534 ===========================*/
535export function update(s, plt, updateTranslate) {
536 if (!s)
537 return;
538 updateContainerSize(s, plt);
539 updateSlidesSize(s, plt);
540 updateProgress(s);
541 updatePagination(s);
542 updateClasses(s);
543 if (s.zoom) {
544 resetZoomEvents(s, plt);
545 }
546 var translated;
547 var newTranslate;
548 function forceSetTranslate() {
549 newTranslate = Math.min(Math.max(s._translate, maxTranslate(s)), minTranslate(s));
550 setWrapperTranslate(s, plt, newTranslate);
551 updateActiveIndex(s);
552 updateClasses(s);
553 }
554 if (updateTranslate) {
555 if (s._spline) {
556 s._spline = undefined;
557 }
558 if (s.freeMode) {
559 forceSetTranslate();
560 if (s.autoHeight) {
561 updateAutoHeight(s);
562 }
563 }
564 else {
565 if ((s.slidesPerView === 'auto' || s.slidesPerView > 1) && s._isEnd && !s.centeredSlides) {
566 translated = slideTo(s, plt, s._slides.length - 1, 0, false, true);
567 }
568 else {
569 translated = slideTo(s, plt, s._activeIndex, 0, false, true);
570 }
571 if (!translated) {
572 forceSetTranslate();
573 }
574 }
575 }
576 else if (s.autoHeight) {
577 updateAutoHeight(s);
578 }
579}
580/*=========================
581 Loop
582 ===========================*/
583// Create looped slides
584function createLoop(s) {
585 // Remove duplicated slides
586 eachChild(s._wrapper, '.' + CLS.slide + '.' + CLS.slideDuplicate, function (ele) {
587 ele.parentElement.removeChild(ele);
588 });
589 var slides = s._wrapper.querySelectorAll('.' + CLS.slide);
590 if (s.slidesPerView === 'auto' && !s.loopedSlides) {
591 s.loopedSlides = slides.length;
592 }
593 s.loopedSlides = parseInt((s.loopedSlides || s.slidesPerView), 10);
594 s.loopedSlides = s.loopedSlides + s.loopAdditionalSlides;
595 if (s.loopedSlides > slides.length) {
596 s.loopedSlides = slides.length;
597 }
598 var prependSlides = [];
599 var appendSlides = [];
600 for (var i = 0; i < slides.length; i++) {
601 var slide = slides[i];
602 if (i < s.loopedSlides)
603 appendSlides.push(slide);
604 if (i < slides.length && i >= slides.length - s.loopedSlides)
605 prependSlides.push(slide);
606 slide.setAttribute('data-swiper-slide-index', i);
607 }
608 for (i = 0; i < appendSlides.length; i++) {
609 var appendClone = appendSlides[i].cloneNode(true);
610 addClass(appendClone, CLS.slideDuplicate);
611 s._wrapper.appendChild(appendClone);
612 }
613 for (i = prependSlides.length - 1; i >= 0; i--) {
614 var prependClone = prependSlides[i].cloneNode(true);
615 addClass(prependClone, CLS.slideDuplicate);
616 s._wrapper.insertBefore(prependClone, s._wrapper.firstElementChild);
617 }
618}
619function destroyLoop(s) {
620 eachChild(s._wrapper, '.' + CLS.slide + '.' + CLS.slideDuplicate, function (ele) {
621 ele.parentElement.removeChild(ele);
622 });
623 if (s._slides) {
624 for (var i = 0; i < s._slides.length; i++) {
625 s._slides[i].removeAttribute('data-swiper-slide-index');
626 }
627 }
628}
629export function fixLoop(s, plt) {
630 var newIndex;
631 if (s._activeIndex < s.loopedSlides) {
632 // Fix For Negative Oversliding
633 newIndex = s._slides.length - s.loopedSlides * 3 + s._activeIndex;
634 newIndex = newIndex + s.loopedSlides;
635 slideTo(s, plt, newIndex, 0, false, true);
636 }
637 else if ((s.slidesPerView === 'auto' && s._activeIndex >= s.loopedSlides * 2) || (s._activeIndex > s._slides.length - s.slidesPerView * 2)) {
638 // Fix For Positive Oversliding
639 newIndex = -s._slides.length + s._activeIndex + s.loopedSlides;
640 newIndex = newIndex + s.loopedSlides;
641 slideTo(s, plt, newIndex, 0, false, true);
642 }
643}
644/*=========================
645 Transitions
646 ===========================*/
647export function slideTo(s, plt, slideIndex, speed, runCallbacks, internal) {
648 if (runCallbacks === void 0) { runCallbacks = true; }
649 if (typeof slideIndex === 'undefined')
650 slideIndex = 0;
651 if (slideIndex < 0)
652 slideIndex = 0;
653 s._snapIndex = Math.floor(slideIndex / s.slidesPerGroup);
654 if (s._snapIndex >= s._snapGrid.length)
655 s._snapIndex = s._snapGrid.length - 1;
656 var translate = -s._snapGrid[s._snapIndex];
657 // Stop autoplay
658 if (s.autoplay && s._autoplaying) {
659 if (internal || !s.autoplayDisableOnInteraction) {
660 pauseAutoplay(s, plt, speed);
661 }
662 else {
663 stopAutoplay(s);
664 }
665 }
666 // Update progress
667 updateProgress(s, translate);
668 // Directions locks
669 if (!s._allowSwipeToNext && translate < s._translate && translate < minTranslate(s)) {
670 return false;
671 }
672 if (!s._allowSwipeToPrev && translate > s._translate && translate > maxTranslate(s)) {
673 if ((s._activeIndex || 0) !== slideIndex)
674 return false;
675 }
676 // Update Index
677 if (typeof speed === 'undefined')
678 speed = s.speed;
679 s._previousIndex = s._activeIndex || 0;
680 s._activeIndex = slideIndex;
681 updateRealIndex(s);
682 if ((s._rtl && -translate === s._translate) || (!s._rtl && translate === s._translate)) {
683 // Update Height
684 if (s.autoHeight) {
685 updateAutoHeight(s);
686 }
687 updateClasses(s);
688 if (s.effect !== 'slide') {
689 setWrapperTranslate(s, plt, translate);
690 }
691 return false;
692 }
693 updateClasses(s);
694 onTransitionStart(s, runCallbacks);
695 if (speed === 0) {
696 setWrapperTranslate(s, plt, translate);
697 setWrapperTransition(s, plt, 0);
698 onTransitionEnd(s, plt, runCallbacks);
699 }
700 else {
701 setWrapperTranslate(s, plt, translate);
702 setWrapperTransition(s, plt, speed);
703 if (!s._animating) {
704 s._animating = true;
705 plt.transitionEnd(s._wrapper, function () {
706 if (!s)
707 return;
708 onTransitionEnd(s, plt, runCallbacks);
709 });
710 }
711 }
712 return true;
713}
714export function onTransitionStart(s, runCallbacks) {
715 if (runCallbacks === void 0) { runCallbacks = true; }
716 if (s.autoHeight) {
717 updateAutoHeight(s);
718 }
719 if (runCallbacks) {
720 s._zone.run(function () {
721 s.ionSlideTransitionStart.emit(s);
722 if (s._activeIndex !== s._previousIndex) {
723 s.ionSlideWillChange.emit(s);
724 if (s._activeIndex > s._previousIndex) {
725 s.ionSlideNextStart.emit(s);
726 }
727 else {
728 s.ionSlidePrevStart.emit(s);
729 }
730 }
731 });
732 }
733}
734export function onTransitionEnd(s, plt, runCallbacks) {
735 if (runCallbacks === void 0) { runCallbacks = true; }
736 s._animating = false;
737 setWrapperTransition(s, plt, 0);
738 if (runCallbacks) {
739 s._zone.run(function () {
740 s.ionSlideTransitionEnd.emit(s);
741 if (s._activeIndex !== s._previousIndex) {
742 s.ionSlideDidChange.emit(s);
743 if (s._activeIndex > s._previousIndex) {
744 s.ionSlideNextEnd.emit(s);
745 }
746 else {
747 s.ionSlidePrevEnd.emit(s);
748 }
749 }
750 });
751 }
752}
753export function slideNext(s, plt, runCallbacks, speed, internal) {
754 if (s.loop) {
755 if (s._animating)
756 return false;
757 fixLoop(s, plt);
758 s.container.clientLeft;
759 return slideTo(s, plt, s._activeIndex + s.slidesPerGroup, speed, runCallbacks, internal);
760 }
761 var nextSlide = s._activeIndex + s.slidesPerGroup;
762 if (nextSlide < s._slides.length) {
763 return slideTo(s, plt, nextSlide, speed, runCallbacks, internal);
764 }
765 return false;
766}
767export function slidePrev(s, plt, runCallbacks, speed, internal) {
768 if (s.loop) {
769 if (s._animating)
770 return false;
771 fixLoop(s, plt);
772 s.container.clientLeft;
773 return slideTo(s, plt, s._activeIndex - 1, speed, runCallbacks, internal);
774 }
775 var previousSlide = s._activeIndex - 1;
776 if (previousSlide >= 0) {
777 return slideTo(s, plt, s._activeIndex - 1, speed, runCallbacks, internal);
778 }
779 return false;
780}
781export function slideReset(s, plt, runCallbacks, speed) {
782 return slideTo(s, plt, s._activeIndex, speed, runCallbacks, true);
783}
784export function disableTouchControl(s) {
785 s.onlyExternal = true;
786 return true;
787}
788export function enableTouchControl(s) {
789 s.onlyExternal = false;
790 return true;
791}
792/*=========================
793 Translate/transition helpers
794 ===========================*/
795// Cleanup dynamic styles
796function cleanupStyles(s) {
797 if (!s.container || !s._wrapper) {
798 // fix #10830
799 return;
800 }
801 // Container
802 if (s.container) {
803 removeClass(s.container, s._classNames);
804 s.container.removeAttribute('style');
805 }
806 // Wrapper
807 s._wrapper.removeAttribute('style');
808 // Slides
809 if (s._slides && s._slides.length) {
810 removeClass(s._slides, [
811 CLS.slideVisible,
812 CLS.slideActive,
813 CLS.slideNext,
814 CLS.slidePrev
815 ]);
816 for (var i = 0; i < s._slides.length; i++) {
817 var slide = s._slides[i];
818 slide.removeAttribute('style');
819 slide.removeAttribute('data-swiper-column');
820 slide.removeAttribute('data-swiper-row');
821 }
822 }
823 // Pagination/Bullets
824 removeClass(s._bullets, CLS.bulletActive);
825 // Buttons
826 removeClass(s.prevButton, CLS.buttonDisabled);
827 removeClass(s.nextButton, CLS.buttonDisabled);
828}
829// Destroy
830export function destroySwiper(s) {
831 // Stop autoplay
832 stopAutoplay(s);
833 // Destroy loop
834 if (s.loop) {
835 destroyLoop(s);
836 }
837 // Cleanup styles
838 cleanupStyles(s);
839}
840//# sourceMappingURL=swiper.js.map
\No newline at end of file