| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840 |
- /**
- * Adopted from Swiper
- * Most modern mobile touch slider and framework with hardware
- * accelerated transitions.
- *
- * http://www.idangero.us/swiper/
- *
- * Copyright 2016, Vladimir Kharlampidi
- * The iDangero.us
- * http://www.idangero.us/
- *
- * Licensed under MIT
- */
- import { CLS, addClass, eachChild, inlineStyle, isHorizontal, maxTranslate, minTranslate, removeClass, round, updateSlidesOffset } from './swiper-utils';
- import { setWrapperTransition, setWrapperTranslate } from './swiper-transition';
- import { updateProgress } from './swiper-progress';
- import { updateClasses } from './swiper-classes';
- import { parallaxSetTranslate } from './swiper-parallax';
- import { updateActiveIndex, updateRealIndex } from './swiper-index';
- import { SWIPER_EFFECTS } from './swiper-effects';
- import { updatePagination } from './swiper-pagination';
- import { resetZoomEvents } from './swiper-zoom';
- export function initSwiper(s, plt) {
- // Classname
- s._classNames = [];
- /*=========================
- Preparation - Define Container, Wrapper and Pagination
- ===========================*/
- if (!s.container) {
- return;
- }
- // Save instance in container HTML Element and in data
- s.container.swiper = s;
- var containerModifierClass = CLS.containerModifier;
- s._classNames.push(containerModifierClass + s.direction);
- if (s.freeMode) {
- s._classNames.push(containerModifierClass + 'free-mode');
- }
- if (s.autoHeight) {
- s._classNames.push(containerModifierClass + 'autoheight');
- }
- // Enable slides progress when required
- if (s.parallax || s.watchSlidesVisibility) {
- s.watchSlidesProgress = true;
- }
- // Max resistance when touchReleaseOnEdges
- if (s.touchReleaseOnEdges) {
- s.resistanceRatio = 0;
- }
- var effect = s.effect;
- // Coverflow / 3D
- if (['cube', 'coverflow', 'flip'].indexOf(effect) >= 0) {
- s.watchSlidesProgress = true;
- s._classNames.push(containerModifierClass + '3d');
- }
- if (effect !== 'slide') {
- s._classNames.push(containerModifierClass + effect);
- }
- if (effect === 'cube') {
- s.resistanceRatio = 0;
- s.slidesPerView = 1;
- s.slidesPerColumn = 1;
- s.slidesPerGroup = 1;
- s.centeredSlides = false;
- s.spaceBetween = 0;
- s.virtualTranslate = true;
- s.setWrapperSize = false;
- }
- if (effect === 'fade' || effect === 'flip') {
- s.slidesPerView = 1;
- s.slidesPerColumn = 1;
- s.slidesPerGroup = 1;
- s.watchSlidesProgress = true;
- s.spaceBetween = 0;
- s.setWrapperSize = false;
- s.virtualTranslate = true;
- }
- // Wrapper
- s._wrapper = s.container.querySelector('.' + CLS.wrapper);
- // Pagination
- if (s.paginationType) {
- s._paginationContainer = s.container.querySelector('.swiper-pagination');
- if (s.paginationType === 'bullets') {
- s._paginationContainer.classList.add(CLS.paginationModifier + 'clickable');
- }
- s._paginationContainer.classList.add(CLS.paginationModifier + s.paginationType);
- }
- // Next/Prev Buttons
- // if (s.nextButton || s.prevButton) {
- // if (s.nextButton) {
- // s.nextButton = <any>s.container.closest('ion-content').querySelector(s.nextButton);
- // }
- // if (s.prevButton) {
- // s.prevButton = <any>s.container.closest('ion-content').querySelector(s.prevButton);
- // }
- // }
- // RTL
- s._rtl = isHorizontal(s) && (s.container.dir.toLowerCase() === 'rtl' || s.container.style.direction === 'rtl');
- if (s._rtl) {
- s._classNames.push(containerModifierClass + 'rtl');
- }
- // Columns
- if (s.slidesPerColumn > 1) {
- s._classNames.push(containerModifierClass + 'multirow');
- }
- // Check for Android
- if (plt.is('android')) {
- s._classNames.push(containerModifierClass + 'android');
- }
- // Add classes
- s._classNames.forEach(function (clsName) {
- s.container.classList.add(clsName);
- });
- // Translate
- s._translate = 0;
- // Progress
- s.progress = 0;
- // Velocity
- s.velocity = 0;
- /*=========================
- Autoplay
- ===========================*/
- s._autoplayTimeoutId = undefined;
- s._autoplaying = false;
- s._autoplayPaused = false;
- s._allowClick = true;
- // Animating Flag
- s._animating = false;
- // Touches information
- s._touches = {
- startX: 0,
- startY: 0,
- currentX: 0,
- currentY: 0,
- diff: 0
- };
- if (s.loop) {
- createLoop(s);
- }
- updateContainerSize(s, plt);
- updateSlidesSize(s, plt);
- updatePagination(s);
- if (effect !== 'slide' && SWIPER_EFFECTS[effect]) {
- if (!s.loop) {
- updateProgress(s);
- }
- SWIPER_EFFECTS[effect].setTranslate(s, plt);
- }
- if (s.loop) {
- slideTo(s, plt, s.initialSlide + s.loopedSlides, 0, s.runCallbacksOnInit);
- }
- else {
- slideTo(s, plt, s.initialSlide, 0, s.runCallbacksOnInit);
- if (s.initialSlide === 0) {
- parallaxSetTranslate(s);
- }
- }
- if (s.autoplay) {
- startAutoplay(s, plt);
- }
- }
- /*=========================
- Autoplay
- ===========================*/
- function autoplay(s, plt) {
- var autoplayDelay = s.autoplay;
- var activeSlide = s._slides[s._activeIndex];
- if (activeSlide.hasAttribute('data-swiper-autoplay')) {
- autoplayDelay = (activeSlide.getAttribute('data-swiper-autoplay') || s.autoplay);
- }
- s._autoplayTimeoutId = plt.timeout(function () {
- s._zone.run(function () {
- if (s.loop) {
- fixLoop(s, plt);
- slideNext(s, plt, true, undefined, true);
- s.ionSlideAutoplay.emit(s);
- }
- else {
- if (!s._isEnd) {
- slideNext(s, plt, true, undefined, true);
- s.ionSlideAutoplay.emit(s);
- }
- else {
- if (!s.autoplayStopOnLast) {
- slideTo(s, plt, 0);
- s.ionSlideAutoplay.emit(s);
- }
- else {
- stopAutoplay(s);
- }
- }
- }
- });
- }, autoplayDelay);
- }
- export function startAutoplay(s, plt) {
- if (typeof s._autoplayTimeoutId !== 'undefined')
- return false;
- if (!s.autoplay || s._autoplaying) {
- return false;
- }
- s._autoplaying = true;
- s._zone.run(function () {
- s.ionSlideAutoplayStart.emit(s);
- });
- autoplay(s, plt);
- }
- export function stopAutoplay(s) {
- if (!s._autoplayTimeoutId)
- return;
- if (s._autoplayTimeoutId)
- clearTimeout(s._autoplayTimeoutId);
- s._autoplaying = false;
- s._autoplayTimeoutId = undefined;
- s._zone.run(function () {
- s.ionSlideAutoplayStop.emit(s);
- });
- }
- export function pauseAutoplay(s, plt, speed) {
- if (s._autoplayPaused)
- return;
- if (s._autoplayTimeoutId)
- clearTimeout(s._autoplayTimeoutId);
- s._autoplayPaused = true;
- if (speed === 0) {
- s._autoplayPaused = false;
- autoplay(s, plt);
- }
- else {
- plt.transitionEnd(s._wrapper, function () {
- if (!s)
- return;
- s._autoplayPaused = false;
- if (!s._autoplaying) {
- stopAutoplay(s);
- }
- else {
- autoplay(s, plt);
- }
- });
- }
- }
- /*=========================
- Slider/slides sizes
- ===========================*/
- export function updateAutoHeight(s) {
- var activeSlides = [];
- var newHeight = 0;
- var i;
- // Find slides currently in view
- if (s.slidesPerView !== 'auto' && s.slidesPerView > 1) {
- for (i = 0; i < Math.ceil(s.slidesPerView); i++) {
- var index = s._activeIndex + i;
- if (index > s._slides.length)
- break;
- activeSlides.push(s._slides[index]);
- }
- }
- else {
- activeSlides.push(s._slides[s._activeIndex]);
- }
- // Find new height from heighest slide in view
- for (i = 0; i < activeSlides.length; i++) {
- if (typeof activeSlides[i] !== 'undefined') {
- var height = activeSlides[i].offsetHeight;
- newHeight = height > newHeight ? height : newHeight;
- }
- }
- // Update Height
- if (newHeight) {
- s._wrapper.style.height = newHeight + 'px';
- }
- }
- export function updateContainerSize(s, plt) {
- var container = s.container;
- var width;
- var height;
- if (typeof s.width !== 'undefined') {
- // manually assign user width
- width = s.width;
- }
- else {
- width = container.clientWidth;
- }
- if (typeof s.renderedHeight !== 'undefined') {
- // manually assign user height
- height = s.renderedHeight;
- }
- else {
- height = container.clientHeight;
- }
- if (width === 0 && isHorizontal(s) || height === 0 && !isHorizontal(s)) {
- return;
- }
- // Subtract paddings
- var containerStyles = plt.getElementComputedStyle(container);
- width = width - parseInt(containerStyles.paddingLeft, 10) - parseInt(containerStyles.paddingRight, 10);
- height = height - parseInt(containerStyles.paddingTop, 10) - parseInt(containerStyles.paddingBottom, 10);
- // Store values
- s.renderedWidth = width;
- s.renderedHeight = height;
- s._renderedSize = isHorizontal(s) ? width : height;
- }
- export function updateSlidesSize(s, plt) {
- s._slides = s._wrapper.querySelectorAll('.' + CLS.slide);
- s._snapGrid = [];
- s._slidesGrid = [];
- s._slidesSizesGrid = [];
- var spaceBetween = s.spaceBetween;
- var slidePosition = -s.slidesOffsetBefore;
- var i;
- var prevSlideSize = 0;
- var index = 0;
- if (typeof s._renderedSize === 'undefined')
- return;
- if (typeof spaceBetween === 'string' && spaceBetween.indexOf('%') >= 0) {
- spaceBetween = parseFloat(spaceBetween.replace('%', '')) / 100 * s._renderedSize;
- }
- s._virtualSize = -spaceBetween;
- // reset margins
- if (s._rtl) {
- inlineStyle(s._slides, { marginLeft: '', marginTop: '' });
- }
- else {
- inlineStyle(s._slides, { marginRight: '', marginBottom: '' });
- }
- var slidesNumberEvenToRows;
- if (s.slidesPerColumn > 1) {
- if (Math.floor(s._slides.length / s.slidesPerColumn) === s._slides.length / s.slidesPerColumn) {
- slidesNumberEvenToRows = s._slides.length;
- }
- else {
- slidesNumberEvenToRows = Math.ceil(s._slides.length / s.slidesPerColumn) * s.slidesPerColumn;
- }
- if (s.slidesPerView !== 'auto' && s.slidesPerColumnFill === 'row') {
- slidesNumberEvenToRows = Math.max(slidesNumberEvenToRows, s.slidesPerView * s.slidesPerColumn);
- }
- }
- // Calc slides
- var slideSize;
- var slidesPerColumn = s.slidesPerColumn;
- var slidesPerRow = slidesNumberEvenToRows / slidesPerColumn;
- var numFullColumns = slidesPerRow - (s.slidesPerColumn * slidesPerRow - s._slides.length);
- for (i = 0; i < s._slides.length; i++) {
- slideSize = 0;
- var slide = s._slides[i];
- if (s.slidesPerColumn > 1) {
- // Set slides order
- var newSlideOrderIndex;
- var column;
- var row;
- if (s.slidesPerColumnFill === 'column') {
- column = Math.floor(i / slidesPerColumn);
- row = i - column * slidesPerColumn;
- if (column > numFullColumns || (column === numFullColumns && row === slidesPerColumn - 1)) {
- if (++row >= slidesPerColumn) {
- row = 0;
- column++;
- }
- }
- newSlideOrderIndex = column + row * slidesNumberEvenToRows / slidesPerColumn;
- inlineStyle(slide, {
- '-webkit-box-ordinal-group': newSlideOrderIndex,
- '-moz-box-ordinal-group': newSlideOrderIndex,
- '-ms-flex-order': newSlideOrderIndex,
- '-webkit-order': newSlideOrderIndex,
- 'order': newSlideOrderIndex
- });
- }
- else {
- row = Math.floor(i / slidesPerRow);
- column = i - row * slidesPerRow;
- }
- var cssVal = (row !== 0 && s.spaceBetween) && (s.spaceBetween + 'px');
- var cssObj = {};
- if (isHorizontal(s)) {
- cssObj['marginTop'] = cssVal;
- }
- else {
- cssObj['marginLeft'] = cssVal;
- }
- inlineStyle(slide, cssObj);
- slide.setAttribute('data-swiper-column', column);
- slide.setAttribute('data-swiper-row', row);
- }
- if (slide.style.display === 'none') {
- continue;
- }
- if (s.slidesPerView === 'auto') {
- var styles = plt.getElementComputedStyle(slide);
- if (isHorizontal(s)) {
- slideSize = slide.offsetWidth + parseFloat(styles.marginRight) + parseFloat(styles.marginLeft);
- }
- else {
- slideSize = slide.offsetHeight + parseFloat(styles.marginTop) + parseFloat(styles.marginBottom);
- }
- if (s.roundLengths)
- slideSize = round(slideSize);
- }
- else {
- slideSize = (s._renderedSize - (s.slidesPerView - 1) * spaceBetween) / s.slidesPerView;
- if (s.roundLengths)
- slideSize = round(slideSize);
- if (isHorizontal(s)) {
- s._slides[i].style.width = slideSize + 'px';
- }
- else {
- s._slides[i].style.height = slideSize + 'px';
- }
- }
- s._slides[i].swiperSlideSize = slideSize;
- s._slidesSizesGrid.push(slideSize);
- if (s.centeredSlides) {
- slidePosition = slidePosition + slideSize / 2 + prevSlideSize / 2 + spaceBetween;
- if (i === 0)
- slidePosition = slidePosition - s._renderedSize / 2 - spaceBetween;
- if (Math.abs(slidePosition) < 1 / 1000)
- slidePosition = 0;
- if ((index) % s.slidesPerGroup === 0)
- s._snapGrid.push(slidePosition);
- s._slidesGrid.push(slidePosition);
- }
- else {
- if ((index) % s.slidesPerGroup === 0)
- s._snapGrid.push(slidePosition);
- s._slidesGrid.push(slidePosition);
- slidePosition = slidePosition + slideSize + spaceBetween;
- }
- s._virtualSize += slideSize + spaceBetween;
- prevSlideSize = slideSize;
- index++;
- }
- s._virtualSize = Math.max(s._virtualSize, s._renderedSize) + s.slidesOffsetAfter;
- var newSlidesGrid;
- if (s._rtl && (s.effect === 'slide' || s.effect === 'coverflow')) {
- inlineStyle(s._wrapper, { width: s._virtualSize + s.spaceBetween + 'px' });
- }
- if (s.setWrapperSize) {
- if (isHorizontal(s)) {
- inlineStyle(s._wrapper, { width: s._virtualSize + s.spaceBetween + 'px' });
- }
- else {
- inlineStyle(s._wrapper, { height: s._virtualSize + s.spaceBetween + 'px' });
- }
- }
- if (s.slidesPerColumn > 1) {
- s._virtualSize = (slideSize + s.spaceBetween) * slidesNumberEvenToRows;
- s._virtualSize = Math.ceil(s._virtualSize / s.slidesPerColumn) - s.spaceBetween;
- if (isHorizontal(s)) {
- inlineStyle(s._wrapper, { width: s._virtualSize + s.spaceBetween + 'px' });
- }
- else {
- inlineStyle(s._wrapper, { height: s._virtualSize + s.spaceBetween + 'px' });
- }
- if (s.centeredSlides) {
- newSlidesGrid = [];
- for (i = 0; i < s._snapGrid.length; i++) {
- if (s._snapGrid[i] < s._virtualSize + s._snapGrid[0])
- newSlidesGrid.push(s._snapGrid[i]);
- }
- s._snapGrid = newSlidesGrid;
- }
- }
- // Remove last grid elements depending on width
- if (!s.centeredSlides) {
- newSlidesGrid = [];
- for (i = 0; i < s._snapGrid.length; i++) {
- if (s._snapGrid[i] <= s._virtualSize - s._renderedSize) {
- newSlidesGrid.push(s._snapGrid[i]);
- }
- }
- s._snapGrid = newSlidesGrid;
- if (Math.floor(s._virtualSize - s._renderedSize) - Math.floor(s._snapGrid[s._snapGrid.length - 1]) > 1) {
- s._snapGrid.push(s._virtualSize - s._renderedSize);
- }
- }
- if (s._snapGrid.length === 0)
- s._snapGrid = [0];
- if (s.spaceBetween !== 0) {
- if (isHorizontal(s)) {
- if (s._rtl) {
- inlineStyle(s._slides, { marginLeft: spaceBetween + 'px' });
- }
- else {
- inlineStyle(s._slides, { marginRight: spaceBetween + 'px' });
- }
- }
- else {
- inlineStyle(s._slides, { marginBottom: spaceBetween + 'px' });
- }
- }
- if (s.watchSlidesProgress) {
- updateSlidesOffset(s);
- }
- }
- /*=========================
- Dynamic Slides Per View
- ===========================*/
- export function currentSlidesPerView(s) {
- var spv = 1;
- var i;
- var j;
- if (s.centeredSlides) {
- var size = s._slides[s._activeIndex].swiperSlideSize;
- var breakLoop;
- for (i = s._activeIndex + 1; i < s._slides.length; i++) {
- if (s._slides[i] && !breakLoop) {
- size += s._slides[i].swiperSlideSize;
- spv++;
- if (size > s._renderedSize)
- breakLoop = true;
- }
- }
- for (j = s._activeIndex - 1; j >= 0; j--) {
- if (s._slides[j] && !breakLoop) {
- size += s._slides[j].swiperSlideSize;
- spv++;
- if (size > s._renderedSize)
- breakLoop = true;
- }
- }
- }
- else {
- for (i = s._activeIndex + 1; i < s._slides.length; i++) {
- if (s._slidesGrid[i] - s._slidesGrid[s._activeIndex] < s._renderedSize) {
- spv++;
- }
- }
- }
- return spv;
- }
- /*=========================
- Common update method
- ===========================*/
- export function update(s, plt, updateTranslate) {
- if (!s)
- return;
- updateContainerSize(s, plt);
- updateSlidesSize(s, plt);
- updateProgress(s);
- updatePagination(s);
- updateClasses(s);
- if (s.zoom) {
- resetZoomEvents(s, plt);
- }
- var translated;
- var newTranslate;
- function forceSetTranslate() {
- newTranslate = Math.min(Math.max(s._translate, maxTranslate(s)), minTranslate(s));
- setWrapperTranslate(s, plt, newTranslate);
- updateActiveIndex(s);
- updateClasses(s);
- }
- if (updateTranslate) {
- if (s._spline) {
- s._spline = undefined;
- }
- if (s.freeMode) {
- forceSetTranslate();
- if (s.autoHeight) {
- updateAutoHeight(s);
- }
- }
- else {
- if ((s.slidesPerView === 'auto' || s.slidesPerView > 1) && s._isEnd && !s.centeredSlides) {
- translated = slideTo(s, plt, s._slides.length - 1, 0, false, true);
- }
- else {
- translated = slideTo(s, plt, s._activeIndex, 0, false, true);
- }
- if (!translated) {
- forceSetTranslate();
- }
- }
- }
- else if (s.autoHeight) {
- updateAutoHeight(s);
- }
- }
- /*=========================
- Loop
- ===========================*/
- // Create looped slides
- function createLoop(s) {
- // Remove duplicated slides
- eachChild(s._wrapper, '.' + CLS.slide + '.' + CLS.slideDuplicate, function (ele) {
- ele.parentElement.removeChild(ele);
- });
- var slides = s._wrapper.querySelectorAll('.' + CLS.slide);
- if (s.slidesPerView === 'auto' && !s.loopedSlides) {
- s.loopedSlides = slides.length;
- }
- s.loopedSlides = parseInt((s.loopedSlides || s.slidesPerView), 10);
- s.loopedSlides = s.loopedSlides + s.loopAdditionalSlides;
- if (s.loopedSlides > slides.length) {
- s.loopedSlides = slides.length;
- }
- var prependSlides = [];
- var appendSlides = [];
- for (var i = 0; i < slides.length; i++) {
- var slide = slides[i];
- if (i < s.loopedSlides)
- appendSlides.push(slide);
- if (i < slides.length && i >= slides.length - s.loopedSlides)
- prependSlides.push(slide);
- slide.setAttribute('data-swiper-slide-index', i);
- }
- for (i = 0; i < appendSlides.length; i++) {
- var appendClone = appendSlides[i].cloneNode(true);
- addClass(appendClone, CLS.slideDuplicate);
- s._wrapper.appendChild(appendClone);
- }
- for (i = prependSlides.length - 1; i >= 0; i--) {
- var prependClone = prependSlides[i].cloneNode(true);
- addClass(prependClone, CLS.slideDuplicate);
- s._wrapper.insertBefore(prependClone, s._wrapper.firstElementChild);
- }
- }
- function destroyLoop(s) {
- eachChild(s._wrapper, '.' + CLS.slide + '.' + CLS.slideDuplicate, function (ele) {
- ele.parentElement.removeChild(ele);
- });
- if (s._slides) {
- for (var i = 0; i < s._slides.length; i++) {
- s._slides[i].removeAttribute('data-swiper-slide-index');
- }
- }
- }
- export function fixLoop(s, plt) {
- var newIndex;
- if (s._activeIndex < s.loopedSlides) {
- // Fix For Negative Oversliding
- newIndex = s._slides.length - s.loopedSlides * 3 + s._activeIndex;
- newIndex = newIndex + s.loopedSlides;
- slideTo(s, plt, newIndex, 0, false, true);
- }
- else if ((s.slidesPerView === 'auto' && s._activeIndex >= s.loopedSlides * 2) || (s._activeIndex > s._slides.length - s.slidesPerView * 2)) {
- // Fix For Positive Oversliding
- newIndex = -s._slides.length + s._activeIndex + s.loopedSlides;
- newIndex = newIndex + s.loopedSlides;
- slideTo(s, plt, newIndex, 0, false, true);
- }
- }
- /*=========================
- Transitions
- ===========================*/
- export function slideTo(s, plt, slideIndex, speed, runCallbacks, internal) {
- if (runCallbacks === void 0) { runCallbacks = true; }
- if (typeof slideIndex === 'undefined')
- slideIndex = 0;
- if (slideIndex < 0)
- slideIndex = 0;
- s._snapIndex = Math.floor(slideIndex / s.slidesPerGroup);
- if (s._snapIndex >= s._snapGrid.length)
- s._snapIndex = s._snapGrid.length - 1;
- var translate = -s._snapGrid[s._snapIndex];
- // Stop autoplay
- if (s.autoplay && s._autoplaying) {
- if (internal || !s.autoplayDisableOnInteraction) {
- pauseAutoplay(s, plt, speed);
- }
- else {
- stopAutoplay(s);
- }
- }
- // Update progress
- updateProgress(s, translate);
- // Directions locks
- if (!s._allowSwipeToNext && translate < s._translate && translate < minTranslate(s)) {
- return false;
- }
- if (!s._allowSwipeToPrev && translate > s._translate && translate > maxTranslate(s)) {
- if ((s._activeIndex || 0) !== slideIndex)
- return false;
- }
- // Update Index
- if (typeof speed === 'undefined')
- speed = s.speed;
- s._previousIndex = s._activeIndex || 0;
- s._activeIndex = slideIndex;
- updateRealIndex(s);
- if ((s._rtl && -translate === s._translate) || (!s._rtl && translate === s._translate)) {
- // Update Height
- if (s.autoHeight) {
- updateAutoHeight(s);
- }
- updateClasses(s);
- if (s.effect !== 'slide') {
- setWrapperTranslate(s, plt, translate);
- }
- return false;
- }
- updateClasses(s);
- onTransitionStart(s, runCallbacks);
- if (speed === 0) {
- setWrapperTranslate(s, plt, translate);
- setWrapperTransition(s, plt, 0);
- onTransitionEnd(s, plt, runCallbacks);
- }
- else {
- setWrapperTranslate(s, plt, translate);
- setWrapperTransition(s, plt, speed);
- if (!s._animating) {
- s._animating = true;
- plt.transitionEnd(s._wrapper, function () {
- if (!s)
- return;
- onTransitionEnd(s, plt, runCallbacks);
- });
- }
- }
- return true;
- }
- export function onTransitionStart(s, runCallbacks) {
- if (runCallbacks === void 0) { runCallbacks = true; }
- if (s.autoHeight) {
- updateAutoHeight(s);
- }
- if (runCallbacks) {
- s._zone.run(function () {
- s.ionSlideTransitionStart.emit(s);
- if (s._activeIndex !== s._previousIndex) {
- s.ionSlideWillChange.emit(s);
- if (s._activeIndex > s._previousIndex) {
- s.ionSlideNextStart.emit(s);
- }
- else {
- s.ionSlidePrevStart.emit(s);
- }
- }
- });
- }
- }
- export function onTransitionEnd(s, plt, runCallbacks) {
- if (runCallbacks === void 0) { runCallbacks = true; }
- s._animating = false;
- setWrapperTransition(s, plt, 0);
- if (runCallbacks) {
- s._zone.run(function () {
- s.ionSlideTransitionEnd.emit(s);
- if (s._activeIndex !== s._previousIndex) {
- s.ionSlideDidChange.emit(s);
- if (s._activeIndex > s._previousIndex) {
- s.ionSlideNextEnd.emit(s);
- }
- else {
- s.ionSlidePrevEnd.emit(s);
- }
- }
- });
- }
- }
- export function slideNext(s, plt, runCallbacks, speed, internal) {
- if (s.loop) {
- if (s._animating)
- return false;
- fixLoop(s, plt);
- s.container.clientLeft;
- return slideTo(s, plt, s._activeIndex + s.slidesPerGroup, speed, runCallbacks, internal);
- }
- var nextSlide = s._activeIndex + s.slidesPerGroup;
- if (nextSlide < s._slides.length) {
- return slideTo(s, plt, nextSlide, speed, runCallbacks, internal);
- }
- return false;
- }
- export function slidePrev(s, plt, runCallbacks, speed, internal) {
- if (s.loop) {
- if (s._animating)
- return false;
- fixLoop(s, plt);
- s.container.clientLeft;
- return slideTo(s, plt, s._activeIndex - 1, speed, runCallbacks, internal);
- }
- var previousSlide = s._activeIndex - 1;
- if (previousSlide >= 0) {
- return slideTo(s, plt, s._activeIndex - 1, speed, runCallbacks, internal);
- }
- return false;
- }
- export function slideReset(s, plt, runCallbacks, speed) {
- return slideTo(s, plt, s._activeIndex, speed, runCallbacks, true);
- }
- export function disableTouchControl(s) {
- s.onlyExternal = true;
- return true;
- }
- export function enableTouchControl(s) {
- s.onlyExternal = false;
- return true;
- }
- /*=========================
- Translate/transition helpers
- ===========================*/
- // Cleanup dynamic styles
- function cleanupStyles(s) {
- if (!s.container || !s._wrapper) {
- // fix #10830
- return;
- }
- // Container
- if (s.container) {
- removeClass(s.container, s._classNames);
- s.container.removeAttribute('style');
- }
- // Wrapper
- s._wrapper.removeAttribute('style');
- // Slides
- if (s._slides && s._slides.length) {
- removeClass(s._slides, [
- CLS.slideVisible,
- CLS.slideActive,
- CLS.slideNext,
- CLS.slidePrev
- ]);
- for (var i = 0; i < s._slides.length; i++) {
- var slide = s._slides[i];
- slide.removeAttribute('style');
- slide.removeAttribute('data-swiper-column');
- slide.removeAttribute('data-swiper-row');
- }
- }
- // Pagination/Bullets
- removeClass(s._bullets, CLS.bulletActive);
- // Buttons
- removeClass(s.prevButton, CLS.buttonDisabled);
- removeClass(s.nextButton, CLS.buttonDisabled);
- }
- // Destroy
- export function destroySwiper(s) {
- // Stop autoplay
- stopAutoplay(s);
- // Destroy loop
- if (s.loop) {
- destroyLoop(s);
- }
- // Cleanup styles
- cleanupStyles(s);
- }
- //# sourceMappingURL=swiper.js.map
|