1/** 2 * Swiper 3.4.2 3 * Most modern mobile touch slider and framework with hardware accelerated transitions 4 * 5 * http://www.idangero.us/swiper/ 6 * 7 * Copyright 2017, Vladimir Kharlampidi 8 * The iDangero.us 9 * http://www.idangero.us/ 10 * 11 * Licensed under MIT 12 * 13 * Released on: March 10, 2017 14 */ 15(function () { 16 'use strict'; 17 var $; 18 19 /*=========================== 20 Swiper 21 ===========================*/ 22 var Swiper = function (container, params) { 23 if (!(this instanceof Swiper)) return new Swiper(container, params); 24 25 26 var defaults = { 27 direction: 'horizontal', 28 touchEventsTarget: 'container', 29 initialSlide: 0, 30 speed: 3000, 31 // autoplay 32 autoplay: false, 33 autoplayDisableOnInteraction: true, 34 autoplayStopOnLast: false, 35 // To support iOS's swipe-to-go-back gesture (when being used in-app, with UIWebView). 36 iOSEdgeSwipeDetection: false, 37 iOSEdgeSwipeThreshold: 20, 38 // Free mode 39 freeMode: false, 40 freeModeMomentum: true, 41 freeModeMomentumRatio: 1, 42 freeModeMomentumBounce: true, 43 freeModeMomentumBounceRatio: 1, 44 freeModeMomentumVelocityRatio: 1, 45 freeModeSticky: false, 46 freeModeMinimumVelocity: 0.02, 47 // Autoheight 48 autoHeight: false, 49 // Set wrapper width 50 setWrapperSize: false, 51 // Virtual Translate 52 virtualTranslate: false, 53 // Effects 54 effect: 'slide', // 'slide' or 'fade' or 'cube' or 'coverflow' or 'flip' 55 coverflow: { 56 rotate: 50, 57 stretch: 0, 58 depth: 100, 59 modifier: 1, 60 slideShadows: true 61 }, 62 flip: { 63 slideShadows: true, 64 limitRotation: true 65 }, 66 cube: { 67 slideShadows: true, 68 shadow: true, 69 shadowOffset: 20, 70 shadowScale: 0.94 71 }, 72 fade: { 73 crossFade: false 74 }, 75 // Parallax 76 parallax: false, 77 // Zoom 78 zoom: false, 79 zoomMax: 3, 80 zoomMin: 1, 81 zoomToggle: true, 82 // Scrollbar 83 scrollbar: null, 84 scrollbarHide: true, 85 scrollbarDraggable: false, 86 scrollbarSnapOnRelease: false, 87 // Keyboard Mousewheel 88 keyboardControl: false, 89 mousewheelControl: false, 90 mousewheelReleaseOnEdges: false, 91 mousewheelInvert: false,
92 mousewheelForceToAxis: false, 93 mousewheelSensitivity: 1, 94 mousewheelEventsTarged: 'container', 95 // Hash Navigation 96 hashnav: false, 97 hashnavWatchState: false, 98 // History 99 history: false, 100 // Commong Nav State 101 replaceState: false, 102 // Breakpoints 103 breakpoints: { 104 960: { 105 slidesPerView: 6, 106 spaceBetween: 8 107 }, 108 720: { 109 slidesPerView: 3, 110 spaceBetween: 4 111 }, 112 540: { 113 slidesPerView: 3, 114 spaceBetween: 4 115 }, 116 320: { 117 slidesPerView: 3, 118 spaceBetween: 2 119 } 120 }, 121 // Slides grid 122 spaceBetween: 0, 123 slidesPerView: 6, 124 slidesPerColumn: 1, 125 slidesPerColumnFill: 'column', 126 slidesPerGroup: 1, 127 centeredSlides: false, 128 slidesOffsetBefore: 0, // in px 129 slidesOffsetAfter: 0, // in px 130 // Round length 131 roundLengths: false, 132 // Touches 133 touchRatio: 1, 134 touchAngle: 45, 135 simulateTouch: true, 136 shortSwipes: true, 137 longSwipes: true, 138 longSwipesRatio: 0.5, 139 longSwipesMs: 300, 140 followFinger: true, 141 onlyExternal: false, 142 threshold: 0, 143 touchMoveStopPropagation: true, 144 touchReleaseOnEdges: false, 145 // Unique Navigation Elements 146 uniqueNavElements: true, 147 // Pagination 148 pagination: null, 149 paginationElement: 'span', 150 paginationClickable: false, 151 paginationHide: false, 152 paginationBulletRender: null, 153 paginationProgressRender: null, 154 paginationFractionRender: null, 155 paginationCustomRender: null, 156 paginationType: 'bullets', // 'bullets' or 'progress' or 'fraction' or 'custom' 157 // Resistance 158 resistance: true, 159 resistanceRatio: 0.85, 160 // Next/prev buttons 161 nextButton: null, 162 prevButton: null, 163 // Progress 164 watchSlidesProgress: false, 165 watchSlidesVisibility: false, 166 // Cursor 167 grabCursor: false, 168 // Clicks 169 preventClicks: true, 170 preventClicksPropagation: true, 171 slideToClickedSlide: false, 172 // Lazy Loading 173 lazyLoading: false, 174 lazyLoadingInPrevNext: false, 175 lazyLoadingInPrevNextAmount: 1, 176 lazyLoadingOnTransitionStart: false, 177 // Images 178 preloadImages: true, 179 updateOnImagesReady: true, 180 // loop 181 loop: false, 182 loopAdditionalSlides: 0, 183 loopedSlides: null, 184 // Control 185 control: undefined, 186 controlInverse: false, 187 controlBy: 'slide', //or 'container' 188 normalizeSlideIndex: true, 189 // Swiping/no swiping 190 allowSwipeToPrev: true, 191 allowSwipeToNext: true, 192 swipeHandler: null, //'.swipe-handler', 193 noSwiping: true, 194 noSwipingClass: 'swiper-no-swiping', 195 // Passive Listeners 196 passiveListeners: true, 197 // NS 198 containerModifierClass: 'swiper-container-', // NEW 199 slideClass: 'swiper-slide', 200 slideActiveClass: 'swiper-slide-active', 201 slideDuplicateActiveClass: 'swiper-slide-duplicate-active', 202 slideVisibleClass: 'swiper-slide-visible', 203 slideDuplicateClass: 'swiper-slide-duplicate', 204 slideNextClass: 'swiper-slide-next', 205 slideDuplicateNextClass: 'swiper-slide-duplicate-next', 206 slidePrevClass: 'swiper-slide-prev', 207 slideDuplicatePrevClass: 'swiper-slide-duplicate-prev', 208 wrapperClass: 'swiper-wrapper', 209 bulletClass: 'swiper-pagination-bullet', 210 bulletActiveClass: 'swiper-pagination-bullet-active', 211 buttonDisabledClass: 'swiper-button-disabled', 212 paginationCurrentClass: 'swiper-pagination-current', 213 paginationTotalClass: 'swiper-pagination-total', 214 paginationHiddenClass: 'swiper-pagination-hidden', 215 paginationProgressbarClass: 'swiper-pagination-progressbar', 216 paginationClickableClass: 'swiper-pagination-clickable', // NEW 217 paginationModifierClass: 'swiper-pagination-', // NEW 218 lazyLoadingClass: 'swiper-lazy', 219 lazyStatusLoadingClass: 'swiper-lazy-loading', 220 lazyStatusLoadedClass: 'swiper-lazy-loaded', 221 lazyPreloaderClass: 'swiper-lazy-preloader', 222 notificationClass: 'swiper-notification', 223 preloaderClass: 'preloader', 224 zoomContainerClass: 'swiper-zoom-container', 225 226 // Observer 227 observer: false, 228 observeParents: false, 229 // Accessibility
230 a11y: false, 231 prevSlideMessage: 'Previous slide', 232 nextSlideMessage: 'Next slide', 233 firstSlideMessage: 'This is the first slide', 234 lastSlideMessage: 'This is the last slide', 235 paginationBulletMessage: 'Go to slide {{index}}', 236 // Callbacks 237 runCallbacksOnInit: true 238 /* 239 Callbacks: 240 onInit: function (swiper) 241 onDestroy: function (swiper) 242 onBeforeResize: function (swiper) 243 onAfterResize: function (swiper) 244 onClick: function (swiper, e) 245 onTap: function (swiper, e) 246 onDoubleTap: function (swiper, e) 247 onSliderMove: function (swiper, e) 248 onSlideChangeStart: function (swiper) 249 onSlideChangeEnd: function (swiper) 250 onTransitionStart: function (swiper) 251 onTransitionEnd: function (swiper) 252 onImagesReady: function (swiper) 253 onProgress: function (swiper, progress) 254 onTouchStart: function (swiper, e) 255 onTouchMove: function (swiper, e) 256 onTouchMoveOpposite: function (swiper, e) 257 onTouchEnd: function (swiper, e) 258 onReachBeginning: function (swiper) 259 onReachEnd: function (swiper) 260 onSetTransition: function (swiper, duration) 261 onSetTranslate: function (swiper, translate) 262 onAutoplayStart: function (swiper) 263 onAutoplayStop: function (swiper), 264 onLazyImageLoad: function (swiper, slide, image) 265 onLazyImageReady: function (swiper, slide, image) 266 onKeyPress: function (swiper, keyCode) 267 */ 268 269 }; 270 var initialVirtualTranslate = params && params.virtualTranslate; 271 272 params = params || {}; 273 var originalParams = {}; 274 for (var param in params) { 275 if (typeof params[param] === 'object' && params[param] !== null && !(params[param].nodeType || params[param] === window || params[param] === document || (typeof Dom7 !== 'undefined' && params[param] instanceof Dom7) || (typeof jQuery !== 'undefined' && params[param] instanceof jQuery))) { 276 originalParams[param] = {}; 277 for (var deepParam in params[param]) { 278 originalParams[param][deepParam] = params[param][deepParam]; 279 } 280 } 281 else { 282 originalParams[param] = params[param]; 283 } 284 } 285 for (var def in defaults) { 286 if (typeof params[def] === 'undefined') { 287 params[def] = defaults[def]; 288 } 289 else if (typeof params[def] === 'object') { 290 for (var deepDef in defaults[def]) { 291 if (typeof params[def][deepDef] === 'undefined') { 292 params[def][deepDef] = defaults[def][deepDef]; 293 } 294 } 295 } 296 } 297 298 // Swiper 299 var s = this; 300 301 // Params 302 s.params = params; 303 s.originalParams = originalParams; 304 305 // Classname 306 s.classNames = []; 307 /*========================= 308 Dom Library and plugins 309 ===========================*/ 310 if (typeof $ !== 'undefined' && typeof Dom7 !== 'undefined') { 311 $ = Dom7; 312 } 313 if (typeof $ === 'undefined') { 314 if (typeof Dom7 === 'undefined') { 315 $ = window.Dom7 || window.Zepto || window.jQuery; 316 } 317 else { 318 $ = Dom7; 319 } 320 if (!$) return; 321 } 322 // Export it to Swiper instance 323 s.$ = $; 324 325 /*========================= 326 Breakpoints 327 ===========================*/ 328 s.currentBreakpoint = undefined; 329 s.getActiveBreakpoint = function () { 330 //Get breakpoint for window width 331 if (!s.params.breakpoints) return false; 332 var breakpoint = false; 333 var points = [], point; 334 for (point in s.params.breakpoints) { 335 if (s.params.breakpoints.hasOwnProperty(point)) { 336 points.push(point); 337 } 338 } 339 points.sort(function (a, b) { 340 return parseInt(a, 10) > parseInt(b, 10); 341 }); 342 for (var i = 0; i < points.length; i++) { 343 point = points[i]; 344 if (point >= window.innerWidth && !breakpoint) { 345 breakpoint = point; 346 } 347 } 348 return breakpoint || 'max'; 349 }; 350 s.setBreakpoint = function () { 351 //Set breakpoint for window width and update parameters 352 var breakpoint = s.getActiveBreakpoint(); 353 if (breakpoint && s.currentBreakpoint !== breakpoint) { 354 var breakPointsParams = breakpoint in s.params.breakpoints ? s.params.breakpoints[breakpoint] : s.originalParams; 355 var needsReLoop = s.params.loop && (breakPointsParams.slidesPerView !== s.params.slidesPerView); 356 for (var param in breakPointsParams) { 357 s.params[param] = breakPointsParams[param]; 358 } 359 s.currentBreakpoint = breakpoint; 360 if (needsReLoop && s.destroyLoop) { 361 s.reLoop(true); 362 } 363 } 364 }; 365 // Set breakpoint on load 366 if (s.params.breakpoints) { 367 s.setBreakpoint(); 368 } 369 370 /*=========================
371 Preparation - Define Container, Wrapper and Pagination 372 ===========================*/ 373 s.container = $(container); 374 if (s.container.length === 0) return; 375 if (s.container.length > 1) { 376 var swipers = []; 377 s.container.each(function () { 378 var container = this; 379 swipers.push(new Swiper(this, params)); 380 }); 381 return swipers; 382 } 383 384 // Save instance in container HTML Element and in data 385 s.container[0].swiper = s; 386 s.container.data('swiper', s); 387 388 s.classNames.push(s.params.containerModifierClass + s.params.direction); 389 390 if (s.params.freeMode) { 391 s.classNames.push(s.params.containerModifierClass + 'free-mode'); 392 } 393 if (!s.support.flexbox) { 394 s.classNames.push(s.params.containerModifierClass + 'no-flexbox'); 395 s.params.slidesPerColumn = 1; 396 } 397 if (s.params.autoHeight) { 398 s.classNames.push(s.params.containerModifierClass + 'autoheight'); 399 } 400 // Enable slides progress when required 401 if (s.params.parallax || s.params.watchSlidesVisibility) { 402 s.params.watchSlidesProgress = true; 403 } 404 // Max resistance when touchReleaseOnEdges 405 if (s.params.touchReleaseOnEdges) { 406 s.params.resistanceRatio = 0; 407 } 408 // Coverflow / 3D 409 if (['cube', 'coverflow', 'flip'].indexOf(s.params.effect) >= 0) { 410 if (s.support.transforms3d) { 411 s.params.watchSlidesProgress = true; 412 s.classNames.push(s.params.containerModifierClass + '3d'); 413 } 414 else { 415 s.params.effect = 'slide'; 416 } 417 } 418 if (s.params.effect !== 'slide') { 419 s.classNames.push(s.params.containerModifierClass + s.params.effect); 420 } 421 if (s.params.effect === 'cube') { 422 s.params.resistanceRatio = 0; 423 s.params.slidesPerView = 1; 424 s.params.slidesPerColumn = 1; 425 s.params.slidesPerGroup = 1; 426 s.params.centeredSlides = false; 427 s.params.spaceBetween = 0; 428 s.params.virtualTranslate = true; 429 } 430 if (s.params.effect === 'fade' || s.params.effect === 'flip') { 431 s.params.slidesPerView = 1; 432 s.params.slidesPerColumn = 1; 433 s.params.slidesPerGroup = 1; 434 s.params.watchSlidesProgress = true; 435 s.params.spaceBetween = 0; 436 if (typeof initialVirtualTranslate === 'undefined') { 437 s.params.virtualTranslate = true; 438 } 439 } 440 441 // Grab Cursor 442 if (s.params.grabCursor && s.support.touch) { 443 s.params.grabCursor = false; 444 } 445 446 // Wrapper 447 s.wrapper = s.container.children('.' + s.params.wrapperClass); 448 449 // Pagination 450 if (s.params.pagination) { 451 s.paginationContainer = $(s.params.pagination); 452 if (s.params.uniqueNavElements && typeof s.params.pagination === 'string' && s.paginationContainer.length > 1 && s.container.find(s.params.pagination).length === 1) { 453 s.paginationContainer = s.container.find(s.params.pagination); 454 } 455 456 if (s.params.paginationType === 'bullets' && s.params.paginationClickable) { 457 s.paginationContainer.addClass(s.params.paginationModifierClass + 'clickable'); 458 } 459 else { 460 s.params.paginationClickable = false; 461 } 462 s.paginationContainer.addClass(s.params.paginationModifierClass + s.params.paginationType); 463 } 464 // Next/Prev Buttons 465 if (s.params.nextButton || s.params.prevButton) { 466 if (s.params.nextButton) { 467 s.nextButton = $(s.params.nextButton); 468 if (s.params.uniqueNavElements && typeof s.params.nextButton === 'string' && s.nextButton.length > 1 && s.container.find(s.params.nextButton).length === 1) { 469 s.nextButton = s.container.find(s.params.nextButton); 470 } 471 } 472 if (s.params.prevButton) { 473 s.prevButton = $(s.params.prevButton); 474 if (s.params.uniqueNavElements && typeof s.params.prevButton === 'string' && s.prevButton.length > 1 && s.container.find(s.params.prevButton).length === 1) { 475 s.prevButton = s.container.find(s.params.prevButton); 476 } 477 } 478 } 479 480 // Is Horizontal 481 s.isHorizontal = function () { 482 return s.params.direction === 'horizontal'; 483 }; 484 // s.isH = isH; 485 486 // RTL 487 s.rtl = s.isHorizontal() && (s.container[0].dir.toLowerCase() === 'rtl' || s.container.css('direction') === 'rtl'); 488 if (s.rtl) { 489 s.classNames.push(s.params.containerModifierClass + 'rtl'); 490 } 491 492 // Wrong RTL support 493 if (s.rtl) { 494 s.wrongRTL = s.wrapper.css('display') === '-webkit-box'; 495 } 496 497 // Columns 498 if (s.params.slidesPerColumn > 1) { 499 s.classNames.push(s.params.containerModifierClass + 'multirow'); 500 } 501 502 // Check for Android 503 if (s.device.android) { 504 s.classNames.push(s.params.containerModifierClass + 'android'); 505 } 506 507 // Add classes 508 s.container.addClass(s.classNames.join(' ')); 509 510 // Translate 511 s.translate = 0; 512 513 // Progress 514 s.progress = 0; 515 516 // Velocity 517 s.velocity = 0; 518 519 /*========================= 520 Locks, unlocks 521 ===========================*/ 522 s.lockSwipeToNext = function () { 523 s.params.allowSwipeToNext = false;
524 if (s.params.allowSwipeToPrev === false && s.params.grabCursor) { 525 s.unsetGrabCursor(); 526 } 527 }; 528 s.lockSwipeToPrev = function () { 529 s.params.allowSwipeToPrev = false; 530 if (s.params.allowSwipeToNext === false && s.params.grabCursor) { 531 s.unsetGrabCursor(); 532 } 533 }; 534 s.lockSwipes = function () { 535 s.params.allowSwipeToNext = s.params.allowSwipeToPrev = false; 536 if (s.params.grabCursor) s.unsetGrabCursor(); 537 }; 538 s.unlockSwipeToNext = function () { 539 s.params.allowSwipeToNext = true; 540 if (s.params.allowSwipeToPrev === true && s.params.grabCursor) { 541 s.setGrabCursor(); 542 } 543 }; 544 s.unlockSwipeToPrev = function () { 545 s.params.allowSwipeToPrev = true; 546 if (s.params.allowSwipeToNext === true && s.params.grabCursor) { 547 s.setGrabCursor(); 548 } 549 }; 550 s.unlockSwipes = function () { 551 s.params.allowSwipeToNext = s.params.allowSwipeToPrev = true; 552 if (s.params.grabCursor) s.setGrabCursor(); 553 }; 554 555 /*========================= 556 Round helper 557 ===========================*/ 558 function round(a) { 559 return Math.floor(a); 560 } 561 /*========================= 562 Set grab cursor 563 ===========================*/ 564 s.setGrabCursor = function (moving) { 565 s.container[0].style.cursor = 'move'; 566 s.container[0].style.cursor = moving ? '-webkit-grabbing' : '-webkit-grab'; 567 s.container[0].style.cursor = moving ? '-moz-grabbin' : '-moz-grab'; 568 s.container[0].style.cursor = moving ? 'grabbing' : 'grab'; 569 }; 570 s.unsetGrabCursor = function () { 571 s.container[0].style.cursor = ''; 572 }; 573 if (s.params.grabCursor) { 574 s.setGrabCursor(); 575 } 576 /*========================= 577 Update on Images Ready 578 ===========================*/ 579 s.imagesToLoad = []; 580 s.imagesLoaded = 0; 581 582 s.loadImage = function (imgElement, src, srcset, sizes, checkForComplete, callback) { 583 var image; 584 function onReady() { 585 if (callback) callback(); 586 } 587 if (!imgElement.complete || !checkForComplete) { 588 if (src) { 589 image = new window.Image(); 590 image.onload = onReady; 591 image.onerror = onReady; 592 if (sizes) { 593 image.sizes = sizes; 594 } 595 if (srcset) { 596 image.srcset = srcset; 597 } 598 if (src) { 599 image.src = src; 600 } 601 } else { 602 onReady(); 603 } 604 605 } else {//image already loaded... 606 onReady(); 607 } 608 }; 609 s.preloadImages = function () { 610 s.imagesToLoad = s.container.find('img'); 611 function _onReady() { 612 if (typeof s === 'undefined' || s === null || !s) return; 613 if (s.imagesLoaded !== undefined) s.imagesLoaded++; 614 if (s.imagesLoaded === s.imagesToLoad.length) { 615 if (s.params.updateOnImagesReady) s.update(); 616 s.emit('onImagesReady', s); 617 } 618 } 619 for (var i = 0; i < s.imagesToLoad.length; i++) { 620 s.loadImage(s.imagesToLoad[i], (s.imagesToLoad[i].currentSrc || s.imagesToLoad[i].getAttribute('src')), (s.imagesToLoad[i].srcset || s.imagesToLoad[i].getAttribute('srcset')), s.imagesToLoad[i].sizes || s.imagesToLoad[i].getAttribute('sizes'), true, _onReady); 621 } 622 }; 623 624 /*========================= 625 Autoplay 626 ===========================*/ 627 s.autoplayTimeoutId = undefined; 628 s.autoplaying = false; 629 s.autoplayPaused = false; 630 function autoplay() { 631 var autoplayDelay = s.params.autoplay; 632 var activeSlide = s.slides.eq(s.activeIndex); 633 if (activeSlide.attr('data-swiper-autoplay')) { 634 autoplayDelay = activeSlide.attr('data-swiper-autoplay') || s.params.autoplay; 635 } 636 s.autoplayTimeoutId = setTimeout(function () { 637 if (s.params.loop) { 638 s.fixLoop(); 639 s._slideNext(); 640 s.emit('onAutoplay', s); 641 } 642 else { 643 if (!s.isEnd) { 644 s._slideNext(); 645 s.emit('onAutoplay', s); 646 } 647 else { 648 if (!params.autoplayStopOnLast) { 649 s._slideTo(0); 650 s.emit('onAutoplay', s); 651 } 652 else { 653 s.stopAutoplay(); 654 } 655 } 656 } 657 }, autoplayDelay); 658 } 659 s.startAutoplay = function () { 660 if (typeof s.autoplayTimeoutId !== 'undefined') return false;
661 if (!s.params.autoplay) return false; 662 if (s.autoplaying) return false; 663 s.autoplaying = true; 664 s.emit('onAutoplayStart', s); 665 autoplay(); 666 }; 667 s.stopAutoplay = function (internal) { 668 if (!s.autoplayTimeoutId) return; 669 if (s.autoplayTimeoutId) clearTimeout(s.autoplayTimeoutId); 670 s.autoplaying = false; 671 s.autoplayTimeoutId = undefined; 672 s.emit('onAutoplayStop', s); 673 }; 674 s.pauseAutoplay = function (speed) { 675 if (s.autoplayPaused) return; 676 if (s.autoplayTimeoutId) clearTimeout(s.autoplayTimeoutId); 677 s.autoplayPaused = true; 678 if (speed === 0) { 679 s.autoplayPaused = false; 680 autoplay(); 681 } 682 else { 683 s.wrapper.transitionEnd(function () { 684 if (!s) return; 685 s.autoplayPaused = false; 686 if (!s.autoplaying) { 687 s.stopAutoplay(); 688 } 689 else { 690 autoplay(); 691 } 692 }); 693 } 694 }; 695 /*========================= 696 Min/Max Translate 697 ===========================*/ 698 s.minTranslate = function () { 699 return (-s.snapGrid[0]); 700 }; 701 s.maxTranslate = function () { 702 return (-s.snapGrid[s.snapGrid.length - 1]); 703 }; 704 /*========================= 705 Slider/slides sizes 706 ===========================*/ 707 s.updateAutoHeight = function () { 708 var activeSlides = []; 709 var newHeight = 0; 710 var i; 711 712 // Find slides currently in view 713 if (s.params.slidesPerView !== 'auto' && s.params.slidesPerView > 1) { 714 for (i = 0; i < Math.ceil(s.params.slidesPerView); i++) { 715 var index = s.activeIndex + i; 716 if (index > s.slides.length) break; 717 activeSlides.push(s.slides.eq(index)[0]); 718 } 719 } else { 720 activeSlides.push(s.slides.eq(s.activeIndex)[0]); 721 } 722 723 // Find new height from heighest slide in view 724 for (i = 0; i < activeSlides.length; i++) { 725 if (typeof activeSlides[i] !== 'undefined') { 726 var height = activeSlides[i].offsetHeight; 727 newHeight = height > newHeight ? height : newHeight; 728 } 729 } 730 731 // Update Height 732 if (newHeight) s.wrapper.css('height', newHeight + 'px'); 733 }; 734 s.updateContainerSize = function () { 735 var width, height; 736 if (typeof s.params.width !== 'undefined') { 737 width = s.params.width; 738 } 739 else { 740 width = s.container[0].clientWidth; 741 } 742 if (typeof s.params.height !== 'undefined') { 743 height = s.params.height; 744 } 745 else { 746 height = s.container[0].clientHeight; 747 } 748 if (width === 0 && s.isHorizontal() || height === 0 && !s.isHorizontal()) { 749 return; 750 } 751 752 //Subtract paddings 753 width = width - parseInt(s.container.css('padding-left'), 10) - parseInt(s.container.css('padding-right'), 10); 754 height = height - parseInt(s.container.css('padding-top'), 10) - parseInt(s.container.css('padding-bottom'), 10); 755 756 // Store values 757 s.width = width; 758 s.height = height; 759 s.size = s.isHorizontal() ? s.width : s.height; 760 }; 761 762 s.updateSlidesSize = function () { 763 s.slides = s.wrapper.children('.' + s.params.slideClass); 764 s.snapGrid = []; 765 s.slidesGrid = []; 766 s.slidesSizesGrid = []; 767 768 var spaceBetween = s.params.spaceBetween, 769 slidePosition = -s.params.slidesOffsetBefore, 770 i, 771 prevSlideSize = 0, 772 index = 0; 773 if (typeof s.size === 'undefined') return; 774 if (typeof spaceBetween === 'string' && spaceBetween.indexOf('%') >= 0) { 775 spaceBetween = parseFloat(spaceBetween.replace('%', '')) / 100 * s.size; 776 } 777 778 s.virtualSize = -spaceBetween; 779 // reset margins 780 if (s.rtl) s.slides.css({ marginLeft: '', marginTop: '' }); 781 else s.slides.css({ marginRight: '', marginBottom: '' }); 782
783 var slidesNumberEvenToRows; 784 if (s.params.slidesPerColumn > 1) { 785 if (Math.floor(s.slides.length / s.params.slidesPerColumn) === s.slides.length / s.params.slidesPerColumn) { 786 slidesNumberEvenToRows = s.slides.length; 787 } 788 else { 789 slidesNumberEvenToRows = Math.ceil(s.slides.length / s.params.slidesPerColumn) * s.params.slidesPerColumn; 790 } 791 if (s.params.slidesPerView !== 'auto' && s.params.slidesPerColumnFill === 'row') { 792 slidesNumberEvenToRows = Math.max(slidesNumberEvenToRows, s.params.slidesPerView * s.params.slidesPerColumn); 793 } 794 } 795 796 // Calc slides 797 var slideSize; 798 var slidesPerColumn = s.params.slidesPerColumn; 799 var slidesPerRow = slidesNumberEvenToRows / slidesPerColumn; 800 var numFullColumns = slidesPerRow - (s.params.slidesPerColumn * slidesPerRow - s.slides.length); 801 for (i = 0; i < s.slides.length; i++) { 802 slideSize = 0; 803 var slide = s.slides.eq(i); 804 if (s.params.slidesPerColumn > 1) { 805 // Set slides order 806 var newSlideOrderIndex; 807 var column, row; 808 if (s.params.slidesPerColumnFill === 'column') { 809 column = Math.floor(i / slidesPerColumn); 810 row = i - column * slidesPerColumn; 811 if (column > numFullColumns || (column === numFullColumns && row === slidesPerColumn - 1)) { 812 if (++row >= slidesPerColumn) { 813 row = 0; 814 column++; 815 } 816 } 817 newSlideOrderIndex = column + row * slidesNumberEvenToRows / slidesPerColumn; 818 slide 819 .css({ 820 '-webkit-box-ordinal-group': newSlideOrderIndex, 821 '-moz-box-ordinal-group': newSlideOrderIndex, 822 '-ms-flex-order': newSlideOrderIndex, 823 '-webkit-order': newSlideOrderIndex, 824 'order': newSlideOrderIndex 825 }); 826 } 827 else { 828 row = Math.floor(i / slidesPerRow); 829 column = i - row * slidesPerRow; 830 } 831 slide 832 .css( 833 'margin-' + (s.isHorizontal() ? 'top' : 'left'), 834 (row !== 0 && s.params.spaceBetween) && (s.params.spaceBetween + 'px') 835 ) 836 .attr('data-swiper-column', column) 837 .attr('data-swiper-row', row); 838 839 } 840 if (slide.css('display') === 'none') continue; 841 if (s.params.slidesPerView === 'auto') { 842 slideSize = s.isHorizontal() ? slide.outerWidth(true) : slide.outerHeight(true); 843 if (s.params.roundLengths) slideSize = round(slideSize); 844 } 845 else { 846 slideSize = (s.size - (s.params.slidesPerView - 1) * spaceBetween) / s.params.slidesPerView; 847 if (s.params.roundLengths) slideSize = round(slideSize); 848 849 if (s.isHorizontal()) { 850 s.slides[i].style.width = slideSize + 'px'; 851 } 852 else { 853 s.slides[i].style.height = slideSize + 'px'; 854 } 855 } 856 s.slides[i].swiperSlideSize = slideSize; 857 s.slidesSizesGrid.push(slideSize); 858 859 860 if (s.params.centeredSlides) { 861 slidePosition = slidePosition + slideSize / 2 + prevSlideSize / 2 + spaceBetween; 862 if (prevSlideSize === 0 && i !== 0) slidePosition = slidePosition - s.size / 2 - spaceBetween; 863 if (i === 0) slidePosition = slidePosition - s.size / 2 - spaceBetween; 864 if (Math.abs(slidePosition) < 1 / 1000) slidePosition = 0; 865 if ((index) % s.params.slidesPerGroup === 0) s.snapGrid.push(slidePosition); 866 s.slidesGrid.push(slidePosition); 867 } 868 else { 869 if ((index) % s.params.slidesPerGroup === 0) s.snapGrid.push(slidePosition); 870 s.slidesGrid.push(slidePosition); 871 slidePosition = slidePosition + slideSize + spaceBetween; 872 } 873 874 s.virtualSize += slideSize + spaceBetween; 875 876 prevSlideSize = slideSize; 877 878 index++; 879 } 880 s.virtualSize = Math.max(s.virtualSize, s.size) + s.params.slidesOffsetAfter; 881 var newSlidesGrid; 882 883 if ( 884 s.rtl && s.wrongRTL && (s.params.effect === 'slide' || s.params.effect === 'coverflow')) { 885 s.wrapper.css({ width: s.virtualSize + s.params.spaceBetween + 'px' }); 886 } 887 if (!s.support.flexbox || s.params.setWrapperSize) { 888 if (s.isHorizontal()) s.wrapper.css({ width: s.virtualSize + s.params.spaceBetween + 'px' }); 889 else s.wrapper.css({ height: s.virtualSize + s.params.spaceBetween + 'px' }); 890 } 891 892 if (s.params.slidesPerColumn > 1) { 893 s.virtualSize = (slideSize + s.params.spaceBetween) * slidesNumber
893EvenToRows; 894 s.virtualSize = Math.ceil(s.virtualSize / s.params.slidesPerColumn) - s.params.spaceBetween; 895 if (s.isHorizontal()) s.wrapper.css({ width: s.virtualSize + s.params.spaceBetween + 'px' }); 896 else s.wrapper.css({ height: s.virtualSize + s.params.spaceBetween + 'px' }); 897 if (s.params.centeredSlides) { 898 newSlidesGrid = []; 899 for (i = 0; i < s.snapGrid.length; i++) { 900 if (s.snapGrid[i] < s.virtualSize + s.snapGrid[0]) newSlidesGrid.push(s.snapGrid[i]); 901 } 902 s.snapGrid = newSlidesGrid; 903 } 904 } 905 906 // Remove last grid elements depending on width 907 if (!s.params.centeredSlides) { 908 newSlidesGrid = []; 909 for (i = 0; i < s.snapGrid.length; i++) { 910 if (s.snapGrid[i] <= s.virtualSize - s.size) { 911 newSlidesGrid.push(s.snapGrid[i]); 912 } 913 } 914 s.snapGrid = newSlidesGrid; 915 if (Math.floor(s.virtualSize - s.size) - Math.floor(s.snapGrid[s.snapGrid.length - 1]) > 1) { 916 s.snapGrid.push(s.virtualSize - s.size); 917 } 918 } 919 if (s.snapGrid.length === 0) s.snapGrid = [0]; 920 921 if (s.params.spaceBetween !== 0) { 922 if (s.isHorizontal()) { 923 if (s.rtl) s.slides.css({ marginLeft: spaceBetween + 'px' }); 924 else s.slides.css({ marginRight: spaceBetween + 'px' }); 925 } 926 else s.slides.css({ marginBottom: spaceBetween + 'px' }); 927 } 928 if (s.params.watchSlidesProgress) { 929 s.updateSlidesOffset(); 930 } 931 }; 932 s.updateSlidesOffset = function () { 933 for (var i = 0; i < s.slides.length; i++) { 934 s.slides[i].swiperSlideOffset = s.isHorizontal() ? s.slides[i].offsetLeft : s.slides[i].offsetTop; 935 } 936 }; 937 938 /*========================= 939 Dynamic Slides Per View 940 ===========================*/ 941 s.currentSlidesPerView = function () { 942 var spv = 1, i, j; 943 if (s.params.centeredSlides) { 944 var size = s.slides[s.activeIndex].swiperSlideSize; 945 var breakLoop; 946 for (i = s.activeIndex + 1; i < s.slides.length; i++) { 947 if (s.slides[i] && !breakLoop) { 948 size += s.slides[i].swiperSlideSize; 949 spv++; 950 if (size > s.size) breakLoop = true; 951 } 952 } 953 for (j = s.activeIndex - 1; j >= 0; j--) { 954 if (s.slides[j] && !breakLoop) { 955 size += s.slides[j].swiperSlideSize; 956 spv++; 957 if (size > s.size) breakLoop = true; 958 } 959 } 960 } 961 else { 962 for (i = s.activeIndex + 1; i < s.slides.length; i++) { 963 if (s.slidesGrid[i] - s.slidesGrid[s.activeIndex] < s.size) { 964 spv++; 965 } 966 } 967 } 968 return spv; 969 }; 970 /*========================= 971 Slider/slides progress 972 ===========================*/ 973 s.updateSlidesProgress = function (translate) { 974 if (typeof translate === 'undefined') { 975 translate = s.translate || 0; 976 } 977 if (s.slides.length === 0) return; 978 if (typeof s.slides[0].swiperSlideOffset === 'undefined') s.updateSlidesOffset(); 979 980 var offsetCenter = -translate; 981 if (s.rtl) offsetCenter = translate; 982 983 // Visible Slides 984 s.slides.removeClass(s.params.slideVisibleClass); 985 for (var i = 0; i < s.slides.length; i++) { 986 var slide = s.slides[i]; 987 var slideProgress = (offsetCenter + (s.params.centeredSlides ? s.minTranslate() : 0) - slide.swiperSlideOffset) / (slide.swiperSlideSize + s.params.spaceBetween); 988 if (s.params.watchSlidesVisibility) { 989 var slideBefore = -(offsetCenter - slide.swiperSlideOffset); 990 var slideAfter = slideBefore + s.slidesSizesGrid[i]; 991 var isVisible = 992 (slideBefore >= 0 && slideBefore < s.size) || 993 (slideAfter > 0 && slideAfter <= s.size) || 994 (slideBefore <= 0 && slideAfter >= s.size); 995 if (isVisible) { 996 s.slides.eq(i).addClass(s.params.slideVisibleClass); 997 } 998 } 999 slide.progress = s.rtl ? -slideProgress : slideProgress; 1000 } 1001 }; 1002 s.updateProgress = function (translate) { 1003 if (typeof translate === 'undefined') { 1004 translate = s.translate || 0; 1005 } 1006 var translatesDiff = s.maxTranslate() - s.minTranslate(); 1007 var wasBeginning = s.isBeginning; 1008 var wasEnd = s.isEnd; 1009 if (translatesDiff === 0) { 1010 s.progress = 0; 1011 s.isBeginning = s.isEnd = true; 1012 } 1013 else { 1014 s.progress = (translate - s.minTranslate()) / (translatesDiff); 1015 s.isBeginning = s.progress <= 0; 1016 s.isEnd = s.progress >= 1; 1017 } 1018 if (s.isBeginning && !wasBeginning) s.emit('onReachBeginning', s); 1019 if (s.isEnd && !wasEnd) s.emit('onReachEnd', s); 1020 1021 if (s.params.watchSlidesProgress) s.updateSlidesProgress(translate); 1022 s.emit('onProgress', s, s.progress); 1023 }; 1024 s.updateActiveIndex = function () { 1025 var translate = s.rtl ? s.translate : -s.translate; 1026 var newActiveIndex, i, snapIndex; 1027 for (i = 0; i < s.slidesGrid.length; i++) { 1028 if (typeof s.slidesGrid[i + 1] !== 'undefined') { 1029 if (translate >= s.slidesGrid[i] && translate < s.slidesGrid[i + 1] - (s.slidesGrid[i + 1] - s.slidesGrid[i]) / 2) { 1030 newActiveIndex = i; 1031 } 1032 else if (translate >= s.slidesGrid[i] && translate < s.slidesGrid[i + 1]) { 1033 newActiveIndex = i + 1; 1034 } 1035 } 1036 else { 1037 if (translate >= s.slidesGrid[i]) { 1038 newActiveIndex = i; 1039 } 1040 } 1041 } 1042 // Normalize slideIndex 1043 if (s.params.normalizeSlideIndex) { 1044 if (newActiveIndex < 0 || typeof newActiveIndex === 'undefined') newActiveIndex = 0; 1045 } 1046 // for (i = 0; i < s.slidesGrid.length; i++) { 1047 // if (- translate >= s.slidesGrid[i]) { 1048 // newActiveIndex = i; 1049 // } 1050 // } 1051 snapIndex = Math.floor(newActiveIndex / s.params.slidesPerGroup); 1052 if (snapIndex >= s.snapGrid.length) snapIndex = s.snapGrid.length - 1; 1053 1054 if (newActiveIndex === s.activeIndex) { 1055 return; 1056 } 1057 s.snapIndex = snapIndex; 1058 s.previousIndex = s.activeIndex; 1059 s.activeIndex = newActiveIndex; 1060 s.updateClasses(); 1061 s.updateRealIndex(); 1062 }; 1063 s.updateRealIndex = function () { 1064 s.realIndex = parseInt(s.slides.eq(s.activeIndex).attr('data-swiper-slide-index') || s.activeIndex, 10); 1065 }; 1066 1067 /*========================= 1068 Classes 1069 ===========================*/ 1070 s.updateClasses = function () { 1071 s.slides.removeClass(s.params.slideActiveClass + ' ' + s.params.slideNextClass + ' ' + s.params.slidePrevClass + ' ' + s.params.slideDuplicateActiveClass + ' ' + s.params.slideDuplicateNextClass + ' ' + s.params.slideDuplicatePrevClass); 1072 var activeSlide = s.slides.eq(s.activeIndex); 1073 // Active classes 1074 activeSlide.addClass(s.params.slideActiveClass); 1075 if (params.loop) { 1076 // Duplicate to all looped slides 1077 if (activeSlide.hasClass(s.params.slideDuplicateClass)) { 1078 s.wrapper.children('.' + s.params.slideClass + ':not(.' + s.params.slideDuplicateClass + ')[data-swiper-slide-index="' + s.realIndex + '"]').addClass(s.params.slideDuplicateActiveClass); 1079 } 1080 else { 1081 s.wrapper.children('.' + s.params.slideClass + '.' + s.params.slideDuplicateClass + '[data-swiper-slide-index="' + s.realIndex + '"]').addClass(s.params.slideDuplicateActiveClass); 1082 } 1083 } 1084 // Next Slide 1085 var nextSlide = activeSlide.next('.' + s.params.slideClass).addClass(s.params.slideNextClass); 1086 if (s.params.loop && nextSlide.length === 0) { 1087 nextSlide = s.slides.eq(0); 1088 nextSlide.addClass(s.params.slideNextClass); 1089 } 1090 // Prev Slide 1091 var prevSlide = activeSlide.prev('.' + s.params.slideClass).addClass(s.params.slidePrevClass); 1092 if (s.params.loop && prevSlide.length === 0) { 1093 prevSlide = s.slides.eq(-1); 1094 prevSlide.addClass(s.params.slidePrevClass); 1095 } 1096 if (params.loop) { 1097 // Duplicate to all looped slides 1098 if (nextSlide.hasClass(s.params.slideDuplicateClass)) { 1099 s.wrapper.children('.' + s.params.slideClass + ':not(.' + s.params.slideDuplicateClass + ')[data-swiper-slide-index="' + nextSlide.attr('data-swiper-slide-index') + '"]').addClass(s.params.slideDuplicateNextClass); 1100 } 1101 else { 1102 s.wrapper.children('.' + s.params.slideClass + '.' + s.params.slideDuplicateClass + '[data-swiper-slide-index="' + nextSlide.attr('data-swiper-slide-index') + '"]').addClass(s.params.slideDuplicateNextClass); 1103 } 1104 if (prevSlide.hasClass(s.params.slideDuplicateClass)) { 1105 s.wrapper.children('.' + s.params.slideClass + ':not(.' + s.params.slideDuplicateClass + ')[data-swiper-slide-index="' + prevSlide.attr('data-swiper-slide-index') + '"]').addClass(s.params.slideDuplicatePrevClass); 1106 } 1107 else { 1108 s.wrapper.children('.' + s.params.slideClass + '.' + s.params.slideDuplicateClass + '[data-swiper-slide-index="' + prevSlide.attr('data-swiper-slide-index') + '"]').addClass(s.params.slideDuplicatePrevClass); 1109 } 1110 } 1111 1112 // Pagination 1113 if (s.paginationContainer && s.paginationContainer.length > 0) { 1114 // Current/Total 1115 var current, 1116 total = s.params.loop ? Math.ceil((s.slides.length - s.loopedSlides * 2) / s.params.slidesPerGroup) : s.snapGrid.length; 1117 if (s.params.loop) {
1118 current = Math.ceil((s.activeIndex - s.loopedSlides) / s.params.slidesPerGroup); 1119 if (current > s.slides.length - 1 - s.loopedSlides * 2) { 1120 current = current - (s.slides.length - s.loopedSlides * 2); 1121 } 1122 if (current > total - 1) current = current - total; 1123 if (current < 0 && s.params.paginationType !== 'bullets') current = total + current; 1124 } 1125 else { 1126 if (typeof s.snapIndex !== 'undefined') { 1127 current = s.snapIndex; 1128 } 1129 else { 1130 current = s.activeIndex || 0; 1131 } 1132 } 1133 // Types 1134 if (s.params.paginationType === 'bullets' && s.bullets && s.bullets.length > 0) { 1135 s.bullets.removeClass(s.params.bulletActiveClass); 1136 if (s.paginationContainer.length > 1) { 1137 s.bullets.each(function () { 1138 if ($(this).index() === current) $(this).addClass(s.params.bulletActiveClass); 1139 }); 1140 } 1141 else { 1142 s.bullets.eq(current).addClass(s.params.bulletActiveClass); 1143 } 1144 } 1145 if (s.params.paginationType === 'fraction') { 1146 s.paginationContainer.find('.' + s.params.paginationCurrentClass).text(current + 1); 1147 s.paginationContainer.find('.' + s.params.paginationTotalClass).text(total); 1148 } 1149 if (s.params.paginationType === 'progress') { 1150 var scale = (current + 1) / total, 1151 scaleX = scale, 1152 scaleY = 1; 1153 if (!s.isHorizontal()) { 1154 scaleY = scale; 1155 scaleX = 1; 1156 } 1157 s.paginationContainer.find('.' + s.params.paginationProgressbarClass).transform('translate3d(0,0,0) scaleX(' + scaleX + ') scaleY(' + scaleY + ')').transition(s.params.speed); 1158 } 1159 if (s.params.paginationType === 'custom' && s.params.paginationCustomRender) { 1160 s.paginationContainer.html(s.params.paginationCustomRender(s, current + 1, total)); 1161 s.emit('onPaginationRendered', s, s.paginationContainer[0]); 1162 } 1163 } 1164 1165 // Next/active buttons 1166 if (!s.params.loop) { 1167 if (s.params.prevButton && s.prevButton && s.prevButton.length > 0) { 1168 if (s.isBeginning) { 1169 s.prevButton.addClass(s.params.buttonDisabledClass); 1170 if (s.params.a11y && s.a11y) s.a11y.disable(s.prevButton); 1171 } 1172 else { 1173 s.prevButton.removeClass(s.params.buttonDisabledClass); 1174 if (s.params.a11y && s.a11y) s.a11y.enable(s.prevButton); 1175 } 1176 } 1177 if (s.params.nextButton && s.nextButton && s.nextButton.length > 0) { 1178 if (s.isEnd) { 1179 s.nextButton.addClass(s.params.buttonDisabledClass); 1180 if (s.params.a11y && s.a11y) s.a11y.disable(s.nextButton); 1181 } 1182 else { 1183 s.nextButton.removeClass(s.params.buttonDisabledClass); 1184 if (s.params.a11y && s.a11y) s.a11y.enable(s.nextButton); 1185 } 1186 } 1187 } 1188 }; 1189 1190 /*========================= 1191 Pagination 1192 ===========================*/ 1193 s.updatePagination = function () { 1194 if (!s.params.pagination) return; 1195 if (s.paginationContainer && s.paginationContainer.length > 0) { 1196 var paginationHTML = ''; 1197 if (s.params.paginationType === 'bullets') { 1198 var numberOfBullets = s.params.loop ? Math.ceil((s.slides.length - s.loopedSlides * 2) / s.params.slidesPerGroup) : s.snapGrid.length; 1199 for (var i = 0; i < numberOfBullets; i++) { 1200 if (s.params.paginationBulletRender) { 1201 paginationHTML += s.params.paginationBulletRender(s, i, s.params.bulletClass); 1202 } 1203 else { 1204 paginationHTML += '<' + s.params.paginationElement + ' class="' + s.params.bulletClass + '"></' + s.params.paginationElement + '>'; 1205 } 1206 } 1207 s.paginationContainer.html(paginationHTML); 1208 s.bullets = s.paginationContainer.find('.' + s.params.bulletClass); 1209 if (s.params.paginationClickable && s.params.a11y && s.a11y) { 1210 s.a11y.initPagination(); 1211 } 1212 } 1213 if (s.params.paginationType === 'fraction') { 1214 if (s.params.paginationFractionRender) { 1215 paginationHTML = s.params.paginationFractionRender(s, s.params.paginationCurrentClass, s.params.paginationTotalClass); 1216 } 1217 else { 1218 paginationHTML = 1219 '<span class="' + s.params.paginationCurrentClass + '"></span>' + 1220 ' / ' + 1221 '<span class="' + s.params.paginationTotalClass + '"></span>'; 1222 } 1223 s.paginationContainer.html(paginationHTML); 1224 } 1225 if (s.params.paginationType === 'progress') { 1226 if (s.params.paginationProgressRender) { 1227 paginationHTML = s.params.paginationProgressRender(s, s.params.paginationProgressbarClass); 1228 } 1229 else { 1230 paginationHTML = '<span class="' + s.params.paginationProgressbarClass + '"></span>'; 1231 } 1232 s.paginationContainer.html(paginationHTML); 1233 } 1234 if (s.params.paginationType !== 'custom') { 1235 s.emit('onPaginationRendered', s, s.paginationContainer[0]); 1236 } 1237 } 1238 }; 1239 /*========================= 1240 Common update method 1241 ===========================*/ 1242 s.update = function (updateTranslate) { 1243 if (!s) return; 1244 s.updateContainerSize(); 1245 s.updateSlidesSize(); 1246 s.updateProgress(); 1247 s.updatePagination(); 1248 s.updateClasses(); 1249 if (s.params.scrollbar && s.scrollbar) { 1250 s.scrollbar.set(); 1251 } 1252 var newTranslate; 1253 function forceSetTranslate() { 1254 var translate = s.rtl ? -s.translate : s.translate; 1255 newTranslate = Math.min(Math.max(s.translate, s.maxTranslate()), s.minTranslate()); 1256 s.setWrapperTranslate(newTranslate); 1257 s.updateActiveIndex(); 1258 s.updateClasses(); 1259 } 1260 if (updateTranslate) { 1261 var translated; 1262 if (s.controller && s.controller.spline) { 1263 s.controller.spline = undefined; 1264 } 1265 if (s.params.freeMode) { 1266 forceSetTranslate(); 1267 if (s.params.autoHeight) { 1268 s.updateAutoHeight(); 1269 } 1270 } 1271 else { 1272 if ((s.params.slidesPerView === 'auto' || s.params.slidesPerView > 1) && s.isEnd && !s.params.centeredSlides) { 1273 translated = s.slideTo(s.slides.length - 1, 0, false, true); 1274 } 1275 else { 1276 translated = s.slideTo(s.activeIndex, 0, false, true); 1277 } 1278 if (!translated) { 1279 forceSetTranslate(); 1280 } 1281 } 1282 } 1283 else if (s.params.autoHeight) { 1284 s.updateAutoHeight(); 1285 } 1286 }; 1287 1288 /*========================= 1289 Resize Handler 1290 ===========================*/ 1291 s.onResize = function (forceUpdatePagination) { 1292 if (s.params.onBeforeResize) s.params.onBeforeResize(s); 1293 //Breakpoints 1294 if (s.params.breakpoints) { 1295 s.setBreakpoint(); 1296 } 1297 1298 // Disable locks on resize 1299 var allowSwipeToPrev = s.params.allowSwipeToPrev; 1300 var allowSwipeToNext = s.params.allowSwipeToNext; 1301 s.params.allowSwipeToPrev = s.params.allowSwipeToNext = true; 1302 1303 s.updateContainerSize(); 1304 s.updateSlidesSize(); 1305 if (s.params.slidesPerView === 'auto' || s.params.freeMode || force
1305UpdatePagination) s.updatePagination(); 1306 if (s.params.scrollbar && s.scrollbar) { 1307 s.scrollbar.set(); 1308 } 1309 if (s.controller && s.controller.spline) { 1310 s.controller.spline = undefined; 1311 } 1312 var slideChangedBySlideTo = false; 1313 if (s.params.freeMode) { 1314 var newTranslate = Math.min(Math.max(s.translate, s.maxTranslate()), s.minTranslate()); 1315 s.setWrapperTranslate(newTranslate); 1316 s.updateActiveIndex(); 1317 s.updateClasses(); 1318 1319 if (s.params.autoHeight) { 1320 s.updateAutoHeight(); 1321 } 1322 } 1323 else { 1324 s.updateClasses(); 1325 if ((s.params.slidesPerView === 'auto' || s.params.slidesPerView > 1) && s.isEnd && !s.params.centeredSlides) { 1326 slideChangedBySlideTo = s.slideTo(s.slides.length - 1, 0, false, true); 1327 } 1328 else { 1329 slideChangedBySlideTo = s.slideTo(s.activeIndex, 0, false, true); 1330 } 1331 } 1332 if (s.params.lazyLoading && !slideChangedBySlideTo && s.lazy) { 1333 s.lazy.load(); 1334 } 1335 // Return locks after resize 1336 s.params.allowSwipeToPrev = allowSwipeToPrev; 1337 s.params.allowSwipeToNext = allowSwipeToNext; 1338 if (s.params.onAfterResize) s.params.onAfterResize(s); 1339 }; 1340 1341 /*========================= 1342 Events 1343 ===========================*/ 1344 1345 //Define Touch Events 1346 s.touchEventsDesktop = { start: 'mousedown', move: 'mousemove', end: 'mouseup' }; 1347 if (window.navigator.pointerEnabled) s.touchEventsDesktop = { start: 'pointerdown', move: 'pointermove', end: 'pointerup' }; 1348 else if (window.navigator.msPointerEnabled) s.touchEventsDesktop = { start: 'MSPointerDown', move: 'MSPointerMove', end: 'MSPointerUp' }; 1349 s.touchEvents = { 1350 start: s.support.touch || !s.params.simulateTouch ? 'touchstart' : s.touchEventsDesktop.start, 1351 move: s.support.touch || !s.params.simulateTouch ? 'touchmove' : s.touchEventsDesktop.move, 1352 end: s.support.touch || !s.params.simulateTouch ? 'touchend' : s.touchEventsDesktop.end 1353 }; 1354 1355 1356 // WP8 Touch Events Fix 1357 if (window.navigator.pointerEnabled || window.navigator.msPointerEnabled) { 1358 (s.params.touchEventsTarget === 'container' ? s.container : s.wrapper).addClass('swiper-wp8-' + s.params.direction); 1359 } 1360 1361 // Attach/detach events 1362 s.initEvents = function (detach) { 1363 var actionDom = detach ? 'off' : 'on'; 1364 var action = detach ? 'removeEventListener' : 'addEventListener'; 1365 var touchEventsTarget = s.params.touchEventsTarget === 'container' ? s.container[0] : s.wrapper[0]; 1366 var target = s.support.touch ? touchEventsTarget : document; 1367 1368 var moveCapture = s.params.nested ? true : false; 1369 1370 //Touch Events 1371 if (s.browser.ie) { 1372 touchEventsTarget[action](s.touchEvents.start, s.onTouchStart, false); 1373 target[action](s.touchEvents.move, s.onTouchMove, moveCapture); 1374 target[action](s.touchEvents.end, s.onTouchEnd, false); 1375 } 1376 else { 1377 if (s.support.touch) { 1378 var passiveListener = s.touchEvents.start === 'touchstart' && s.support.passiveListener && s.params.passiveListeners ? { passive: true, capture: false } : false; 1379 touchEventsTarget[action](s.touchEvents.start, s.onTouchStart, passiveListener); 1380 touchEventsTarget[action](s.touchEvents.move, s.onTouchMove, moveCapture); 1381 touchEventsTarget[action](s.touchEvents.end, s.onTouchEnd, passiveListener); 1382 } 1383 if ((params.simulateTouch && !s.device.ios && !s.device.android) || (params.simulateTouch && !s.support.touch && s.device.ios)) { 1384 touchEventsTarget[action]('mousedown', s.onTouchStart, false); 1385 document[action]('mousemove', s.onTouchMove, moveCapture); 1386 document[action]('mouseup', s.onTouchEnd, false); 1387 } 1388 } 1389 window[action]('resize', s.onResize); 1390 1391 // Next, Prev, Index 1392 if (s.params.nextButton && s.nextButton && s.nextButton.length > 0) { 1393 s.nextButton[actionDom]('click', s.onClickNext); 1394 if (s.params.a11y && s.a11y) s.nextButton[actionDom]('keydown', s.a11y.onEnterKey); 1395 } 1396 if (s.params.prevButton && s.prevButton && s.prevButton.length > 0) { 1397 s.prevButton[actionDom]('click', s.onClickPrev); 1398 if (s.params.a11y && s.a11y) s.prevButton[actionDom]('keydown', s.a11y.onEnterKey); 1399 } 1400 if (s.params.pagination && s.params.paginationClickable) { 1401 s.paginationContainer[actionDom]('click', '.' + s.params.bulletClass, s.onClickIndex); 1402 if (s.params.a11y && s.a11y) s.paginationContainer[actionDom]('keydown', '.' + s.params.bulletClass, s.a11y.onEnterKey); 1403 } 1404 1405 // Prevent Links Clicks 1406 if (s.params.preventClicks || s.params.preventClicksPropagation) touchEventsTarget[action]('click', s.preventClicks, true); 1407 }; 1408 s.attachEvents = function () { 1409 s.initEvents(); 1410 }; 1411 s.detachEvents = function () { 1412 s.initEvents(true); 1413 }; 1414 1415 /*========================= 1416 Handle Clicks 1417 ===========================*/ 1418 // Prevent Clicks 1419 s.allowClick = true; 1420 s.preventClicks = function (e) { 1421 if (!s.allowClick) { 1422 if (s.params.preventClicks) e.preventDefault(); 1423 if (s.params.preventClicksPropagation && s.animating) { 1424 e.stopPropagation(); 1425 e.stopImmediatePropagation(); 1426 } 1427 } 1428 }; 1429 // Clicks 1430 s.onClickNext = function (e) { 1431 e.preventDefault(); 1432 if (s.isEnd && !s.params.loop) return; 1433 s.slideNext(); 1434 }; 1435 s.onClickPrev = function (e) { 1436 e.preventDefault(); 1437 if (s.isBeginning && !s.params.loop) return; 1438 s.slidePrev(); 1439 }; 1440 s.onClickIndex = function (e) { 1441 e.preventDefault(); 1442 var index = $(this).index() * s.params.slidesPerGroup; 1443 if (s.params.loop) index = index + s.loopedSlides; 1444 s.slideTo(index); 1445 }; 1446 1447 /*========================= 1448 Handle Touches 1449 ===========================*/ 1450 function findElementInEvent(e, selector) { 1451 var el = $(e.target); 1452 if (!el.is(selector)) { 1453 if (typeof selector === 'string') { 1454 el = el.parents(selector); 1455 } 1456 else if (selector.nodeType) { 1457 var found; 1458 el.parents().each(function (index, _el) { 1459 if (_el === selector) found = selector; 1460 }); 1461 if (!found) return undefined; 1462 else return selector; 1463 } 1464 } 1465 if (el.length === 0) { 1466 return undefined; 1467 } 1468 return el[0]; 1469 } 1470 s.updateClickedSlide = function (e) { 1471 var slide = findElementInEvent(e, '.' + s.params.slideClass); 1472 var slideFound = false;
1473 if (slide) { 1474 for (var i = 0; i < s.slides.length; i++) { 1475 if (s.slides[i] === slide) slideFound = true; 1476 } 1477 } 1478 1479 if (slide && slideFound) { 1480 s.clickedSlide = slide; 1481 s.clickedIndex = $(slide).index(); 1482 } 1483 else { 1484 s.clickedSlide = undefined; 1485 s.clickedIndex = undefined; 1486 return; 1487 } 1488 if (s.params.slideToClickedSlide && s.clickedIndex !== undefined && s.clickedIndex !== s.activeIndex) { 1489 var slideToIndex = s.clickedIndex, 1490 realIndex, 1491 duplicatedSlides, 1492 slidesPerView = s.params.slidesPerView === 'auto' ? s.currentSlidesPerView() : s.params.slidesPerView; 1493 if (s.params.loop) { 1494 if (s.animating) return; 1495 realIndex = parseInt($(s.clickedSlide).attr('data-swiper-slide-index'), 10); 1496 if (s.params.centeredSlides) { 1497 if ((slideToIndex < s.loopedSlides - slidesPerView / 2) || (slideToIndex > s.slides.length - s.loopedSlides + slidesPerView / 2)) { 1498 s.fixLoop(); 1499 slideToIndex = s.wrapper.children('.' + s.params.slideClass + '[data-swiper-slide-index="' + realIndex + '"]:not(.' + s.params.slideDuplicateClass + ')').eq(0).index(); 1500 setTimeout(function () { 1501 s.slideTo(slideToIndex); 1502 }, 0); 1503 } 1504 else { 1505 s.slideTo(slideToIndex); 1506 } 1507 } 1508 else { 1509 if (slideToIndex > s.slides.length - slidesPerView) { 1510 s.fixLoop(); 1511 slideToIndex = s.wrapper.children('.' + s.params.slideClass + '[data-swiper-slide-index="' + realIndex + '"]:not(.' + s.params.slideDuplicateClass + ')').eq(0).index(); 1512 setTimeout(function () { 1513 s.slideTo(slideToIndex); 1514 }, 0); 1515 } 1516 else { 1517 s.slideTo(slideToIndex); 1518 } 1519 } 1520 } 1521 else { 1522 s.slideTo(slideToIndex); 1523 } 1524 } 1525 }; 1526 1527 var isTouched, 1528 isMoved, 1529 allowTouchCallbacks, 1530 touchStartTime, 1531 isScrolling, 1532 currentTranslate, 1533 startTranslate, 1534 allowThresholdMove, 1535 // Form elements to match 1536 formElements = 'input, select, textarea, button, video', 1537 // Last click time 1538 lastClickTime = Date.now(), clickTimeout, 1539 //Velocities 1540 velocities = [], 1541 allowMomentumBounce; 1542 1543 // Animating Flag 1544 s.animating = false; 1545 1546 // Touches information 1547 s.touches = { 1548 startX: 0, 1549 startY: 0, 1550 currentX: 0, 1551 currentY: 0, 1552 diff: 0 1553 }; 1554 1555 // Touch handlers 1556 var isTouchEvent, startMoving; 1557 s.onTouchStart = function (e) { 1558 if (e.originalEvent) e = e.originalEvent; 1559 isTouchEvent = e.type === 'touchstart'; 1560 if (!isTouchEvent && 'which' in e && e.which === 3) return; 1561 if (s.params.noSwiping && findElementInEvent(e, '.' + s.params.noSwipingClass)) { 1562 s.allowClick = true; 1563 return; 1564 } 1565 if (s.params.swipeHandler) { 1566 if (!findElementInEvent(e, s.params.swipeHandler)) return; 1567 } 1568 1569 var startX = s.touches.currentX = e.type === 'touchstart' ? e.targetTouches[0].pageX : e.pageX; 1570 var startY = s.touches.currentY = e.type === 'touchstart' ? e.targetTouches[0].pageY : e.pageY; 1571 1572 // Do NOT start if iOS edge swipe is detected. Otherwise iOS app (UIWebView) cannot swipe-to-go-back anymore 1573 if (s.device.ios && s.params.iOSEdgeSwipeDetection && startX <= s.params.iOSEdgeSwipeThreshold) { 1574 return; 1575 } 1576 1577 isTouched = true; 1578 isMoved = false;
1579 allowTouchCallbacks = true; 1580 isScrolling = undefined; 1581 startMoving = undefined; 1582 s.touches.startX = startX; 1583 s.touches.startY = startY; 1584 touchStartTime = Date.now(); 1585 s.allowClick = true; 1586 s.updateContainerSize(); 1587 s.swipeDirection = undefined; 1588 if (s.params.threshold > 0) allowThresholdMove = false; 1589 if (e.type !== 'touchstart') { 1590 var preventDefault = true; 1591 if ($(e.target).is(formElements)) preventDefault = false; 1592 if (document.activeElement && $(document.activeElement).is(formElements)) { 1593 document.activeElement.blur(); 1594 } 1595 if (preventDefault) { 1596 e.preventDefault(); 1597 } 1598 } 1599 s.emit('onTouchStart', s, e); 1600 }; 1601 1602 s.onTouchMove = function (e) { 1603 if (e.originalEvent) e = e.originalEvent; 1604 if (isTouchEvent && e.type === 'mousemove') return; 1605 if (e.preventedByNestedSwiper) { 1606 s.touches.startX = e.type === 'touchmove' ? e.targetTouches[0].pageX : e.pageX; 1607 s.touches.startY = e.type === 'touchmove' ? e.targetTouches[0].pageY : e.pageY; 1608 return; 1609 } 1610 if (s.params.onlyExternal) { 1611 // isMoved = true; 1612 s.allowClick = false; 1613 if (isTouched) { 1614 s.touches.startX = s.touches.currentX = e.type === 'touchmove' ? e.targetTouches[0].pageX : e.pageX; 1615 s.touches.startY = s.touches.currentY = e.type === 'touchmove' ? e.targetTouches[0].pageY : e.pageY; 1616 touchStartTime = Date.now(); 1617 } 1618 return; 1619 } 1620 if (isTouchEvent && s.params.touchReleaseOnEdges && !s.params.loop) { 1621 if (!s.isHorizontal()) { 1622 // Vertical 1623 if ( 1624 (s.touches.currentY < s.touches.startY && s.translate <= s.maxTranslate()) || 1625 (s.touches.currentY > s.touches.startY && s.translate >= s.minTranslate()) 1626 ) { 1627 return; 1628 } 1629 } 1630 else { 1631 if ( 1632 (s.touches.currentX < s.touches.startX && s.translate <= s.maxTranslate()) || 1633 (s.touches.currentX > s.touches.startX && s.translate >= s.minTranslate()) 1634 ) { 1635 return; 1636 } 1637 } 1638 } 1639 if (isTouchEvent && document.activeElement) { 1640 if (e.target === document.activeElement && $(e.target).is(formElements)) { 1641 isMoved = true; 1642 s.allowClick = false; 1643 return; 1644 } 1645 } 1646 if (allowTouchCallbacks) { 1647 s.emit('onTouchMove', s, e); 1648 } 1649 if (e.targetTouches && e.targetTouches.length > 1) return; 1650 1651 s.touches.currentX = e.type === 'touchmove' ? e.targetTouches[0].pageX : e.pageX; 1652 s.touches.currentY = e.type === 'touchmove' ? e.targetTouches[0].pageY : e.pageY; 1653 1654 if (typeof isScrolling === 'undefined') { 1655 var touchAngle; 1656 if (s.isHorizontal() && s.touches.currentY === s.touches.startY || !s.isHorizontal() && s.touches.currentX === s.touches.startX) { 1657 isScrolling = false; 1658 } 1659 else { 1660 touchAngle = Math.atan2(Math.abs(s.touches.currentY - s.touches.startY), Math.abs(s.touches.currentX - s.touches.startX)) * 180 / Math.PI; 1661 isScrolling = s.isHorizontal() ? touchAngle > s.params.touchAngle : (90 - touchAngle > s.params.touchAngle); 1662 } 1663 } 1664 if (isScrolling) { 1665 s.emit('onTouchMoveOpposite', s, e); 1666 } 1667 if (typeof startMoving === 'undefined') { 1668 if (s.touches.currentX !== s.touches.startX || s.touches.currentY !== s.touches.startY) { 1669 startMoving = true; 1670 } 1671 } 1672 if (!isTouched) return; 1673 if (isScrolling) { 1674 isTouched = false;
1675 return; 1676 } 1677 if (!startMoving) { 1678 return; 1679 } 1680 s.allowClick = false; 1681 s.emit('onSliderMove', s, e); 1682 e.preventDefault(); 1683 if (s.params.touchMoveStopPropagation && !s.params.nested) { 1684 e.stopPropagation(); 1685 } 1686 1687 if (!isMoved) { 1688 if (params.loop) { 1689 s.fixLoop(); 1690 } 1691 startTranslate = s.getWrapperTranslate(); 1692 s.setWrapperTransition(0); 1693 if (s.animating) { 1694 s.wrapper.trigger('webkitTransitionEnd transitionend oTransitionEnd MSTransitionEnd msTransitionEnd'); 1695 } 1696 if (s.params.autoplay && s.autoplaying) { 1697 if (s.params.autoplayDisableOnInteraction) { 1698 s.stopAutoplay(); 1699 } 1700 else { 1701 s.pauseAutoplay(); 1702 } 1703 } 1704 allowMomentumBounce = false; 1705 //Grab Cursor 1706 if (s.params.grabCursor && (s.params.allowSwipeToNext === true || s.params.allowSwipeToPrev === true)) { 1707 s.setGrabCursor(true); 1708 } 1709 } 1710 isMoved = true; 1711 1712 var diff = s.touches.diff = s.isHorizontal() ? s.touches.currentX - s.touches.startX : s.touches.currentY - s.touches.startY; 1713 1714 diff = diff * s.params.touchRatio; 1715 if (s.rtl) diff = -diff; 1716 1717 s.swipeDirection = diff > 0 ? 'prev' : 'next'; 1718 currentTranslate = diff + startTranslate; 1719 1720 var disableParentSwiper = true; 1721 if ((diff > 0 && currentTranslate > s.minTranslate())) { 1722 disableParentSwiper = false;
1723 if (s.params.resistance) currentTranslate = s.minTranslate() - 1 + Math.pow(-s.minTranslate() + startTranslate + diff, s.params.resistanceRatio); 1724 } 1725 else if (diff < 0 && currentTranslate < s.maxTranslate()) { 1726 disableParentSwiper = false; 1727 if (s.params.resistance) currentTranslate = s.maxTranslate() + 1 - Math.pow(s.maxTranslate() - startTranslate - diff, s.params.resistanceRatio); 1728 } 1729 1730 if (disableParentSwiper) { 1731 e.preventedByNestedSwiper = true; 1732 } 1733 1734 // Directions locks 1735 if (!s.params.allowSwipeToNext && s.swipeDirection === 'next' && currentTranslate < startTranslate) { 1736 currentTranslate = startTranslate; 1737 } 1738 if (!s.params.allowSwipeToPrev && s.swipeDirection === 'prev' && currentTranslate > startTranslate) { 1739 currentTranslate = startTranslate; 1740 } 1741 1742 1743 // Threshold 1744 if (s.params.threshold > 0) { 1745 if (Math.abs(diff) > s.params.threshold || allowThresholdMove) { 1746 if (!allowThresholdMove) { 1747 allowThresholdMove = true; 1748 s.touches.startX = s.touches.currentX; 1749 s.touches.startY = s.touches.currentY; 1750 currentTranslate = startTranslate; 1751 s.touches.diff = s.isHorizontal() ? s.touches.currentX - s.touches.startX : s.touches.currentY - s.touches.startY; 1752 return; 1753 } 1754 } 1755 else { 1756 currentTranslate = startTranslate; 1757 return; 1758 } 1759 } 1760 1761 if (!s.params.followFinger) return; 1762 1763 // Update active index in free mode 1764 if (s.params.freeMode || s.params.watchSlidesProgress) { 1765 s.updateActiveIndex(); 1766 } 1767 if (s.params.freeMode) { 1768 //Velocity 1769 if (velocities.length === 0) { 1770 velocities.push({ 1771 position: s.touches[s.isHorizontal() ? 'startX' : 'startY'], 1772 time: touchStartTime 1773 }); 1774 } 1775 velocities.push({ 1776 position: s.touches[s.isHorizontal() ? 'currentX' : 'currentY'], 1777 time: (new window.Date()).getTime() 1778 }); 1779 } 1780 // Update progress 1781 s.updateProgress(currentTranslate); 1782 // Update translate 1783 s.setWrapperTranslate(currentTranslate); 1784 }; 1785 s.onTouchEnd = function (e) { 1786 if (e.originalEvent) e = e.originalEvent; 1787 if (allowTouchCallbacks) { 1788 s.emit('onTouchEnd', s, e); 1789 } 1790 allowTouchCallbacks = false; 1791 if (!isTouched) return; 1792 //Return Grab Cursor 1793 if (s.params.grabCursor && isMoved && isTouched && (s.params.allowSwipeToNext === true || s.params.allowSwipeToPrev === true)) { 1794 s.setGrabCursor(false); 1795 } 1796 1797 // Time diff 1798 var touchEndTime = Date.now(); 1799 var timeDiff = touchEndTime - touchStartTime; 1800 1801 // Tap, doubleTap, Click 1802 if (s.allowClick) { 1803 s.updateClickedSlide(e); 1804 s.emit('onTap', s, e); 1805 if (timeDiff < 300 && (touchEndTime - lastClickTime) > 300) { 1806 if (clickTimeout) clearTimeout(clickTimeout); 1807 clickTimeout = setTimeout(function () { 1808 if (!s) return; 1809 if (s.params.paginationHide && s.paginationContainer.length > 0 && !$(e.target).hasClass(s.params.bulletClass)) { 1810 s.paginationContainer.toggleClass(s.params.paginationHiddenClass); 1811 } 1812 s.emit('onClick', s, e); 1813 }, 300); 1814 1815 } 1816 if (timeDiff < 300 && (touchEndTime - lastClickTime) < 300) { 1817 if (clickTimeout) clearTimeout(clickTimeout); 1818 s.emit('onDoubleTap', s, e); 1819 } 1820 } 1821 1822 lastClickTime = Date.now(); 1823 setTimeout(function () { 1824 if (s) s.allowClick = true; 1825 }, 0); 1826 1827 if (!isTouched || !isMoved || !s.swipeDirection || s.touches.diff === 0 || currentTranslate === startTranslate) { 1828 isTouched = isMoved = false;
1829 return; 1830 } 1831 isTouched = isMoved = false; 1832 1833 var currentPos; 1834 if (s.params.followFinger) { 1835 currentPos = s.rtl ? s.translate : -s.translate; 1836 } 1837 else { 1838 currentPos = -currentTranslate; 1839 } 1840 if (s.params.freeMode) { 1841 if (currentPos < -s.minTranslate()) { 1842 s.slideTo(s.activeIndex); 1843 return; 1844 } 1845 else if (currentPos > -s.maxTranslate()) { 1846 if (s.slides.length < s.snapGrid.length) { 1847 s.slideTo(s.snapGrid.length - 1); 1848 } 1849 else { 1850 s.slideTo(s.slides.length - 1); 1851 } 1852 return; 1853 } 1854 1855 if (s.params.freeModeMomentum) { 1856 if (velocities.length > 1) { 1857 var lastMoveEvent = velocities.pop(), velocityEvent = velocities.pop(); 1858 1859 var distance = lastMoveEvent.position - velocityEvent.position; 1860 var time = lastMoveEvent.time - velocityEvent.time; 1861 s.velocity = distance / time; 1862 s.velocity = s.velocity / 2; 1863 if (Math.abs(s.velocity) < s.params.freeModeMinimumVelocity) { 1864 s.velocity = 0; 1865 } 1866 // this implies that the user stopped moving a finger then released. 1867 // There would be no events with distance zero, so the last event is stale. 1868 if (time > 150 || (new window.Date().getTime() - lastMoveEvent.time) > 300) { 1869 s.velocity = 0; 1870 } 1871 } else { 1872 s.velocity = 0; 1873 } 1874 s.velocity = s.velocity * s.params.freeModeMomentumVelocityRatio; 1875 1876 velocities.length = 0; 1877 var momentumDuration = 1000 * s.params.freeModeMomentumRatio; 1878 var momentumDistance = s.velocity * momentumDuration; 1879 1880 var newPosition = s.translate + momentumDistance; 1881 if (s.rtl) newPosition = - newPosition; 1882 var doBounce = false; 1883 var afterBouncePosition; 1884 var bounceAmount = Math.abs(s.velocity) * 20 * s.params.freeModeMomentumBounceRatio; 1885 if (newPosition < s.maxTranslate()) { 1886 if (s.params.freeModeMomentumBounce) { 1887 if (newPosition + s.maxTranslate() < -bounceAmount) { 1888 newPosition = s.maxTranslate() - bounceAmount; 1889 } 1890 afterBouncePosition = s.maxTranslate(); 1891 doBounce = true; 1892 allowMomentumBounce = true; 1893 } 1894 else { 1895 newPosition = s.maxTranslate(); 1896 } 1897 } 1898 else if (newPosition > s.minTranslate()) { 1899 if (s.params.freeModeMomentumBounce) { 1900 if (newPosition - s.minTranslate() > bounceAmount) { 1901 newPosition = s.minTranslate() + bounceAmount; 1902 } 1903 afterBouncePosition = s.minTranslate(); 1904 doBounce = true; 1905 allowMomentumBounce = true; 1906 } 1907 else { 1908 newPosition = s.minTranslate(); 1909 } 1910 } 1911 else if (s.params.freeModeSticky) { 1912 var j = 0, 1913 nextSlide; 1914 for (j = 0; j < s.snapGrid.length; j += 1) { 1915 if (s.snapGrid[j] > -newPosition) { 1916 nextSlide = j; 1917 break; 1918 } 1919 1920 } 1921 if (Math.abs(s.snapGrid[nextSlide] - newPosition) < Math.abs(s.snapGrid[nextSlide - 1] - newPosition) || s.swipeDirection === 'next') { 1922 newPosition = s.snapGrid[nextSlide]; 1923 } else { 1924 newPosition = s.snapGrid[nextSlide - 1]; 1925 } 1926 if (!s.rtl) newPosition = - newPosition; 1927 } 1928 //Fix duration 1929 if (s.velocity !== 0) { 1930 if (s.rtl) { 1931 momentumDuration = Math.abs((-newPosition - s.translate) / s.velocity); 1932 } 1933 else { 1934 momentumDuration = Math.abs((newPosition - s.translate) / s.velocity); 1935 } 1936 } 1937 else if (s.params.freeModeSticky) { 1938 s.slideReset(); 1939 return; 1940 } 1941 1942 if (s.params.freeModeMomentumBounce && doBounce) { 1943 s.updateProgress(afterBouncePosition); 1944 s.setWrapperTransition(momentumDuration); 1945 s.setWrapperTranslate(newPosition); 1946 s.onTransitionStart(); 1947 s.animating = true; 1948 s.wrapper.transitionEnd(function () { 1949 if (!s || !allowMomentumBounce) return; 1950 s.emit('onMomentumBounce', s); 1951 1952 s.setWrapperTransition(s.params.speed); 1953 s.setWrapperTranslate(afterBouncePosition); 1954 s.wrapper.transitionEnd(function () { 1955 if (!s) return; 1956 s.onTransitionEnd(); 1957 }); 1958 }); 1959 } else if (s.velocity) { 1960 s.updateProgress(newPosition); 1961 s.setWrapperTransition(momentumDuration); 1962 s.setWrapperTranslate(newPosition); 1963 s.onTransitionStart(); 1964 if (!s.animating) { 1965 s.animating = true; 1966 s.wrapper.transitionEnd(function () { 1967 if (!s) return; 1968 s.onTransitionEnd(); 1969 }); 1970 } 1971 1972 } else { 1973 s.updateProgress(newPosition); 1974 } 1975 1976 s.updateActiveIndex(); 1977 } 1978 if (!s.params.freeModeMomentum || timeDiff >= s.params.longSwipesMs) { 1979 s.updateProgress(); 1980 s.updateActiveIndex(); 1981 } 1982 return; 1983 } 1984 1985 // Find current slide 1986 var i, stopIndex = 0, groupSize = s.slidesSizesGrid[0]; 1987 for (i = 0; i < s.slidesGrid.length; i += s.params.slidesPerGroup) { 1988 if (typeof s.slidesGrid[i + s.params.slidesPerGroup] !== 'undefined') { 1989 if (currentPos >= s.slidesGrid[i] && currentPos < s.slidesGrid[i + s.params.slidesPerGroup]) { 1990 stopIndex = i; 1991 groupSize = s.slidesGrid[i + s.params.slidesPerGroup] - s.slidesGrid[i]; 1992 } 1993 } 1994 else { 1995 if (currentPos >= s.slidesGrid[i]) { 1996 stopIndex = i; 1997 groupSize = s.slidesGrid[s.slidesGrid.length - 1] - s.slidesGrid[s.slidesGrid.length - 2]; 1998 } 1999 } 2000 } 2001 2002 // Find current slide size 2003 var ratio = (currentPos - s.slidesGrid[stopIndex]) / groupSize; 2004 2005 if (timeDiff > s.params.longSwipesMs) { 2006 // Long touches 2007 if (!s.params.longSwipes) { 2008 s.slideTo(s.activeIndex); 2009 return; 2010 } 2011 if (s.swipeDirection === 'next') { 2012 if (ratio >= s.params.longSwipesRatio) s.slideTo(stopIndex + s.params.slidesPerGroup); 2013 else s.slideTo(stopIndex); 2014 2015 } 2016 if (s.swipeDirection === 'prev') { 2017 if (ratio > (1 - s.params.longSwipesRatio)) s.slideTo(stopIndex + s.params.slidesPerGroup); 2018 else s.slideTo(stopIndex); 2019 } 2020 } 2021 else { 2022 // Short swipes 2023 if (!s.params.shortSwipes) { 2024 s.slideTo(s.activeIndex); 2025 return; 2026 } 2027 if (s.swipeDirection === 'next') { 2028 s.slideTo(stopIndex + s.params.slidesPerGroup); 2029 2030 } 2031 if (s.swipeDirection === 'prev') { 2032 s.slideTo(stopIndex); 2033 } 2034 } 2035 }; 2036 /*========================= 2037 Transitions 2038 ===========================*/ 2039 s._slideTo = function (slideIndex, speed) { 2040 return s.slideTo(slideIndex, speed, true, true); 2041 }; 2042 s.slideTo = function (slideIndex, speed, runCallbacks, internal) { 2043 if (typeof runCallbacks === 'undefined') runCallbacks = true; 2044 if (typeof slideIndex === 'undefined') slideIndex = 0; 2045 if (slideIndex < 0) slideIndex = 0; 2046 s.snapIndex = Math.floor(slideIndex / s.params.slidesPerGroup); 2047 if (s.snapIndex >= s.snapGrid.length) s.snapIndex = s.snapGrid.length - 1; 2048 2049 var translate = - s.snapGrid[s.snapIndex]; 2050 // Stop autoplay 2051 if (s.params.autoplay && s.autoplaying) { 2052 if (internal || !s.params.autoplayDisableOnInteraction) { 2053 s.pauseAutoplay(speed); 2054 } 2055 else { 2056 s.stopAutoplay(); 2057 } 2058 } 2059 // Update progress 2060 s.updateProgress(translate); 2061 2062 // Normalize slideIndex 2063 if (s.params.normalizeSlideIndex) { 2064 for (var i = 0; i < s.slidesGrid.length; i++) { 2065 if (- Math.floor(translate * 100) >= Math.floor(s.slidesGrid[i] * 100)) { 2066 slideIndex = i; 2067 } 2068 } 2069 } 2070 2071 // Directions locks 2072 if (!s.params.allowSwipeToNext && translate < s.translate && translate < s.minTranslate()) { 2073 return false;
2074 } 2075 if (!s.params.allowSwipeToPrev && translate > s.translate && translate > s.maxTranslate()) { 2076 if ((s.activeIndex || 0) !== slideIndex) return false; 2077 } 2078 2079 // Update Index 2080 if (typeof speed === 'undefined') speed = s.params.speed; 2081 s.previousIndex = s.activeIndex || 0; 2082 s.activeIndex = slideIndex; 2083 s.updateRealIndex(); 2084 if ((s.rtl && -translate === s.translate) || (!s.rtl && translate === s.translate)) { 2085 // Update Height 2086 if (s.params.autoHeight) { 2087 s.updateAutoHeight(); 2088 } 2089 s.updateClasses(); 2090 if (s.params.effect !== 'slide') { 2091 s.setWrapperTranslate(translate); 2092 } 2093 return false; 2094 } 2095 s.updateClasses(); 2096 s.onTransitionStart(runCallbacks); 2097 2098 if (speed === 0 || s.browser.lteIE9) { 2099 s.setWrapperTranslate(translate); 2100 s.setWrapperTransition(0); 2101 s.onTransitionEnd(runCallbacks); 2102 } 2103 else { 2104 s.setWrapperTranslate(translate); 2105 s.setWrapperTransition(speed); 2106 if (!s.animating) { 2107 s.animating = true; 2108 s.wrapper.transitionEnd(function () { 2109 if (!s) return; 2110 s.onTransitionEnd(runCallbacks); 2111 }); 2112 } 2113 2114 } 2115 2116 return true; 2117 }; 2118 2119 s.onTransitionStart = function (runCallbacks) { 2120 if (typeof runCallbacks === 'undefined') runCallbacks = true; 2121 if (s.params.autoHeight) { 2122 s.updateAutoHeight(); 2123 } 2124 if (s.lazy) s.lazy.onTransitionStart(); 2125 if (runCallbacks) { 2126 s.emit('onTransitionStart', s); 2127 if (s.activeIndex !== s.previousIndex) { 2128 s.emit('onSlideChangeStart', s); 2129 if (s.activeIndex > s.previousIndex) { 2130 s.emit('onSlideNextStart', s); 2131 } 2132 else { 2133 s.emit('onSlidePrevStart', s); 2134 } 2135 } 2136 2137 } 2138 }; 2139 s.onTransitionEnd = function (runCallbacks) { 2140 s.animating = false; 2141 s.setWrapperTransition(0); 2142 if (typeof runCallbacks === 'undefined') runCallbacks = true; 2143 if (s.lazy) s.lazy.onTransitionEnd(); 2144 if (runCallbacks) { 2145 s.emit('onTransitionEnd', s); 2146 if (s.activeIndex !== s.previousIndex) { 2147 s.emit('onSlideChangeEnd', s); 2148 if (s.activeIndex > s.previousIndex) { 2149 s.emit('onSlideNextEnd', s); 2150 } 2151 else { 2152 s.emit('onSlidePrevEnd', s); 2153 } 2154 } 2155 } 2156 if (s.params.history && s.history) { 2157 s.history.setHistory(s.params.history, s.activeIndex); 2158 } 2159 if (s.params.hashnav && s.hashnav) { 2160 s.hashnav.setHash(); 2161 } 2162 2163 }; 2164 s.slideNext = function (runCallbacks, speed, internal) { 2165 if (s.params.loop) { 2166 if (s.animating) return false; 2167 s.fixLoop(); 2168 var clientLeft = s.container[0].clientLeft; 2169 return s.slideTo(s.activeIndex + s.params.slidesPerGroup, speed, runCallbacks, internal); 2170 } 2171 else return s.slideTo(s.activeIndex + s.params.slidesPerGroup, speed, runCallbacks, internal); 2172 }; 2173 s._slideNext = function (speed) { 2174 return s.slideNext(true, speed, true); 2175 }; 2176 s.slidePrev = function (runCallbacks, speed, internal) { 2177 if (s.params.loop) { 2178 if (s.animating) return false; 2179 s.fixLoop(); 2180 var clientLeft = s.container[0].clientLeft; 2181 return s.slideTo(s.activeIndex - 1, speed, runCallbacks, internal); 2182 } 2183 else return s.slideTo(s.activeIndex - 1, speed, runCallbacks, internal); 2184 }; 2185 s._slidePrev = function (speed) { 2186 return s.slidePrev(true, speed, true); 2187 }; 2188 s.slideReset = function (runCallbacks, speed, internal) { 2189 return s.slideTo(s.activeIndex, speed, runCallbacks); 2190 }; 2191 2192 s.disableTouchControl = function () { 2193 s.params.onlyExternal = true; 2194 return true; 2195 }; 2196 s.enableTouchControl = function () { 2197 s.params.onlyExternal = false;
2198 return true; 2199 }; 2200 2201 /*========================= 2202 Translate/transition helpers 2203 ===========================*/ 2204 s.setWrapperTransition = function (duration, byController) { 2205 s.wrapper.transition(duration); 2206 if (s.params.effect !== 'slide' && s.effects[s.params.effect]) { 2207 s.effects[s.params.effect].setTransition(duration); 2208 } 2209 if (s.params.parallax && s.parallax) { 2210 s.parallax.setTransition(duration); 2211 } 2212 if (s.params.scrollbar && s.scrollbar) { 2213 s.scrollbar.setTransition(duration); 2214 } 2215 if (s.params.control && s.controller) { 2216 s.controller.setTransition(duration, byController); 2217 } 2218 s.emit('onSetTransition', s, duration); 2219 }; 2220 s.setWrapperTranslate = function (translate, updateActiveIndex, byController) { 2221 var x = 0, y = 0, z = 0; 2222 if (s.isHorizontal()) { 2223 x = s.rtl ? -translate : translate; 2224 } 2225 else { 2226 y = translate; 2227 } 2228 2229 if (s.params.roundLengths) { 2230 x = round(x); 2231 y = round(y); 2232 } 2233 2234 if (!s.params.virtualTranslate) { 2235 if (s.support.transforms3d) s.wrapper.transform('translate3d(' + x + 'px, ' + y + 'px, ' + z + 'px)'); 2236 else s.wrapper.transform('translate(' + x + 'px, ' + y + 'px)'); 2237 } 2238 2239 s.translate = s.isHorizontal() ? x : y; 2240 2241 // Check if we need to update progress 2242 var progress; 2243 var translatesDiff = s.maxTranslate() - s.minTranslate(); 2244 if (translatesDiff === 0) { 2245 progress = 0; 2246 } 2247 else { 2248 progress = (translate - s.minTranslate()) / (translatesDiff); 2249 } 2250 if (progress !== s.progress) { 2251 s.updateProgress(translate); 2252 } 2253 2254 if (updateActiveIndex) s.updateActiveIndex(); 2255 if (s.params.effect !== 'slide' && s.effects[s.params.effect]) { 2256 s.effects[s.params.effect].setTranslate(s.translate); 2257 } 2258 if (s.params.parallax && s.parallax) { 2259 s.parallax.setTranslate(s.translate); 2260 } 2261 if (s.params.scrollbar && s.scrollbar) { 2262 s.scrollbar.setTranslate(s.translate); 2263 } 2264 if (s.params.control && s.controller) { 2265 s.controller.setTranslate(s.translate, byController); 2266 } 2267 s.emit('onSetTranslate', s, s.translate); 2268 }; 2269 2270 s.getTranslate = function (el, axis) { 2271 var matrix, curTransform, curStyle, transformMatrix; 2272 2273 // automatic axis detection 2274 if (typeof axis === 'undefined') { 2275 axis = 'x'; 2276 } 2277 2278 if (s.params.virtualTranslate) { 2279 return s.rtl ? -s.translate : s.translate; 2280 } 2281 2282 curStyle = window.getComputedStyle(el, null); 2283 if (window.WebKitCSSMatrix) { 2284 curTransform = curStyle.transform || curStyle.webkitTransform; 2285 if (curTransform.split(',').length > 6) { 2286 curTransform = curTransform.split(', ').map(function (a) { 2287 return a.replace(',', '.'); 2288 }).join(', '); 2289 } 2290 // Some old versions of Webkit choke when 'none' is passed; pass 2291 // empty string instead in this case 2292 transformMatrix = new window.WebKitCSSMatrix(curTransform === 'none' ? '' : curTransform); 2293 } 2294 else { 2295 transformMatrix = curStyle.MozTransform || curStyle.OTransform || curStyle.MsTransform || curStyle.msTransform || curStyle.transform || curStyle.getPropertyValue('transform').replace('translate(', 'matrix(1, 0, 0, 1,'); 2296 matrix = transformMatrix.toString().split(','); 2297 } 2298 2299 if (axis === 'x') { 2300 //Latest Chrome and webkits Fix 2301 if (window.WebKitCSSMatrix) 2302 curTransform = transformMatrix.m41; 2303 //Crazy IE10 Matrix 2304 else if (matrix.length === 16) 2305 curTransform = parseFloat(matrix[12]); 2306 //Normal Browsers 2307 else 2308 curTransform = parseFloat(matrix[4]); 2309 } 2310 if (axis === 'y') { 2311 //Latest Chrome and webkits Fix 2312 if (window.WebKitCSSMatrix) 2313 curTransform = transformMatrix.m42; 2314 //Crazy IE10 Matrix 2315 else if (matrix.length === 16) 2316 curTransform = parseFloat(matrix[13]); 2317 //Normal Browsers 2318 else 2319 curTransform = parseFloat(matrix[5]); 2320 } 2321 if (s.rtl && curTransform) curTransform = -curTransform; 2322 return curTransform || 0; 2323 }; 2324 s.getWrapperTranslate = function (axis) { 2325 if (typeof axis === 'undefined') { 2326 axis = s.isHorizontal() ? 'x' : 'y'; 2327 } 2328 return s.getTranslate(s.wrapper[0], axis); 2329 }; 2330 2331 /*========================= 2332 Observer 2333 ===========================*/ 2334 s.observers = []; 2335 function initObserver(target, options) { 2336 options = options || {}; 2337 // create an observer instance 2338 var ObserverFunc = window.MutationObserver || window.WebkitMutationObserver; 2339 var observer = new ObserverFunc(function (mutations) { 2340 mutations.forEach(function (mutation) { 2341 s.onResize(true); 2342 s.emit('onObserverUpdate', s, mutation); 2343 }); 2344 }); 2345 2346 observer.observe(target, { 2347 attributes: typeof options.attributes === 'undefined' ? true : options.attributes, 2348 childList: typeof options.childList === 'undefined' ? true : options.childList, 2349 characterData: typeof options.characterData === 'undefined' ? true : options.characterData 2350 }); 2351 2352 s.observers.push(observer); 2353 }
2354 s.initObservers = function () { 2355 if (s.params.observeParents) { 2356 var containerParents = s.container.parents(); 2357 for (var i = 0; i < containerParents.length; i++) { 2358 initObserver(containerParents[i]); 2359 } 2360 } 2361 2362 // Observe container 2363 initObserver(s.container[0], { childList: false }); 2364 2365 // Observe wrapper 2366 initObserver(s.wrapper[0], { attributes: false }); 2367 }; 2368 s.disconnectObservers = function () { 2369 for (var i = 0; i < s.observers.length; i++) { 2370 s.observers[i].disconnect(); 2371 } 2372 s.observers = []; 2373 }; 2374 /*========================= 2375 Loop 2376 ===========================*/ 2377 // Create looped slides 2378 s.createLoop = function () { 2379 // Remove duplicated slides 2380 s.wrapper.children('.' + s.params.slideClass + '.' + s.params.slideDuplicateClass).remove(); 2381 2382 var slides = s.wrapper.children('.' + s.params.slideClass); 2383 2384 if (s.params.slidesPerView === 'auto' && !s.params.loopedSlides) s.params.loopedSlides = slides.length; 2385 2386 s.loopedSlides = parseInt(s.params.loopedSlides || s.params.slidesPerView, 10); 2387 s.loopedSlides = s.loopedSlides + s.params.loopAdditionalSlides; 2388 if (s.loopedSlides > slides.length) { 2389 s.loopedSlides = slides.length; 2390 } 2391 2392 var prependSlides = [], appendSlides = [], i; 2393 slides.each(function (index, el) { 2394 var slide = $(this); 2395 if (index < s.loopedSlides) appendSlides.push(el); 2396 if (index < slides.length && index >= slides.length - s.loopedSlides) prependSlides.push(el); 2397 slide.attr('data-swiper-slide-index', index); 2398 }); 2399 for (i = 0; i < appendSlides.length; i++) { 2400 s.wrapper.append($(appendSlides[i].cloneNode(true)).addClass(s.params.slideDuplicateClass)); 2401 } 2402 for (i = prependSlides.length - 1; i >= 0; i--) { 2403 s.wrapper.prepend($(prependSlides[i].cloneNode(true)).addClass(s.params.slideDuplicateClass)); 2404 } 2405 }; 2406 s.destroyLoop = function () { 2407 s.wrapper.children('.' + s.params.slideClass + '.' + s.params.slideDuplicateClass).remove(); 2408 s.slides.removeAttr('data-swiper-slide-index'); 2409 }; 2410 s.reLoop = function (updatePosition) { 2411 var oldIndex = s.activeIndex - s.loopedSlides; 2412 s.destroyLoop(); 2413 s.createLoop(); 2414 s.updateSlidesSize(); 2415 if (updatePosition) { 2416 s.slideTo(oldIndex + s.loopedSlides, 0, false); 2417 } 2418 2419 }; 2420 s.fixLoop = function () { 2421 var newIndex; 2422 //Fix For Negative Oversliding 2423 if (s.activeIndex < s.loopedSlides) { 2424 newIndex = s.slides.length - s.loopedSlides * 3 + s.activeIndex; 2425 newIndex = newIndex + s.loopedSlides; 2426 s.slideTo(newIndex, 0, false, true); 2427 } 2428 //Fix For Positive Oversliding 2429 else if ((s.params.slidesPerView === 'auto' && s.activeIndex >= s.loopedSlides * 2) || (s.activeIndex > s.slides.length - s.params.slidesPerView * 2)) { 2430 newIndex = -s.slides.length + s.activeIndex + s.loopedSlides; 2431 newIndex = newIndex + s.loopedSlides; 2432 s.slideTo(newIndex, 0, false, true); 2433 } 2434 }; 2435 /*========================= 2436 Append/Prepend/Remove Slides 2437 ===========================*/ 2438 s.appendSlide = function (slides) { 2439 if (s.params.loop) { 2440 s.destroyLoop(); 2441 } 2442 if (typeof slides === 'object' && slides.length) { 2443 for (var i = 0; i < slides.length; i++) { 2444 if (slides[i]) s.wrapper.append(slides[i]); 2445 } 2446 } 2447 else { 2448 s.wrapper.append(slides); 2449 } 2450 if (s.params.loop) { 2451 s.createLoop(); 2452 } 2453 if (!(s.params.observer && s.support.observer)) { 2454 s.update(true); 2455 } 2456 }; 2457 s.prependSlide = function (slides) { 2458 if (s.params.loop) { 2459 s.destroyLoop(); 2460 } 2461 var newActiveIndex = s.activeIndex + 1; 2462 if (typeof slides === 'object' && slides.length) { 2463 for (var i = 0; i < slides.length; i++) {
2464 if (slides[i]) s.wrapper.prepend(slides[i]); 2465 } 2466 newActiveIndex = s.activeIndex + slides.length; 2467 } 2468 else { 2469 s.wrapper.prepend(slides); 2470 } 2471 if (s.params.loop) { 2472 s.createLoop(); 2473 } 2474 if (!(s.params.observer && s.support.observer)) { 2475 s.update(true); 2476 } 2477 s.slideTo(newActiveIndex, 0, false); 2478 }; 2479 s.removeSlide = function (slidesIndexes) { 2480 if (s.params.loop) { 2481 s.destroyLoop(); 2482 s.slides = s.wrapper.children('.' + s.params.slideClass); 2483 } 2484 var newActiveIndex = s.activeIndex, 2485 indexToRemove; 2486 if (typeof slidesIndexes === 'object' && slidesIndexes.length) { 2487 for (var i = 0; i < slidesIndexes.length; i++) { 2488 indexToRemove = slidesIndexes[i]; 2489 if (s.slides[indexToRemove]) s.slides.eq(indexToRemove).remove(); 2490 if (indexToRemove < newActiveIndex) newActiveIndex--; 2491 } 2492 newActiveIndex = Math.max(newActiveIndex, 0); 2493 } 2494 else { 2495 indexToRemove = slidesIndexes; 2496 if (s.slides[indexToRemove]) s.slides.eq(indexToRemove).remove(); 2497 if (indexToRemove < newActiveIndex) newActiveIndex--; 2498 newActiveIndex = Math.max(newActiveIndex, 0); 2499 } 2500 2501 if (s.params.loop) { 2502 s.createLoop(); 2503 } 2504 2505 if (!(s.params.observer && s.support.observer)) { 2506 s.update(true); 2507 } 2508 if (s.params.loop) { 2509 s.slideTo(newActiveIndex + s.loopedSlides, 0, false); 2510 } 2511 else { 2512 s.slideTo(newActiveIndex, 0, false); 2513 } 2514 2515 }; 2516 s.removeAllSlides = function () { 2517 var slidesIndexes = []; 2518 for (var i = 0; i < s.slides.length; i++) { 2519 slidesIndexes.push(i); 2520 } 2521 s.removeSlide(slidesIndexes); 2522 }; 2523 2524 2525 /*=========================
2526 Effects 2527 ===========================*/ 2528 s.effects = { 2529 fade: { 2530 setTranslate: function () { 2531 for (var i = 0; i < s.slides.length; i++) { 2532 var slide = s.slides.eq(i); 2533 var offset = slide[0].swiperSlideOffset; 2534 var tx = -offset; 2535 if (!s.params.virtualTranslate) tx = tx - s.translate; 2536 var ty = 0; 2537 if (!s.isHorizontal()) { 2538 ty = tx; 2539 tx = 0; 2540 } 2541 var slideOpacity = s.params.fade.crossFade ? 2542 Math.max(1 - Math.abs(slide[0].progress), 0) : 2543 1 + Math.min(Math.max(slide[0].progress, -1), 0); 2544 slide 2545 .css({ 2546 opacity: slideOpacity 2547 }) 2548 .transform('translate3d(' + tx + 'px, ' + ty + 'px, 0px)'); 2549 2550 } 2551 2552 }, 2553 setTransition: function (duration) { 2554 s.slides.transition(duration); 2555 if (s.params.virtualTranslate && duration !== 0) { 2556 var eventTriggered = false; 2557 s.slides.transitionEnd(function () { 2558 if (eventTriggered) return; 2559 if (!s) return; 2560 eventTriggered = true; 2561 s.animating = false; 2562 var triggerEvents = ['webkitTransitionEnd', 'transitionend', 'oTransitionEnd', 'MSTransitionEnd', 'msTransitionEnd']; 2563 for (var i = 0; i < triggerEvents.length; i++) { 2564 s.wrapper.trigger(triggerEvents[i]); 2565 } 2566 }); 2567 } 2568 } 2569 }, 2570 flip: { 2571 setTranslate: function () { 2572 for (var i = 0; i < s.slides.length; i++) { 2573 var slide = s.slides.eq(i); 2574 var progress = slide[0].progress; 2575 if (s.params.flip.limitRotation) { 2576 progress = Math.max(Math.min(slide[0].progress, 1), -1); 2577 } 2578 var offset = slide[0].swiperSlideOffset; 2579 var rotate = -180 * progress, 2580 rotateY = rotate, 2581 rotateX = 0, 2582 tx = -offset, 2583 ty = 0; 2584 if (!s.isHorizontal()) { 2585 ty = tx; 2586 tx = 0; 2587 rotateX = -rotateY; 2588 rotateY = 0; 2589 } 2590 else if (s.rtl) { 2591 rotateY = -rotateY; 2592 } 2593 2594 slide[0].style.zIndex = -Math.abs(Math.round(progress)) + s.slides.length; 2595 2596 if (s.params.flip.slideShadows) { 2597 //Set shadows 2598 var shadowBefore = s.isHorizontal() ? slide.find('.swiper-slide-shadow-left') : slide.find('.swiper-slide-shadow-top'); 2599 var shadowAfter = s.isHorizontal() ? slide.find('.swiper-slide-shadow-right') : slide.find('.swiper-slide-shadow-bottom'); 2600 if (shadowBefore.length === 0) { 2601 shadowBefore = $('<div class="swiper-slide-shadow-' + (s.isHorizontal() ? 'left' : 'top') + '"></div>'); 2602 slide.append(shadowBefore); 2603 } 2604 if (shadowAfter.length === 0) { 2605 shadowAfter = $('<div class="swiper-slide-shadow-' + (s.isHorizontal() ? 'right' : 'bottom') + '"></div>'); 2606 slide.append(shadowAfter); 2607 } 2608 if (shadowBefore.length) shadowBefore[0].style.opacity = Math.max(-progress, 0); 2609 if (shadowAfter.length) shadowAfter[0].style.opacity = Math.max(progress, 0); 2610 } 2611 2612 slide 2613 .transform('translate3d(' + tx + 'px, ' + ty + 'px, 0px) rotateX(' + rotateX + 'deg) rotateY(' + rotateY + 'deg)'); 2614 } 2615 }, 2616 setTransition: function (duration) { 2617 s.slides.transition(duration).find('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').transition(duration); 2618 if (s.params.virtualTranslate && duration !== 0) { 2619 var eventTriggered = false;
2620 s.slides.eq(s.activeIndex).transitionEnd(function () { 2621 if (eventTriggered) return; 2622 if (!s) return; 2623 if (!$(this).hasClass(s.params.slideActiveClass)) return; 2624 eventTriggered = true; 2625 s.animating = false; 2626 var triggerEvents = ['webkitTransitionEnd', 'transitionend', 'oTransitionEnd', 'MSTransitionEnd', 'msTransitionEnd']; 2627 for (var i = 0; i < triggerEvents.length; i++) { 2628 s.wrapper.trigger(triggerEvents[i]); 2629 } 2630 }); 2631 } 2632 } 2633 }, 2634 cube: { 2635 setTranslate: function () { 2636 var wrapperRotate = 0, cubeShadow; 2637 if (s.params.cube.shadow) { 2638 if (s.isHorizontal()) { 2639 cubeShadow = s.wrapper.find('.swiper-cube-shadow'); 2640 if (cubeShadow.length === 0) { 2641 cubeShadow = $('<div class="swiper-cube-shadow"></div>'); 2642 s.wrapper.append(cubeShadow); 2643 } 2644 cubeShadow.css({ height: s.width + 'px' }); 2645 } 2646 else { 2647 cubeShadow = s.container.find('.swiper-cube-shadow'); 2648 if (cubeShadow.length === 0) { 2649 cubeShadow = $('<div class="swiper-cube-shadow"></div>'); 2650 s.container.append(cubeShadow); 2651 } 2652 } 2653 } 2654 for (var i = 0; i < s.slides.length; i++) { 2655 var slide = s.slides.eq(i); 2656 var slideAngle = i * 90; 2657 var round = Math.floor(slideAngle / 360); 2658 if (s.rtl) { 2659 slideAngle = -slideAngle; 2660 round = Math.floor(-slideAngle / 360); 2661 } 2662 var progress = Math.max(Math.min(slide[0].progress, 1), -1); 2663 var tx = 0, ty = 0, tz = 0; 2664 if (i % 4 === 0) { 2665 tx = - round * 4 * s.size; 2666 tz = 0; 2667 } 2668 else if ((i - 1) % 4 === 0) { 2669 tx = 0; 2670 tz = - round * 4 * s.size; 2671 } 2672 else if ((i - 2) % 4 === 0) { 2673 tx = s.size + round * 4 * s.size; 2674 tz = s.size; 2675 } 2676 else if ((i - 3) % 4 === 0) { 2677 tx = - s.size; 2678 tz = 3 * s.size + s.size * 4 * round; 2679 } 2680 if (s.rtl) { 2681 tx = -tx; 2682 } 2683 2684 if (!s.isHorizontal()) { 2685 ty = tx; 2686 tx = 0; 2687 } 2688 2689 var transform = 'rotateX(' + (s.isHorizontal() ? 0 : -slideAngle) + 'deg) rotateY(' + (s.isHorizontal() ? slideAngle : 0) + 'deg) translate3d(' + tx + 'px, ' + ty + 'px, ' + tz + 'px)'; 2690 if (progress <= 1 && progress > -1) { 2691 wrapperRotate = i * 90 + progress * 90; 2692 if (s.rtl) wrapperRotate = -i * 90 - progress * 90; 2693 } 2694 slide.transform(transform); 2695 if (s.params.cube.slideShadows) { 2696 //Set shadows 2697 var shadowBefore = s.isHorizontal() ? slide.find('.swiper-slide-shadow-left') : slide.find('.swiper-slide-shadow-top'); 2698 var shadowAfter = s.isHorizontal() ? slide.find('.swiper-slide-shadow-right') : slide.find('.swiper-slide-shadow-bottom'); 2699 if (shadowBefore.length === 0) { 2700 shadowBefore = $('<div class="swiper-slide-shadow-' + (s.isHorizontal() ? 'left' : 'top') + '"></div>'); 2701 slide.append(shadowBefore); 2702 } 2703 if (shadowAfter.length === 0) {
2704 shadowAfter = $('<div class="swiper-slide-shadow-' + (s.isHorizontal() ? 'right' : 'bottom') + '"></div>'); 2705 slide.append(shadowAfter); 2706 } 2707 if (shadowBefore.length) shadowBefore[0].style.opacity = Math.max(-progress, 0); 2708 if (shadowAfter.length) shadowAfter[0].style.opacity = Math.max(progress, 0); 2709 } 2710 } 2711 s.wrapper.css({ 2712 '-webkit-transform-origin': '50% 50% -' + (s.size / 2) + 'px', 2713 '-moz-transform-origin': '50% 50% -' + (s.size / 2) + 'px', 2714 '-ms-transform-origin': '50% 50% -' + (s.size / 2) + 'px', 2715 'transform-origin': '50% 50% -' + (s.size / 2) + 'px' 2716 }); 2717 2718 if (s.params.cube.shadow) { 2719 if (s.isHorizontal()) { 2720 cubeShadow.transform('translate3d(0px, ' + (s.width / 2 + s.params.cube.shadowOffset) + 'px, ' + (-s.width / 2) + 'px) rotateX(90deg) rotateZ(0deg) scale(' + (s.params.cube.shadowScale) + ')'); 2721 } 2722 else { 2723 var shadowAngle = Math.abs(wrapperRotate) - Math.floor(Math.abs(wrapperRotate) / 90) * 90; 2724 var multiplier = 1.5 - (Math.sin(shadowAngle * 2 * Math.PI / 360) / 2 + Math.cos(shadowAngle * 2 * Math.PI / 360) / 2); 2725 var scale1 = s.params.cube.shadowScale, 2726 scale2 = s.params.cube.shadowScale / multiplier, 2727 offset = s.params.cube.shadowOffset; 2728 cubeShadow.transform('scale3d(' + scale1 + ', 1, ' + scale2 + ') translate3d(0px, ' + (s.height / 2 + offset) + 'px, ' + (-s.height / 2 / scale2) + 'px) rotateX(-90deg)'); 2729 } 2730 } 2731 var zFactor = (s.isSafari || s.isUiWebView) ? (-s.size / 2) : 0; 2732 s.wrapper.transform('translate3d(0px,0,' + zFactor + 'px) rotateX(' + (s.isHorizontal() ? 0 : wrapperRotate) + 'deg) rotateY(' + (s.isHorizontal() ? -wrapperRotate : 0) + 'deg)'); 2733 }, 2734 setTransition: function (duration) { 2735 s.slides.transition(duration).find('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').transition(duration); 2736 if (s.params.cube.shadow && !s.isHorizontal()) { 2737 s.container.find('.swiper-cube-shadow').transition(duration); 2738 } 2739 } 2740 }, 2741 coverflow: { 2742 setTranslate: function () { 2743 var transform = s.translate; 2744 var center = s.isHorizontal() ? -transform + s.width / 2 : -transform + s.height / 2; 2745 var rotate = s.isHorizontal() ? s.params.coverflow.rotate : -s.params.coverflow.rotate; 2746 var translate = s.params.coverflow.depth; 2747 //Each slide offset from center 2748 for (var i = 0, length = s.slides.length; i < length; i++) { 2749 var slide = s.slides.eq(i); 2750 var slideSize = s.slidesSizesGrid[i]; 2751 var slideOffset = slide[0].swiperSlideOffset; 2752 var offsetMultiplier = (center - slideOffset - slideSize / 2) / slideSize * s.params.coverflow.modifier; 2753 2754 var rotateY = s.isHorizontal() ? rotate * offsetMultiplier : 0; 2755 var rotateX = s.isHorizontal() ? 0 : rotate * offsetMultiplier; 2756 // var rotateZ = 0 2757 var translateZ = -translate * Math.abs(offsetMultiplier); 2758 2759 var translateY = s.isHorizontal() ? 0 : s.params.coverflow.stretch * (offsetMultiplier); 2760 var translateX = s.isHorizontal() ? s.params.coverflow.stretch * (offsetMultiplier) : 0; 2761 2762 //Fix for ultra small values 2763 if (Math.abs(translateX) < 0.001) translateX = 0; 2764 if (Math.abs(translateY) < 0.001) translateY = 0; 2765 if (Math.abs(translateZ) < 0.001) translateZ = 0; 2766 if (Math.abs(rotateY) < 0.001) rotateY = 0; 2767 if (Math.abs(rotateX) < 0.001) rotateX = 0; 2768 2769 var slideTransform = 'translate3d(' + translateX + 'px,' + translateY + 'px,' + translateZ + 'px) rotateX(' + rotateX + 'deg) rotateY(' + rotateY + 'deg)'; 2770 2771 slide.transform(slideTransform); 2772 slide[0].style.zIndex = -Math.abs(Math.round(offsetMultiplier)) + 1; 2773 if (s.params.coverflow.slideShadows) { 2774 //Set shadows 2775 var shadowBefore = s.isHorizontal() ? slide.find('.swiper-slide-shadow-left') : slide.find('.swiper-slide-shadow-top'); 2776 var shadowAfter = s.isHorizontal() ? slide.find('.swiper-slide-shadow-right') : slide.find('.swiper-slide-shadow-bottom'); 2777 if (shadowBefore.length === 0) { 2778 shadowBefore = $('<div class="swiper-slide-shadow-' + (s.isHorizontal() ? 'left' : 'top') + '"></div>'); 2779 slide.append(shadowBefore); 2780 } 2781 if (shadowAfter.length === 0) {
2782 shadowAfter = $('<div class="swiper-slide-shadow-' + (s.isHorizontal() ? 'right' : 'bottom') + '"></div>'); 2783 slide.append(shadowAfter); 2784 } 2785 if (shadowBefore.length) shadowBefore[0].style.opacity = offsetMultiplier > 0 ? offsetMultiplier : 0; 2786 if (shadowAfter.length) shadowAfter[0].style.opacity = (-offsetMultiplier) > 0 ? -offsetMultiplier : 0; 2787 } 2788 } 2789 2790 //Set correct perspective for IE10 2791 if (s.browser.ie) { 2792 var ws = s.wrapper[0].style; 2793 ws.perspectiveOrigin = center + 'px 50%'; 2794 } 2795 }, 2796 setTransition: function (duration) { 2797 s.slides.transition(duration).find('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').transition(duration); 2798 } 2799 } 2800 }; 2801 2802 2803 /*========================= 2804 Images Lazy Loading 2805 ===========================*/ 2806 s.lazy = { 2807 initialImageLoaded: false, 2808 loadImageInSlide: function (index, loadInDuplicate) { 2809 if (typeof index === 'undefined') return; 2810 if (typeof loadInDuplicate === 'undefined') loadInDuplicate = true; 2811 if (s.slides.length === 0) return; 2812 2813 var slide = s.slides.eq(index); 2814 var img = slide.find('.' + s.params.lazyLoadingClass + ':not(.' + s.params.lazyStatusLoadedClass + '):not(.' + s.params.lazyStatusLoadingClass + ')'); 2815 if (slide.hasClass(s.params.lazyLoadingClass) && !slide.hasClass(s.params.lazyStatusLoadedClass) && !slide.hasClass(s.params.lazyStatusLoadingClass)) { 2816 img = img.add(slide[0]); 2817 } 2818 if (img.length === 0) return; 2819 2820 img.each(function () { 2821 var _img = $(this); 2822 _img.addClass(s.params.lazyStatusLoadingClass); 2823 var background = _img.attr('data-background'); 2824 var src = _img.attr('data-src'), 2825 srcset = _img.attr('data-srcset'), 2826 sizes = _img.attr('data-sizes'); 2827 s.loadImage(_img[0], (src || background), srcset, sizes, false, function () { 2828 if (typeof s === 'undefined' || s === null || !s) return; 2829 if (background) { 2830 _img.css('background-image', 'url("' + background + '")'); 2831 _img.removeAttr('data-background'); 2832 } 2833 else { 2834 if (srcset) { 2835 _img.attr('srcset', srcset); 2836 _img.removeAttr('data-srcset'); 2837 } 2838 if (sizes) { 2839 _img.attr('sizes', sizes); 2840 _img.removeAttr('data-sizes'); 2841 } 2842 if (src) { 2843 _img.attr('src', src); 2844 _img.removeAttr('data-src'); 2845 } 2846 2847 } 2848 2849 _img.addClass(s.params.lazyStatusLoadedClass).removeClass(s.params.lazyStatusLoadingClass); 2850 slide.find('.' + s.params.lazyPreloaderClass + ', .' + s.params.preloaderClass).remove(); 2851 if (s.params.loop && loadInDuplicate) { 2852 var slideOriginalIndex = slide.attr('data-swiper-slide-index'); 2853 if (slide.hasClass(s.params.slideDuplicateClass)) { 2854 var originalSlide = s.wrapper.children('[data-swiper-slide-index="' + slideOriginalIndex + '"]:not(.' + s.params.slideDuplicateClass + ')'); 2855 s.lazy.loadImageInSlide(originalSlide.index(), false); 2856 } 2857 else { 2858 var duplicatedSlide = s.wrapper.children('.' + s.params.slideDuplicateClass + '[data-swiper-slide-index="' + slideOriginalIndex + '"]'); 2859 s.lazy.loadImageInSlide(duplicatedSlide.index(), false); 2860 } 2861 } 2862 s.emit('onLazyImageReady', s, slide[0], _img[0]); 2863 }); 2864 2865 s.emit('onLazyImageLoad', s, slide[0], _img[0]); 2866 }); 2867 2868 }, 2869 load: function () { 2870 var i; 2871 var slidesPerView = s.params.slidesPerView; 2872 if (slidesPerView === 'auto') { 2873 slidesPerView = 0; 2874 } 2875 if (!s.lazy.initialImageLoaded) s.lazy.initialImageLoaded = true; 2876 if (s.params.watchSlidesVisibility) { 2877 s.wrapper.children('.' + s.params.slideVisibleClass).each(function () { 2878 s.lazy.loadImageInSlide($(this).index()); 2879 }); 2880 } 2881 else { 2882 if (slidesPerView > 1) { 2883 for (i = s.activeIndex; i < s.activeIndex + slidesPerView; i++) { 2884 if (s.slides[i]) s.lazy.loadImageInSlide(i); 2885 } 2886 } 2887 else { 2888 s.lazy.loadImageInSlide(s.activeIndex); 2889 } 2890 } 2891 if (s.params.lazyLoadingInPrevNext) { 2892 if (slidesPerView > 1 || (s.params.lazyLoadingInPrevNextAmount && s.params.lazyLoadingInPrevNextAmount > 1)) { 2893 var amount = s.params.lazyLoadingInPrevNextAmount; 2894 var spv = slidesPerView; 2895 var maxIndex = Math.min(s.activeIndex + spv + Math.max(amount, spv), s.slides.length); 2896 var minIndex = Math.max(s.activeIndex - Math.max(spv, amount), 0); 2897 // Next Slides 2898 for (i = s.activeIndex + slidesPerView; i < maxIndex; i++) { 2899 if (s.slides[i]) s.lazy.loadImageInSlide(i); 2900 } 2901 // Prev Slides 2902 for (i = minIndex; i < s.activeIndex; i++) { 2903 if (s.slides[i]) s.lazy.loadImageInSlide(i); 2904 } 2905 } 2906 else { 2907 var nextSlide = s.wrapper.children('.' + s.params.slideNextClass); 2908 if (nextSlide.length > 0) s.lazy.loadImageInSlide(nextSlide.index()); 2909 2910 var prevSlide = s.wrapper.children('.' + s.params.slidePrevClass); 2911 if (prevSlide.length > 0) s.lazy.loadImageInSlide(prevSlide.index()); 2912 } 2913 } 2914 }, 2915 onTransitionStart: function () { 2916 if (s.params.lazyLoading) { 2917 if (s.params.lazyLoadingOnTransitionStart || (!s.params.lazyLoadingOnTransitionStart && !s.lazy.initialImageLoaded)) { 2918 s.lazy.load(); 2919 } 2920 } 2921 }, 2922 onTransitionEnd: function () { 2923 if (s.params.lazyLoading && !s.params.lazyLoadingOnTransitionStart) { 2924 s.lazy.load(); 2925 } 2926 } 2927 }; 2928 2929 2930 /*========================= 2931 Scrollbar 2932 ===========================*/ 2933 s.scrollbar = { 2934 isTouched: false, 2935 setDragPosition: function (e) { 2936 var sb = s.scrollbar; 2937 var x = 0, y = 0; 2938 var translate; 2939 var pointerPosition = s.isHorizontal() ? 2940 ((e.type === 'touchstart' || e.type === 'touchmove') ? e.targetTouches[0].pageX : e.pageX || e.clientX) : 2941 ((e.type === 'touchstart' || e.type === 'touchmove') ? e.targetTouches[0].pageY : e.pageY || e.clientY); 2942 var position = (pointerPosition) - sb.track.offset()[s.isHorizontal() ? 'left' : 'top'] - sb.dragSize / 2; 2943 var positionMin = -s.minTranslate() * sb.moveDivider; 2944 var positionMax = -s.maxTranslate() * sb.moveDivider; 2945 if (position < positionMin) { 2946 position = positionMin; 2947 } 2948 else if (position > positionMax) { 2949 position = positionMax; 2950 } 2951 position = -position / sb.moveDivider; 2952 s.updateProgress(position); 2953 s.setWrapperTranslate(position, true); 2954 }, 2955 dragStart: function (e) { 2956 var sb = s.scrollbar; 2957 sb.isTouched = true; 2958 e.preventDefault(); 2959 e.stopPropagation(); 2960 2961 sb.setDragPosition(e); 2962 clearTimeout(sb.dragTimeout); 2963 2964 sb.track.transition(0); 2965 if (s.params.scrollbarHide) { 2966 sb.track.css('opacity', 1); 2967 } 2968 s.wrapper.transition(100); 2969 sb.drag.transition(100); 2970 s.emit('onScrollbarDragStart', s); 2971 }, 2972 dragMove: function (e) { 2973 var sb = s.scrollbar; 2974 if (!sb.isTouched) return; 2975 if (e.preventDefault) e.preventDefault(); 2976 else e.returnValue = false;
2977 sb.setDragPosition(e); 2978 s.wrapper.transition(0); 2979 sb.track.transition(0); 2980 sb.drag.transition(0); 2981 s.emit('onScrollbarDragMove', s); 2982 }, 2983 dragEnd: function (e) { 2984 var sb = s.scrollbar; 2985 if (!sb.isTouched) return; 2986 sb.isTouched = false; 2987 if (s.params.scrollbarHide) { 2988 clearTimeout(sb.dragTimeout); 2989 sb.dragTimeout = setTimeout(function () { 2990 sb.track.css('opacity', 0); 2991 sb.track.transition(400); 2992 }, 1000); 2993 2994 } 2995 s.emit('onScrollbarDragEnd', s); 2996 if (s.params.scrollbarSnapOnRelease) { 2997 s.slideReset(); 2998 } 2999 }, 3000 draggableEvents: (function () { 3001 if ((s.params.simulateTouch === false && !s.support.touch)) return s.touchEventsDesktop; 3002 else return s.touchEvents; 3003 })(), 3004 enableDraggable: function () { 3005 var sb = s.scrollbar; 3006 var target = s.support.touch ? sb.track : document; 3007 $(sb.track).on(sb.draggableEvents.start, sb.dragStart); 3008 $(target).on(sb.draggableEvents.move, sb.dragMove); 3009 $(target).on(sb.draggableEvents.end, sb.dragEnd); 3010 }, 3011 disableDraggable: function () { 3012 var sb = s.scrollbar; 3013 var target = s.support.touch ? sb.track : document; 3014 $(sb.track).off(sb.draggableEvents.start, sb.dragStart); 3015 $(target).off(sb.draggableEvents.move, sb.dragMove); 3016 $(target).off(sb.draggableEvents.end, sb.dragEnd); 3017 }, 3018 set: function () { 3019 if (!s.params.scrollbar) return; 3020 var sb = s.scrollbar; 3021 sb.track = $(s.params.scrollbar); 3022 if (s.params.uniqueNavElements && typeof s.params.scrollbar === 'string' && sb.track.length > 1 && s.container.find(s.params.scrollbar).length === 1) { 3023 sb.track = s.container.find(s.params.scrollbar); 3024 } 3025 sb.drag = sb.track.find('.swiper-scrollbar-drag'); 3026 if (sb.drag.length === 0) { 3027 sb.drag = $('<div class="swiper-scrollbar-drag"></div>'); 3028 sb.track.append(sb.drag); 3029 } 3030 sb.drag[0].style.width = ''; 3031 sb.drag[0].style.height = ''; 3032 sb.trackSize = s.isHorizontal() ? sb.track[0].offsetWidth : sb.track[0].offsetHeight; 3033 3034 sb.divider = s.size / s.virtualSize; 3035 sb.moveDivider = sb.divider * (sb.trackSize / s.size); 3036 sb.dragSize = sb.trackSize * sb.divider; 3037 3038 if (s.isHorizontal()) { 3039 sb.drag[0].style.width = sb.dragSize + 'px'; 3040 } 3041 else { 3042 sb.drag[0].style.height = sb.dragSize + 'px'; 3043 } 3044 3045 if (sb.divider >= 1) { 3046 sb.track[0].style.display = 'none'; 3047 } 3048 else { 3049 sb.track[0].style.display = ''; 3050 } 3051 if (s.params.scrollbarHide) { 3052 sb.track[0].style.opacity = 0; 3053 } 3054 }, 3055 setTranslate: function () { 3056 if (!s.params.scrollbar) return; 3057 var diff; 3058 var sb = s.scrollbar; 3059 var translate = s.translate || 0; 3060 var newPos; 3061 3062 var newSize = sb.dragSize; 3063 newPos = (sb.trackSize - sb.dragSize) * s.progress; 3064 if (s.rtl && s.isHorizontal()) { 3065 newPos = -newPos; 3066 if (newPos > 0) { 3067 newSize = sb.dragSize - newPos; 3068 newPos = 0; 3069 } 3070 else if (-newPos + sb.dragSize > sb.trackSize) { 3071 newSize = sb.trackSize + newPos; 3072 } 3073 } 3074 else { 3075 if (newPos < 0) { 3076 newSize = sb.dragSize + newPos; 3077 newPos = 0; 3078 } 3079 else if (newPos + sb.dragSize > sb.trackSize) { 3080 newSize = sb.trackSize - newPos; 3081 } 3082 } 3083 if (s.isHorizontal()) { 3084 if (s.support.transforms3d) { 3085 sb.drag.transform('translate3d(' + (newPos) + 'px, 0, 0)'); 3086 } 3087 else { 3088 sb.drag.transform('translateX(' + (newPos) + 'px)'); 3089 } 3090 sb.drag[0].style.width = newSize + 'px'; 3091 } 3092 else { 3093 if (s.support.transforms3d) { 3094 sb.drag.transform('translate3d(0px, ' + (newPos) + 'px, 0)'); 3095 } 3096 else { 3097 sb.drag.transform('translateY(' + (newPos) + 'px)'); 3098 } 3099 sb.drag[0].style.height = newSize + 'px'; 3100 } 3101 if (s.params.scrollbarHide) { 3102 clearTimeout(sb.timeout); 3103 sb.track[0].style.opacity = 1; 3104 sb.timeout = setTimeout(function () { 3105 sb.track[0].style.opacity = 0; 3106 sb.track.transition(400); 3107 }, 1000); 3108 } 3109 }, 3110 setTransition: function (duration) { 3111 if (!s.params.scrollbar) return; 3112 s.scrollbar.drag.transition(duration); 3113 } 3114 }; 3115 3116 3117 /*========================= 3118 Controller 3119 ===========================*/ 3120 s.controller = { 3121 LinearSpline: function (x, y) { 3122 var binarySearch = (function () { 3123 var maxIndex, minIndex, guess; 3124 return function (array, val) { 3125 minIndex = -1; 3126 maxIndex = array.length; 3127 while (maxIndex - minIndex > 1)
3128 if (array[guess = maxIndex + minIndex >> 1] <= val) { 3129 minIndex = guess; 3130 } else { 3131 maxIndex = guess; 3132 } 3133 return maxIndex; 3134 }; 3135 })(); 3136 this.x = x; 3137 this.y = y; 3138 this.lastIndex = x.length - 1; 3139 // Given an x value (x2), return the expected y2 value: 3140 // (x1,y1) is the known point before given value, 3141 // (x3,y3) is the known point after given value. 3142 var i1, i3; 3143 var l = this.x.length; 3144 3145 this.interpolate = function (x2) { 3146 if (!x2) return 0; 3147 3148 // Get the indexes of x1 and x3 (the array indexes before and after given x2): 3149 i3 = binarySearch(this.x, x2); 3150 i1 = i3 - 1; 3151 3152 // We have our indexes i1 & i3, so we can calculate already: 3153 // y2 := ((x2−x1) × (y3−y1)) ÷ (x3−x1) + y1 3154 return ((x2 - this.x[i1]) * (this.y[i3] - this.y[i1])) / (this.x[i3] - this.x[i1]) + this.y[i1]; 3155 }; 3156 }, 3157 //xxx: for now i will just save one spline function to to 3158 getInterpolateFunction: function (c) { 3159 if (!s.controller.spline) s.controller.spline = s.params.loop ? 3160 new s.controller.LinearSpline(s.slidesGrid, c.slidesGrid) : 3161 new s.controller.LinearSpline(s.snapGrid, c.snapGrid); 3162 }, 3163 setTranslate: function (translate, byController) { 3164 var controlled = s.params.control; 3165 var multiplier, controlledTranslate; 3166 function setControlledTranslate(c) { 3167 // this will create an Interpolate function based on the snapGrids 3168 // x is the Grid of the scrolled scroller and y will be the controlled scroller 3169 // it makes sense to create this only once and recall it for the interpolation 3170 // the function does a lot of value caching for performance 3171 translate = c.rtl && c.params.direction === 'horizontal' ? -s.translate : s.translate; 3172 if (s.params.controlBy === 'slide') { 3173 s.controller.getInterpolateFunction(c); 3174 // i am not sure why the values have to be multiplicated this way, tried to invert the snapGrid 3175 // but it did not work out 3176 controlledTranslate = -s.controller.spline.interpolate(-translate); 3177 } 3178 3179 if (!controlledTranslate || s.params.controlBy === 'container') { 3180 multiplier = (c.maxTranslate() - c.minTranslate()) / (s.maxTranslate() - s.minTranslate()); 3181 controlledTranslate = (translate - s.minTranslate()) * multiplier + c.minTranslate(); 3182 } 3183 3184 if (s.params.controlInverse) { 3185 controlledTranslate = c.maxTranslate() - controlledTranslate; 3186 } 3187 c.updateProgress(controlledTranslate); 3188 c.setWrapperTranslate(controlledTranslate, false, s); 3189 c.updateActiveIndex(); 3190 } 3191 if (Array.isArray(controlled)) { 3192 for (var i = 0; i < controlled.length; i++) { 3193 if (controlled[i] !== byController && controlled[i] instanceof Swiper) { 3194 setControlledTranslate(controlled[i]); 3195 } 3196 } 3197 } 3198 else if (controlled instanceof Swiper && byController !== controlled) { 3199 3200 setControlledTranslate(controlled); 3201 } 3202 }, 3203 setTransition: function (duration, byController) { 3204 var controlled = s.params.control; 3205 var i; 3206 function setControlledTransition(c) { 3207 c.setWrapperTransition(duration, s); 3208 if (duration !== 0) { 3209 c.onTransitionStart(); 3210 c.wrapper.transitionEnd(function () { 3211 if (!controlled) return; 3212 if (c.params.loop && s.params.controlBy === 'slide') { 3213 c.fixLoop(); 3214 } 3215 c.onTransitionEnd(); 3216 3217 }); 3218 } 3219 } 3220 if (Array.isArray(controlled)) { 3221 for (i = 0; i < controlled.length; i++) { 3222 if (controlled[i] !== byController && controlled[i] instanceof Swiper) { 3223 setControlledTransition(controlled[i]); 3224 } 3225 } 3226 } 3227 else if (controlled instanceof Swiper && byController !== controlled) { 3228 setControlledTransition(controlled); 3229 } 3230 } 3231 }; 3232 3233 3234 /*========================= 3235 Hash Navigation 3236 ===========================*/ 3237 s.hashnav = { 3238 onHashCange: function (e, a) { 3239 var newHash = document.location.hash.replace('#', ''); 3240 var activeSlideHash = s.slides.eq(s.activeIndex).attr('data-hash'); 3241 if (newHash !== activeSlideHash) { 3242 s.slideTo(s.wrapper.children('.' + s.params.slideClass + '[data-hash="' + (newHash) + '"]').index()); 3243 } 3244 }, 3245 attachEvents: function (detach) { 3246 var action = detach ? 'off' : 'on'; 3247 $(window)[action]('hashchange', s.hashnav.onHashCange); 3248 }, 3249 setHash: function () { 3250 if (!s.hashnav.initialized || !s.params.hashnav) return; 3251 if (s.params.replaceState && window.history && window.history.replaceState) { 3252 window.history.replaceState(null, null, ('#' + s.slides.eq(s.activeIndex).attr('data-hash') || '')); 3253 } else { 3254 var slide = s.slides.eq(s.activeIndex); 3255 var hash = slide.attr('data-hash') || slide.attr('data-history'); 3256 document.location.hash = hash || ''; 3257 } 3258 }, 3259 init: function () { 3260 if (!s.params.hashnav || s.params.history) return; 3261 s.hashnav.initialized = true; 3262 var hash = document.location.hash.replace('#', ''); 3263 if (hash) { 3264 var speed = 0; 3265 for (var i = 0, length = s.slides.length; i < length; i++) { 3266 var slide = s.slides.eq(i); 3267 var slideHash = slide.attr('data-hash') || slide.attr('data-history'); 3268 if (slideHash === hash && !slide.hasClass(s.params.slideDuplicateClass)) { 3269 var index = slide.index(); 3270 s.slideTo(index, speed, s.params.runCallbacksOnInit, true); 3271 } 3272 } 3273 } 3274 if (s.params.hashnavWatchState) s.hashnav.attachEvents(); 3275 }, 3276 destroy: function () { 3277 if (s.params.hashnavWatchState) s.hashnav.attachEvents(true); 3278 } 3279 }; 3280 3281 3282 /*========================= 3283 History Api with fallback to Hashnav 3284 ===========================*/ 3285 s.history = { 3286 init: function () { 3287 if (!s.params.history) return; 3288 if (!window.history || !window.history.pushState) { 3289 s.params.history = false;
3290 s.params.hashnav = true; 3291 return; 3292 } 3293 s.history.initialized = true; 3294 this.paths = this.getPathValues(); 3295 if (!this.paths.key && !this.paths.value) return; 3296 this.scrollToSlide(0, this.paths.value, s.params.runCallbacksOnInit); 3297 if (!s.params.replaceState) { 3298 window.addEventListener('popstate', this.setHistoryPopState); 3299 } 3300 }, 3301 setHistoryPopState: function () { 3302 s.history.paths = s.history.getPathValues(); 3303 s.history.scrollToSlide(s.params.speed, s.history.paths.value, false); 3304 }, 3305 getPathValues: function () { 3306 var pathArray = window.location.pathname.slice(1).split('/'); 3307 var total = pathArray.length; 3308 var key = pathArray[total - 2]; 3309 var value = pathArray[total - 1]; 3310 return { key: key, value: value }; 3311 }, 3312 setHistory: function (key, index) { 3313 if (!s.history.initialized || !s.params.history) return; 3314 var slide = s.slides.eq(index); 3315 var value = this.slugify(slide.attr('data-history')); 3316 if (!window.location.pathname.includes(key)) { 3317 value = key + '/' + value; 3318 } 3319 if (s.params.replaceState) { 3320 window.history.replaceState(null, null, value); 3321 } else { 3322 window.history.pushState(null, null, value); 3323 } 3324 }, 3325 slugify: function (text) { 3326 return text.toString().toLowerCase() 3327 .replace(/\s+/g, '-') 3328 .replace(/[^\w\-]+/g, '') 3329 .replace(/\-\-+/g, '-') 3330 .replace(/^-+/, '') 3331 .replace(/-+$/, ''); 3332 }, 3333 scrollToSlide: function (speed, value, runCallbacks) { 3334 if (value) { 3335 for (var i = 0, length = s.slides.length; i < length; i++) { 3336 var slide = s.slides.eq(i); 3337 var slideHistory = this.slugify(slide.attr('data-history')); 3338 if (slideHistory === value && !slide.hasClass(s.params.slideDuplicateClass)) { 3339 var index = slide.index(); 3340 s.slideTo(index, speed, runCallbacks); 3341 } 3342 } 3343 } else { 3344 s.slideTo(0, speed, runCallbacks); 3345 } 3346 } 3347 }; 3348 3349 3350 /*========================= 3351 Keyboard Control 3352 ===========================*/ 3353 function handleKeyboard(e) { 3354 if (e.originalEvent) e = e.originalEvent; //jquery fix 3355 var kc = e.keyCode || e.charCode; 3356 // Directions locks 3357 if (!s.params.allowSwipeToNext && (s.isHorizontal() && kc === 39 || !s.isHorizontal() && kc === 40)) { 3358 return false; 3359 } 3360 if (!s.params.allowSwipeToPrev && (s.isHorizontal() && kc === 37 || !s.isHorizontal() && kc === 38)) { 3361 return false; 3362 } 3363 if (e.shiftKey || e.altKey || e.ctrlKey || e.metaKey) { 3364 return; 3365 } 3366 if (document.activeElement && document.activeElement.nodeName && (document.activeElement.nodeName.toLowerCase() === 'input' || document.activeElement.nodeName.toLowerCase() === 'textarea')) { 3367 return; 3368 } 3369 if (kc === 37 || kc === 39 || kc === 38 || kc === 40) { 3370 var inView = false; 3371 //Check that swiper should be inside of visible area of window 3372 if (s.container.parents('.' + s.params.slideClass).length > 0 && s.container.parents('.' + s.params.slideActiveClass).length === 0) { 3373 return; 3374 } 3375 var windowScroll = { 3376 left: window.pageXOffset, 3377 top: window.pageYOffset 3378 }; 3379 var windowWidth = window.innerWidth; 3380 var windowHeight = window.innerHeight; 3381 var swiperOffset = s.container.offset(); 3382 if (s.rtl) swiperOffset.left = swiperOffset.left - s.container[0].scrollLeft; 3383 var swiperCoord = [ 3384 [swiperOffset.left, swiperOffset.top], 3385 [swiperOffset.left + s.width, swiperOffset.top], 3386 [swiperOffset.left, swiperOffset.top + s.height], 3387 [swiperOffset.left + s.width, swiperOffset.top + s.height] 3388 ]; 3389 for (var i = 0; i < swiperCoord.length; i++) { 3390 var point = swiperCoord[i]; 3391 if ( 3392 point[0] >= windowScroll.left && point[0] <= windowScroll.left + windowWidth && 3393 point[1] >= windowScroll.top && point[1] <= windowScroll.top + windowHeight 3394 ) { 3395 inView = true; 3396 } 3397 3398 } 3399 if (!inView) return; 3400 } 3401 if (s.isHorizontal()) { 3402 if (kc === 37 || kc === 39) { 3403 if (e.preventDefault) e.preventDefault(); 3404 else e.returnValue = false;
3405 } 3406 if ((kc === 39 && !s.rtl) || (kc === 37 && s.rtl)) s.slideNext(); 3407 if ((kc === 37 && !s.rtl) || (kc === 39 && s.rtl)) s.slidePrev(); 3408 } 3409 else { 3410 if (kc === 38 || kc === 40) { 3411 if (e.preventDefault) e.preventDefault(); 3412 else e.returnValue = false; 3413 } 3414 if (kc === 40) s.slideNext(); 3415 if (kc === 38) s.slidePrev(); 3416 } 3417 s.emit('onKeyPress', s, kc); 3418 } 3419 s.disableKeyboardControl = function () { 3420 s.params.keyboardControl = false; 3421 $(document).off('keydown', handleKeyboard); 3422 }; 3423 s.enableKeyboardControl = function () { 3424 s.params.keyboardControl = true; 3425 $(document).on('keydown', handleKeyboard); 3426 }; 3427 3428 3429 /*========================= 3430 Mousewheel Control 3431 ===========================*/ 3432 s.mousewheel = { 3433 event: false, 3434 lastScrollTime: (new window.Date()).getTime() 3435 }; 3436 function isEventSupported() { 3437 var eventName = 'onwheel'; 3438 var isSupported = eventName in document; 3439 3440 if (!isSupported) { 3441 var element = document.createElement('div'); 3442 element.setAttribute(eventName, 'return;'); 3443 isSupported = typeof element[eventName] === 'function'; 3444 } 3445 3446 if (!isSupported && 3447 document.implementation && 3448 document.implementation.hasFeature && 3449 // always returns true in newer browsers as per the standard. 3450 // @see http://dom.spec.whatwg.org/#dom-domimplementation-hasfeature 3451 document.implementation.hasFeature('', '') !== true) { 3452 // This is the only way to test support for the `wheel` event in IE9+. 3453 isSupported = document.implementation.hasFeature('Events.wheel', '3.0'); 3454 } 3455 3456 return isSupported; 3457 } 3458 /** 3459 * Mouse wheel (and 2-finger trackpad) support on the web sucks. It is 3460 * complicated, thus this doc is long and (hopefully) detailed enough to answer 3461 * your questions. 3462 * 3463 * If you need to react to the mouse wheel in a predictable way, this code is 3464 * like your bestest friend. * hugs * 3465 * 3466 * As of today, there are 4 DOM event types you can listen to: 3467 * 3468 * 'wheel' -- Chrome(31+), FF(17+), IE(9+) 3469 * 'mousewheel' -- Chrome, IE(6+), Opera, Safari 3470 * 'MozMousePixelScroll' -- FF(3.5 only!) (2010-2013) -- don't bother! 3471 * 'DOMMouseScroll' -- FF(0.9.7+) since 2003 3472 * 3473 * So what to do? The is the best: 3474 * 3475 * normalizeWheel.getEventType(); 3476 * 3477 * In your event callback, use this code to get sane interpretation of the 3478 * deltas. This code will return an object with properties: 3479 * 3480 * spinX -- normalized spin speed (use for zoom) - x plane 3481 * spinY -- " - y plane 3482 * pixelX -- normalized distance (to pixels) - x plane 3483 * pixelY -- " - y plane 3484 * 3485 * Wheel values are provided by the browser assuming you are using the wheel to
3486 * scroll a web page by a number of lines or pixels (or pages). Values can vary 3487 * significantly on different platforms and browsers, forgetting that you can 3488 * scroll at different speeds. Some devices (like trackpads) emit more events 3489 * at smaller increments with fine granularity, and some emit massive jumps with 3490 * linear speed or acceleration. 3491 * 3492 * This code does its best to normalize the deltas for you: 3493 * 3494 * - spin is trying to normalize how far the wheel was spun (or trackpad 3495 * dragged). This is super useful for zoom support where you want to 3496 * throw away the chunky scroll steps on the PC and make those equal to 3497 * the slow and smooth tiny steps on the Mac. Key data: This code tries to 3498 * resolve a single slow step on a wheel to 1. 3499 * 3500 * - pixel is normalizing the desired scroll delta in pixel units. You'll 3501 * get the crazy differences between browsers, but at least it'll be in 3502 * pixels! 3503 * 3504 * - positive value indicates scrolling DOWN/RIGHT, negative UP/LEFT. This 3505 * should translate to positive value zooming IN, negative zooming OUT. 3506 * This matches the newer 'wheel' event. 3507 * 3508 * Why are there spinX, spinY (or pixels)? 3509 * 3510 * - spinX is a 2-finger side drag on the trackpad, and a shift + wheel turn 3511 * with a mouse. It results in side-scrolling in the browser by default. 3512 * 3513 * - spinY is what you expect -- it's the classic axis of a mouse wheel. 3514 * 3515 * - I dropped spinZ/pixelZ. It is supported by the DOM 3 'wheel' event and 3516 * probably is by browsers in conjunction with fancy 3D controllers .. but 3517 * you know. 3518 * 3519 * Implementation info: 3520 * 3521 * Examples of 'wheel' event if you scroll slowly (down) by one step with an 3522 * average mouse: 3523 * 3524 * OS X + Chrome (mouse) - 4 pixel delta (wheelDelta -120) 3525 * OS X + Safari (mouse) - N/A pixel delta (wheelDelta -12) 3526 * OS X + Firefox (mouse) - 0.1 line delta (wheelDelta N/A) 3527 * Win8 + Chrome (mouse) - 100 pixel delta (wheelDelta -120) 3528 * Win8 + Firefox (mouse) - 3 line delta (wheelDelta -120) 3529 * 3530 * On the trackpad: 3531 * 3532 * OS X + Chrome (trackpad) - 2 pixel delta (wheelDelta -6) 3533 * OS X + Firefox (trackpad) - 1 pixel delta (wheelDelta N/A) 3534 * 3535 * On other/older browsers.. it's more complicated as there can be multiple and 3536 * also missing delta values. 3537 * 3538 * The 'wheel' event is more standard: 3539 * 3540 * http://www.w3.org/TR/DOM-Level-3-Events/#events-wheelevents 3541 * 3542 * The basics is that it includes a unit, deltaMode (pixels, lines, pages), and 3543 * deltaX, deltaY and deltaZ. Some browsers provide other values to maintain 3544 * backward compatibility with older events. Those other values help us 3545 * better normalize spin speed. Example of what the browsers provide: 3546 * 3547 * | event.wheelDelta | event.detail 3548 * ------------------+------------------+-------------- 3549 * Safari v5/OS X | -120 | 0 3550 * Safari v5/Win7 | -120 | 0 3551 * Chrome v17/OS X | -120 | 0 3552 * Chrome v17/Win7 | -120 | 0 3553 * IE9/Win7 | -120 | undefined 3554 * Firefox v4/OS X | undefined | 1 3555 * Firefox v4/Win7 | undefined | 3 3556 * 3557 */ 3558 function normalizeWheel( /*object*/ event) /*object*/ { 3559 // Reasonable defaults 3560 var PIXEL_STEP = 10; 3561 var LINE_HEIGHT = 40; 3562 var PAGE_HEIGHT = 800; 3563 3564 var sX = 0, sY = 0, // spinX, spinY 3565 pX = 0, pY = 0; // pixelX, pixelY 3566 3567 // Legacy 3568 if ('detail' in event) { 3569 sY = event.detail; 3570 } 3571 if ('wheelDelta' in event) { 3572 sY = -event.wheelDelta / 120; 3573 } 3574 if ('wheelDeltaY' in event) { 3575 sY = -event.wheelDeltaY / 120; 3576 } 3577 if ('wheelDeltaX' in event) { 3578 sX = -event.wheelDeltaX / 120; 3579 } 3580 3581 // side scrolling on FF with DOMMouseScroll 3582 if ('axis' in event && event.axis === event.HORIZONTAL_AXIS) { 3583 sX = sY; 3584 sY = 0; 3585 } 3586 3587 pX = sX * PIXEL_STEP; 3588 pY = sY * PIXEL_STEP; 3589 3590 if ('deltaY' in event) { 3591 pY = event.deltaY; 3592 } 3593 if ('deltaX' in event) { 3594 pX = event.deltaX; 3595 } 3596 3597 if ((pX || pY) && event.deltaMode) { 3598 if (event.deltaMode === 1) { // delta in LINE units 3599 pX *= LINE_HEIGHT; 3600 pY *= LINE_HEIGHT; 3601 } else { // delta in PAGE units 3602 pX *= PAGE_HEIGHT; 3603 pY *= PAGE_HEIGHT; 3604 } 3605 } 3606 3607 // Fall-back if spin cannot be determined 3608 if (pX && !sX) { 3609 sX = (pX < 1) ? -1 : 1; 3610 } 3611 if (pY && !sY) { 3612 sY = (pY < 1) ? -1 : 1; 3613 } 3614 3615 return { 3616 spinX: sX, 3617 spinY: sY, 3618 pixelX: pX, 3619 pixelY: pY 3620 }; 3621 } 3622 if (s.params.mousewheelControl) { 3623 /** 3624 * The best combination if you prefer spinX + spinY normalization. It favors 3625 * the older DOMMouseScroll for Firefox, as FF does not include wheelDelta with 3626 * 'wheel' event, making spin speed determination impossible. 3627 */ 3628 s.mousewheel.event = (navigator.userAgent.indexOf('firefox') > -1) ? 3629 'DOMMouseScroll' : 3630 isEventSupported() ? 3631 'wheel' : 'mousewheel'; 3632 } 3633 function handleMousewheel(e) { 3634 if (e.originalEvent) e = e.originalEvent; //jquery fix 3635 var delta = 0; 3636 var rtlFactor = s.rtl ? -1 : 1; 3637 3638 var data = normalizeWheel(e); 3639 3640 if (s.params.mousewheelForceToAxis) { 3641 if (s.isHorizontal()) { 3642 if (Math.abs(data.pixelX) > Math.abs(data.pixelY)) delta = data.pixelX * rtlFactor; 3643 else return; 3644 } 3645 else { 3646 if (Math.abs(data.pixelY) > Math.abs(data.pixelX)) delta = data.pixelY; 3647 else return; 3648 } 3649 } 3650 else { 3651 delta = Math.abs(data.pixelX) > Math.abs(data.pixelY) ? - data.pixelX * rtlFactor : - data.pixelY; 3652 } 3653 3654 if (delta === 0) return; 3655 3656 if (s.params.mousewheelInvert) delta = -delta; 3657 3658 if (!s.params.freeMode) { 3659 if ((new window.Date()).getTime() - s.mousewheel.lastScrollTime > 60) { 3660 if (delta < 0) { 3661 if ((!s.isEnd || s.params.loop) && !s.animating) { 3662 s.slideNext(); 3663 s.emit('onScroll', s, e); 3664 } 3665 else if (s.params.mousewheelReleaseOnEdges) return true; 3666 } 3667 else {
3668 if ((!s.isBeginning || s.params.loop) && !s.animating) { 3669 s.slidePrev(); 3670 s.emit('onScroll', s, e); 3671 } 3672 else if (s.params.mousewheelReleaseOnEdges) return true; 3673 } 3674 } 3675 s.mousewheel.lastScrollTime = (new window.Date()).getTime(); 3676 3677 } 3678 else { 3679 //Freemode or scrollContainer: 3680 var position = s.getWrapperTranslate() + delta * s.params.mousewheelSensitivity; 3681 var wasBeginning = s.isBeginning, 3682 wasEnd = s.isEnd; 3683 3684 if (position >= s.minTranslate()) position = s.minTranslate(); 3685 if (position <= s.maxTranslate()) position = s.maxTranslate(); 3686 3687 s.setWrapperTransition(0); 3688 s.setWrapperTranslate(position); 3689 s.updateProgress(); 3690 s.updateActiveIndex(); 3691 3692 if (!wasBeginning && s.isBeginning || !wasEnd && s.isEnd) { 3693 s.updateClasses(); 3694 } 3695 3696 if (s.params.freeModeSticky) { 3697 clearTimeout(s.mousewheel.timeout); 3698 s.mousewheel.timeout = setTimeout(function () { 3699 s.slideReset(); 3700 }, 300); 3701 } 3702 else { 3703 if (s.params.lazyLoading && s.lazy) { 3704 s.lazy.load(); 3705 } 3706 } 3707 // Emit event 3708 s.emit('onScroll', s, e); 3709 3710 // Stop autoplay 3711 if (s.params.autoplay && s.params.autoplayDisableOnInteraction) s.stopAutoplay(); 3712 3713 // Return page scroll on edge positions 3714 if (position === 0 || position === s.maxTranslate()) return; 3715 } 3716 3717 if (e.preventDefault) e.preventDefault(); 3718 else e.returnValue = false; 3719 return false; 3720 } 3721 s.disableMousewheelControl = function () { 3722 if (!s.mousewheel.event) return false; 3723 var target = s.container; 3724 if (s.params.mousewheelEventsTarged !== 'container') { 3725 target = $(s.params.mousewheelEventsTarged); 3726 } 3727 target.off(s.mousewheel.event, handleMousewheel); 3728 s.params.mousewheelControl = false; 3729 return true; 3730 }; 3731 3732 s.enableMousewheelControl = function () { 3733 if (!s.mousewheel.event) return false; 3734 var target = s.container; 3735 if (s.params.mousewheelEventsTarged !== 'container') { 3736 target = $(s.params.mousewheelEventsTarged); 3737 } 3738 target.on(s.mousewheel.event, handleMousewheel); 3739 s.params.mousewheelControl = true; 3740 return true; 3741 }; 3742 3743 3744 /*========================= 3745 Parallax 3746 ===========================*/ 3747 function setParallaxTransform(el, progress) { 3748 el = $(el); 3749 var p, pX, pY; 3750 var rtlFactor = s.rtl ? -1 : 1; 3751 3752 p = el.attr('data-swiper-parallax') || '0'; 3753 pX = el.attr('data-swiper-parallax-x'); 3754 pY = el.attr('data-swiper-parallax-y'); 3755 if (pX || pY) { 3756 pX = pX || '0'; 3757 pY = pY || '0'; 3758 } 3759 else { 3760 if (s.isHorizontal()) { 3761 pX = p; 3762 pY = '0'; 3763 } 3764 else { 3765 pY = p; 3766 pX = '0'; 3767 } 3768 } 3769 3770 if ((pX).indexOf('%') >= 0) { 3771 pX = parseInt(pX, 10) * progress * rtlFactor + '%'; 3772 } 3773 else { 3774 pX = pX * progress * rtlFactor + 'px'; 3775 } 3776 if ((pY).indexOf('%') >= 0) { 3777 pY = parseInt(pY, 10) * progress + '%'; 3778 } 3779 else { 3780 pY = pY * progress + 'px'; 3781 } 3782 3783 el.transform('translate3d(' + pX + ', ' + pY + ',0px)'); 3784 } 3785 s.parallax = { 3786 setTranslate: function () { 3787 s.container.children('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y]').each(function () { 3788 setParallaxTransform(this, s.progress); 3789 3790 }); 3791 s.slides.each(function () { 3792 var slide = $(this); 3793 slide.find('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y]').each(function () { 3794 var progress = Math.min(Math.max(slide[0].progress, -1), 1); 3795 setParallaxTransform(this, progress); 3796 }); 3797 }); 3798 }, 3799 setTransition: function (duration) { 3800 if (typeof duration === 'undefined') duration = s.params.speed; 3801 s.container.find('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y]').each(function () { 3802 var el = $(this); 3803 var parallaxDuration = parseInt(el.attr('data-swiper-parallax-duration'), 10) || duration; 3804 if (duration === 0) parallaxDuration = 0; 3805 el.transition(parallaxDuration); 3806 }); 3807 } 3808 }; 3809 3810 3811 /*========================= 3812 Zoom 3813 ===========================*/ 3814 s.zoom = { 3815 // "Global" Props 3816 scale: 1, 3817 currentScale: 1, 3818 isScaling: false, 3819 gesture: { 3820 slide: undefined, 3821 slideWidth: undefined, 3822 slideHeight: undefined, 3823 image: undefined, 3824 imageWrap: undefined, 3825 zoomMax: s.params.zoomMax 3826 }, 3827 image: { 3828 isTouched: undefined, 3829 isMoved: undefined, 3830 currentX: undefined, 3831 currentY: undefined, 3832 minX: undefined, 3833 minY: undefined, 3834 maxX: undefined, 3835 maxY: undefined, 3836 width: undefined, 3837 height: undefined, 3838 startX: undefined, 3839 startY: undefined, 3840 touchesStart: {}, 3841 touchesCurrent: {} 3842 }, 3843 velocity: { 3844 x: undefined, 3845 y: undefined, 3846 prevPositionX: undefined, 3847 prevPositionY: undefined, 3848 prevTime: undefined 3849 }, 3850 // Calc Scale From Multi-touches 3851 getDistanceBetweenTouches: function (e) { 3852 if (e.targetTouches.length < 2) return 1; 3853 var x1 = e.targetTouches[0].pageX, 3854 y1 = e.targetTouches[0].pageY, 3855 x2 = e.targetTouches[1].pageX, 3856 y2 = e.targetTouches[1].pageY; 3857 var distance = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)); 3858 return distance; 3859 }, 3860 // Events 3861 onGestureStart: function (e) { 3862 var z = s.zoom; 3863 if (!s.support.gestures) { 3864 if (e.type !== 'touchstart' || e.type === 'touchstart' && e.targetTouches.length < 2) { 3865 return; 3866 } 3867 z.gesture.scaleStart = z.getDistanceBetweenTouches(e); 3868 } 3869 if (!z.gesture.slide || !z.gesture.slide.length) { 3870 z.gesture.slide = $(this); 3871 if (z.gesture.slide.length === 0) z.gesture.slide = s.slides.eq(s.activeIndex); 3872 z.gesture.image = z.gesture.slide.find('img, svg, canvas'); 3873 z.gesture.imageWrap = z.gesture.image.parent('.' + s.params.zoomContainerClass); 3874 z.gesture.zoomMax = z.gesture.imageWrap.attr('data-swiper-zoom') || s.params.zoomMax; 3875 if (z.gesture.imageWrap.length === 0) { 3876 z.gesture.image = undefined; 3877 return; 3878 } 3879 } 3880 z.gesture.image.transition(0); 3881 z.isScaling = true; 3882 }, 3883 onGestureChange: function (e) { 3884 var z = s.zoom; 3885 if (!s.support.gestures) { 3886 if (e.type !== 'touchmove' || e.type === 'touchmove' && e.targetTouches.length < 2) { 3887 return; 3888 } 3889 z.gesture.scaleMove = z.getDistanceBetweenTouches(e); 3890 } 3891 if (!z.gesture.image || z.gesture.image.length === 0) return; 3892 if (s.support.gestures) { 3893 z.scale = e.scale * z.currentScale; 3894 } 3895 else { 3896 z.scale = (z.gesture.scaleMove / z.gesture.scaleStart) * z.currentScale; 3897 } 3898 if (z.scale > z.gesture.zoomMax) { 3899 z.scale = z.gesture.zoomMax - 1 + Math.pow((z.scale - z.gesture.zoomMax + 1), 0.5); 3900 } 3901 if (z.scale < s.params.zoomMin) { 3902 z.scale = s.params.zoomMin + 1 - Math.pow((s.params.zoomMin - z.scale + 1), 0.5); 3903 }
3904 z.gesture.image.transform('translate3d(0,0,0) scale(' + z.scale + ')'); 3905 }, 3906 onGestureEnd: function (e) { 3907 var z = s.zoom; 3908 if (!s.support.gestures) { 3909 if (e.type !== 'touchend' || e.type === 'touchend' && e.changedTouches.length < 2) { 3910 return; 3911 } 3912 } 3913 if (!z.gesture.image || z.gesture.image.length === 0) return; 3914 z.scale = Math.max(Math.min(z.scale, z.gesture.zoomMax), s.params.zoomMin); 3915 z.gesture.image.transition(s.params.speed).transform('translate3d(0,0,0) scale(' + z.scale + ')'); 3916 z.currentScale = z.scale; 3917 z.isScaling = false; 3918 if (z.scale === 1) z.gesture.slide = undefined; 3919 }, 3920 onTouchStart: function (s, e) { 3921 var z = s.zoom; 3922 if (!z.gesture.image || z.gesture.image.length === 0) return; 3923 if (z.image.isTouched) return; 3924 if (s.device.os === 'android') e.preventDefault(); 3925 z.image.isTouched = true; 3926 z.image.touchesStart.x = e.type === 'touchstart' ? e.targetTouches[0].pageX : e.pageX; 3927 z.image.touchesStart.y = e.type === 'touchstart' ? e.targetTouches[0].pageY : e.pageY; 3928 }, 3929 onTouchMove: function (e) { 3930 var z = s.zoom; 3931 if (!z.gesture.image || z.gesture.image.length === 0) return; 3932 s.allowClick = false; 3933 if (!z.image.isTouched || !z.gesture.slide) return; 3934 3935 if (!z.image.isMoved) { 3936 z.image.width = z.gesture.image[0].offsetWidth; 3937 z.image.height = z.gesture.image[0].offsetHeight; 3938 z.image.startX = s.getTranslate(z.gesture.imageWrap[0], 'x') || 0; 3939 z.image.startY = s.getTranslate(z.gesture.imageWrap[0], 'y') || 0; 3940 z.gesture.slideWidth = z.gesture.slide[0].offsetWidth; 3941 z.gesture.slideHeight = z.gesture.slide[0].offsetHeight; 3942 z.gesture.imageWrap.transition(0); 3943 if (s.rtl) z.image.startX = -z.image.startX; 3944 if (s.rtl) z.image.startY = -z.image.startY; 3945 } 3946 // Define if we need image drag 3947 var scaledWidth = z.image.width * z.scale; 3948 var scaledHeight = z.image.height * z.scale; 3949 3950 if (scaledWidth < z.gesture.slideWidth && scaledHeight < z.gesture.slideHeight) return; 3951 3952 z.image.minX = Math.min((z.gesture.slideWidth / 2 - scaledWidth / 2), 0); 3953 z.image.maxX = -z.image.minX; 3954 z.image.minY = Math.min((z.gesture.slideHeight / 2 - scaledHeight / 2), 0); 3955 z.image.maxY = -z.image.minY; 3956 3957 z.image.touchesCurrent.x = e.type === 'touchmove' ? e.targetTouches[0].pageX : e.pageX; 3958 z.image.touchesCurrent.y = e.type === 'touchmove' ? e.targetTouches[0].pageY : e.pageY; 3959 3960 if (!z.image.isMoved && !z.isScaling) { 3961 if (s.isHorizontal() && 3962 (Math.floor(z.image.minX) === Math.floor(z.image.startX) && z.image.touchesCurrent.x < z.image.touchesStart.x) || 3963 (Math.floor(z.image.maxX) === Math.floor(z.image.startX) && z.image.touchesCurrent.x > z.image.touchesStart.x) 3964 ) { 3965 z.image.isTouched = false; 3966 return; 3967 } 3968 else if (!s.isHorizontal() && 3969 (Math.floor(z.image.minY) === Math.floor(z.image.startY) && z.image.touchesCurrent.y < z.image.touchesStart.y) || 3970 (Math.floor(z.image.maxY) === Math.floor(z.image.startY) && z.image.touchesCurrent.y > z.image.touchesStart.y) 3971 ) { 3972 z.image.isTouched = false; 3973 return; 3974 } 3975 } 3976 e.preventDefault(); 3977 e.stopPropagation(); 3978 3979 z.image.isMoved = true; 3980 z.image.currentX = z.image.touchesCurrent.x - z.image.touchesStart.x + z.image.startX; 3981 z.image.currentY = z.image.touchesCurrent.y - z.image.touchesStart.y + z.image.startY; 3982 3983 if (z.image.currentX < z.image.minX) { 3984 z.image.currentX = z.image.minX + 1 - Math.pow((z.image.minX - z.image.currentX + 1), 0.8); 3985 } 3986 if (z.image.currentX > z.image.maxX) { 3987 z.image.currentX = z.image.maxX - 1 + Math.pow((z.image.currentX - z.image.maxX + 1), 0.8); 3988 } 3989 3990 if (z.image.currentY < z.image.minY) { 3991 z.image.currentY = z.image.minY + 1 - Math.pow((z.image.minY - z.image.currentY + 1), 0.8); 3992 } 3993 if (z.image.currentY > z.image.maxY) { 3994 z.image.currentY = z.image.maxY - 1 + Math.pow((z.image.currentY - z.image.maxY + 1), 0.8); 3995 } 3996 3997 //Velocity 3998 if (!z.velocity.prevPositionX) z.velocity.prevPositionX = z.image.touchesCurrent.x; 3999 if (!z.velocity.prevPositionY) z.velocity.prevPositionY = z.image.touchesCurrent.y; 4000 if (!z.velocity.prevTime) z.velocity.prevTime = Date.now(); 4001 z.velocity.x = (z.image.touchesCurrent.x - z.velocity.prevPositionX) / (Date.now() - z.velocity.prevTime) / 2; 4002 z.velocity.y = (z.image.touchesCurrent.y - z.velocity.prevPositionY) / (Date.now() - z.velocity.prevTime) / 2; 4003 if (Math.abs(z.image.touchesCurrent.x - z.velocity.prevPositionX) < 2) z.velocity.x = 0; 4004 if (Math.abs(z.image.touchesCurrent.y - z.velocity.prevPositionY) < 2) z.velocity.y = 0; 4005 z.velocity.prevPositionX = z.image.touchesCurrent.x; 4006 z.velocity.prevPositionY = z.image.touchesCurrent.y; 4007 z.velocity.prevTime = Date.now(); 4008 4009 z.gesture.imageWrap.transform('translate3d(' + z.image.currentX + 'px, ' + z.image.currentY + 'px,0)'); 4010 }, 4011 onTouchEnd: function (s, e) { 4012 var z = s.zoom; 4013 if (!z.gesture.image || z.gesture.image.length === 0) return; 4014 if (!z.image.isTouched || !z.image.isMoved) { 4015 z.image.isTouched = false;
vendor: 6,037 bytes, lines 4016-4128
4016 z.image.isMoved = false; 4017 return; 4018 } 4019 z.image.isTouched = false; 4020 z.image.isMoved = false; 4021 var momentumDurationX = 300; 4022 var momentumDurationY = 300; 4023 var momentumDistanceX = z.velocity.x * momentumDurationX; 4024 var newPositionX = z.image.currentX + momentumDistanceX; 4025 var momentumDistanceY = z.velocity.y * momentumDurationY; 4026 var newPositionY = z.image.currentY + momentumDistanceY; 4027 4028 //Fix duration 4029 if (z.velocity.x !== 0) momentumDurationX = Math.abs((newPositionX - z.image.currentX) / z.velocity.x); 4030 if (z.velocity.y !== 0) momentumDurationY = Math.abs((newPositionY - z.image.currentY) / z.velocity.y); 4031 var momentumDuration = Math.max(momentumDurationX, momentumDurationY); 4032 4033 z.image.currentX = newPositionX; 4034 z.image.currentY = newPositionY; 4035 4036 // Define if we need image drag 4037 var scaledWidth = z.image.width * z.scale; 4038 var scaledHeight = z.image.height * z.scale; 4039 z.image.minX = Math.min((z.gesture.slideWidth / 2 - scaledWidth / 2), 0); 4040 z.image.maxX = -z.image.minX; 4041 z.image.minY = Math.min((z.gesture.slideHeight / 2 - scaledHeight / 2), 0); 4042 z.image.maxY = -z.image.minY; 4043 z.image.currentX = Math.max(Math.min(z.image.currentX, z.image.maxX), z.image.minX); 4044 z.image.currentY = Math.max(Math.min(z.image.currentY, z.image.maxY), z.image.minY); 4045 4046 z.gesture.imageWrap.transition(momentumDuration).transform('translate3d(' + z.image.currentX + 'px, ' + z.image.currentY + 'px,0)'); 4047 }, 4048 onTransitionEnd: function (s) { 4049 var z = s.zoom; 4050 if (z.gesture.slide && s.previousIndex !== s.activeIndex) { 4051 z.gesture.image.transform('translate3d(0,0,0) scale(1)'); 4052 z.gesture.imageWrap.transform('translate3d(0,0,0)'); 4053 z.gesture.slide = z.gesture.image = z.gesture.imageWrap = undefined; 4054 z.scale = z.currentScale = 1; 4055 } 4056 }, 4057 // Toggle Zoom 4058 toggleZoom: function (s, e) { 4059 var z = s.zoom; 4060 if (!z.gesture.slide) { 4061 z.gesture.slide = s.clickedSlide ? $(s.clickedSlide) : s.slides.eq(s.activeIndex); 4062 z.gesture.image = z.gesture.slide.find('img, svg, canvas'); 4063 z.gesture.imageWrap = z.gesture.image.parent('.' + s.params.zoomContainerClass); 4064 } 4065 if (!z.gesture.image || z.gesture.image.length === 0) return; 4066 4067 var touchX, touchY, offsetX, offsetY, diffX, diffY, translateX, translateY, imageWidth, imageHeight, scaledWidth, scaledHeight, translateMinX, translateMinY, translateMaxX, translateMaxY, slideWidth, slideHeight; 4068 4069 if (typeof z.image.touchesStart.x === 'undefined' && e) { 4070 touchX = e.type === 'touchend' ? e.changedTouches[0].pageX : e.pageX; 4071 touchY = e.type === 'touchend' ? e.changedTouches[0].pageY : e.pageY; 4072 } 4073 else { 4074 touchX = z.image.touchesStart.x; 4075 touchY = z.image.touchesStart.y; 4076 } 4077 4078 if (z.scale && z.scale !== 1) { 4079 // Zoom Out 4080 z.scale = z.currentScale = 1; 4081 z.gesture.imageWrap.transition(300).transform('translate3d(0,0,0)'); 4082 z.gesture.image.transition(300).transform('translate3d(0,0,0) scale(1)'); 4083 z.gesture.slide = undefined; 4084 } 4085 else { 4086 // Zoom In 4087 z.scale = z.currentScale = z.gesture.imageWrap.attr('data-swiper-zoom') || s.params.zoomMax; 4088 if (e) { 4089 slideWidth = z.gesture.slide[0].offsetWidth; 4090 slideHeight = z.gesture.slide[0].offsetHeight; 4091 offsetX = z.gesture.slide.offset().left; 4092 offsetY = z.gesture.slide.offset().top; 4093 diffX = offsetX + slideWidth / 2 - touchX; 4094 diffY = offsetY + slideHeight / 2 - touchY; 4095 4096 imageWidth = z.gesture.image[0].offsetWidth; 4097 imageHeight = z.gesture.image[0].offsetHeight; 4098 scaledWidth = imageWidth * z.scale; 4099 scaledHeight = imageHeight * z.scale; 4100 4101 translateMinX = Math.min((slideWidth / 2 - scaledWidth / 2), 0); 4102 translateMinY = Math.min((slideHeight / 2 - scaledHeight / 2), 0); 4103 translateMaxX = -translateMinX; 4104 translateMaxY = -translateMinY; 4105 4106 translateX = diffX * z.scale; 4107 translateY = diffY * z.scale; 4108 4109 if (translateX < translateMinX) { 4110 translateX = translateMinX; 4111 } 4112 if (translateX > translateMaxX) { 4113 translateX = translateMaxX; 4114 } 4115 4116 if (translateY < translateMinY) { 4117 translateY = translateMinY; 4118 } 4119 if (translateY > translateMaxY) { 4120 translateY = translateMaxY; 4121 } 4122 } 4123 else { 4124 translateX = 0; 4125 translateY = 0; 4126 } 4127 z.gesture.imageWrap.transition(300).transform('translate3d(' + translateX + 'px, ' + translateY + 'px,0)'); 4128 z.gesture.image.transition(300).transform('translate3d(0,
41280,0) scale(' + z.scale + ')'); 4129 } 4130 }, 4131 // Attach/Detach Events 4132 attachEvents: function (detach) { 4133 var action = detach ? 'off' : 'on'; 4134 4135 if (s.params.zoom) { 4136 var target = s.slides; 4137 var passiveListener = s.touchEvents.start === 'touchstart' && s.support.passiveListener && s.params.passiveListeners ? { passive: true, capture: false } : false; 4138 // Scale image 4139 if (s.support.gestures) { 4140 s.slides[action]('gesturestart', s.zoom.onGestureStart, passiveListener); 4141 s.slides[action]('gesturechange', s.zoom.onGestureChange, passiveListener); 4142 s.slides[action]('gestureend', s.zoom.onGestureEnd, passiveListener); 4143 } 4144 else if (s.touchEvents.start === 'touchstart') { 4145 s.slides[action](s.touchEvents.start, s.zoom.onGestureStart, passiveListener); 4146 s.slides[action](s.touchEvents.move, s.zoom.onGestureChange, passiveListener); 4147 s.slides[action](s.touchEvents.end, s.zoom.onGestureEnd, passiveListener); 4148 } 4149 4150 // Move image 4151 s[action]('touchStart', s.zoom.onTouchStart); 4152 s.slides.each(function (index, slide) { 4153 if ($(slide).find('.' + s.params.zoomContainerClass).length > 0) { 4154 $(slide)[action](s.touchEvents.move, s.zoom.onTouchMove); 4155 } 4156 }); 4157 s[action]('touchEnd', s.zoom.onTouchEnd); 4158 4159 // Scale Out 4160 s[action]('transitionEnd', s.zoom.onTransitionEnd); 4161 if (s.params.zoomToggle) { 4162 s.on('doubleTap', s.zoom.toggleZoom); 4163 } 4164 } 4165 }, 4166 init: function () { 4167 s.zoom.attachEvents(); 4168 }, 4169 destroy: function () { 4170 s.zoom.attachEvents(true); 4171 } 4172 }; 4173 4174 4175 /*========================= 4176 Plugins API. Collect all and init all plugins 4177 ===========================*/ 4178 s._plugins = []; 4179 for (var plugin in s.plugins) { 4180 var p = s.plugins[plugin](s, s.params[plugin]); 4181 if (p) s._plugins.push(p); 4182 } 4183 // Method to call all plugins event/method 4184 s.callPlugins = function (eventName) { 4185 for (var i = 0; i < s._plugins.length; i++) { 4186 if (eventName in s._plugins[i]) { 4187 s._plugins[i][eventName](arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]); 4188 } 4189 } 4190 }; 4191 4192 4193 /*========================= 4194 Events/Callbacks/Plugins Emitter 4195 ===========================*/ 4196 function normalizeEventName(eventName) { 4197 if (eventName.indexOf('on') !== 0) { 4198 if (eventName[0] !== eventName[0].toUpperCase()) { 4199 eventName = 'on' + eventName[0].toUpperCase() + eventName.substring(1); 4200 } 4201 else { 4202 eventName = 'on' + eventName; 4203 } 4204 } 4205 return eventName; 4206 } 4207 s.emitterEventListeners = { 4208 4209 }; 4210 s.emit = function (eventName) { 4211 // Trigger callbacks 4212 if (s.params[eventName]) { 4213 s.params[eventName](arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]); 4214 } 4215 var i; 4216 // Trigger events 4217 if (s.emitterEventListeners[eventName]) { 4218 for (i = 0; i < s.emitterEventListeners[eventName].length; i++) { 4219 s.emitterEventListeners[eventName][i](arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]); 4220 } 4221 } 4222 // Trigger plugins 4223 if (s.callPlugins) s.callPlugins(eventName, arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]); 4224 }; 4225 s.on = function (eventName, handler) { 4226 eventName = normalizeEventName(eventName); 4227 if (!s.emitterEventListeners[eventName]) s.emitterEventListeners[eventName] = []; 4228 s.emitterEventListeners[eventName].push(handler); 4229 return s; 4230 }; 4231 s.off = function (eventName, handler) { 4232 var i; 4233 eventName = normalizeEventName(eventName); 4234 if (typeof handler === 'undefined') { 4235 // Remove all handlers for such event 4236 s.emitterEventListeners[eventName] = []; 4237 return s; 4238 } 4239 if (!s.emitterEventListeners[eventName] || s.emitterEventListeners[eventName].length === 0) return; 4240 for (i = 0; i < s.emitterEventListeners[eventName].length; i++) { 4241 if (s.emitterEventListeners[eventName][i] === handler) s.emitterEventListeners[eventName].splice(i, 1); 4242 } 4243 return s; 4244 }; 4245 s.once = function (eventName, handler) { 4246 eventName = normalizeEventName(eventName); 4247 var _handler = function () { 4248 handler(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4]); 4249 s.off(eventName, _handler); 4250 }; 4251 s.on(eventName, _handler); 4252 return s; 4253 }; 4254 4255 4256 // Accessibility tools 4257 s.a11y = { 4258 makeFocusable: function ($el) { 4259 $el.attr('tabIndex', '0'); 4260 return $el; 4261 }, 4262 addRole: function ($el, role) { 4263 $el.attr('role', role); 4264 return $el; 4265 }, 4266 4267 addLabel: function ($el, label) { 4268 $el.attr('aria-label', label); 4269 return $el; 4270 }, 4271 4272 disable: function ($el) { 4273 $el.attr('aria-disabled', true); 4274 return $el; 4275 }, 4276 4277 enable: function ($el) { 4278 $el.attr('aria-disabled', false); 4279 return $el; 4280 }, 4281 4282 onEnterKey: function (event) { 4283 if (event.keyCode !== 13) return; 4284 if ($(event.target).is(s.params.nextButton)) { 4285 s.onClickNext(event); 4286 if (s.isEnd) { 4287 s.a11y.notify(s.params.lastSlideMessage); 4288 } 4289 else { 4290 s.a11y.notify(s.params.nextSlideMessage); 4291 } 4292 } 4293 else if ($(event.target).is(s.params.prevButton)) { 4294 s.onClickPrev(event); 4295 if (s.isBeginning) { 4296 s.a11y.notify(s.params.firstSlideMessage); 4297 } 4298 else { 4299 s.a11y.notify(s.params.prevSlideMessage); 4300 } 4301 } 4302 if ($(event.target).is('.' + s.params.bulletClass)) { 4303 $(event.target)[0].click(); 4304 } 4305 }, 4306 4307 liveRegion: $('<span class="' + s.params.notificationClass + '" aria-live="assertive" aria-atomic="true"></span>'), 4308 4309 notify: function (message) { 4310 var notification = s.a11y.liveRegion; 4311 if (notification.length === 0) return; 4312 notification.html(''); 4313 notification.html(message); 4314 }, 4315 init: function () { 4316 // Setup accessibility 4317 if (s.params.nextButton && s.nextButton && s.nextButton.length > 0) { 4318 s.a11y.makeFocusable(s.nextButton); 4319 s.a11y.addRole(s.nextButton, 'button'); 4320 s.a11y.addLabel(s.nextButton, s.params.nextSlideMessage); 4321 } 4322 if (s.params.prevButton && s.prevButton && s.prevButton.length > 0) { 4323 s.a11y.makeFocusable(s.prevButton); 4324 s.a11y.addRole(s.prevButton, 'button'); 4325 s.a11y.addLabel(s.prevButton, s.params.prevSlideMessage); 4326 } 4327 4328 $(s.container).append(s.a11y.liveRegion); 4329 }, 4330 initPagination: function () { 4331 if (s.params.pagination && s.params.paginationClickable && s.bullets && s.bullets.length) { 4332 s.bullets.each(function () { 4333 var bullet = $(this); 4334 s.a11y.makeFocusable(bullet); 4335 s.a11y.addRole(bullet, 'button'); 4336 s.a11y.addLabel(bullet, s.params.paginationBulletMessage.replace(/{{index}}/, bullet.index() + 1)); 4337 }); 4338 } 4339 }, 4340 destroy: function () { 4341 if (s.a11y.liveRegion && s.a11y.liveRegion.length > 0) s.a11y.liveRegion.remove(); 4342 } 4343 }; 4344 4345 4346 /*========================= 4347 Init/Destroy 4348 ===========================*/ 4349 s.init = function () { 4350 if (s.params.loop) s.createLoop(); 4351 s.updateContainerSize(); 4352 s.updateSlidesSize(); 4353 s.updatePagination(); 4354 if (s.params.scrollbar && s.scrollbar) { 4355 s.scrollbar.set(); 4356 if (s.params.scrollbarDraggable) { 4357 s.scrollbar.enableDraggable(); 4358 } 4359 } 4360 if (s.params.effect !== 'slide' && s.effects[s.params.effect]) { 4361 if (!s.params.loop) s.updateProgress(); 4362 s.effects[s.params.effect].setTranslate(); 4363 } 4364 if (s.params.loop) { 4365 s.slideTo(s.params.initialSlide + s.loopedSlides, 0, s.params.runCallbacksOnInit); 4366 } 4367 else { 4368 s.slideTo(s.params.initialSlide, 0, s.params.runCallbacksOnInit); 4369 if (s.params.initialSlide === 0) { 4370 if (s.parallax && s.params.parallax) s.parallax.setTranslate(); 4371 if (s.lazy && s.params.lazyLoading) { 4372 s.lazy.load(); 4373 s.lazy.initialImageLoaded = true; 4374 } 4375 } 4376 } 4377 s.attachEvents(); 4378 if (s.params.observer && s.support.observer) {
4379 s.initObservers(); 4380 } 4381 if (s.params.preloadImages && !s.params.lazyLoading) { 4382 s.preloadImages(); 4383 } 4384 if (s.params.zoom && s.zoom) { 4385 s.zoom.init(); 4386 } 4387 if (s.params.autoplay) { 4388 s.startAutoplay(); 4389 } 4390 if (s.params.keyboardControl) { 4391 if (s.enableKeyboardControl) s.enableKeyboardControl(); 4392 } 4393 if (s.params.mousewheelControl) { 4394 if (s.enableMousewheelControl) s.enableMousewheelControl(); 4395 } 4396 // Deprecated hashnavReplaceState changed to replaceState for use in hashnav and history 4397 if (s.params.hashnavReplaceState) { 4398 s.params.replaceState = s.params.hashnavReplaceState; 4399 } 4400 if (s.params.history) { 4401 if (s.history) s.history.init(); 4402 } 4403 if (s.params.hashnav) { 4404 if (s.hashnav) s.hashnav.init(); 4405 } 4406 if (s.params.a11y && s.a11y) s.a11y.init(); 4407 s.emit('onInit', s); 4408 }; 4409 4410 // Cleanup dynamic styles 4411 s.cleanupStyles = function () { 4412 // Container 4413 s.container.removeClass(s.classNames.join(' ')).removeAttr('style'); 4414 4415 // Wrapper 4416 s.wrapper.removeAttr('style'); 4417 4418 // Slides 4419 if (s.slides && s.slides.length) { 4420 s.slides 4421 .removeClass([ 4422 s.params.slideVisibleClass, 4423 s.params.slideActiveClass, 4424 s.params.slideNextClass, 4425 s.params.slidePrevClass 4426 ].join(' ')) 4427 .removeAttr('style') 4428 .removeAttr('data-swiper-column') 4429 .removeAttr('data-swiper-row'); 4430 } 4431 4432 // Pagination/Bullets 4433 if (s.paginationContainer && s.paginationContainer.length) { 4434 s.paginationContainer.removeClass(s.params.paginationHiddenClass); 4435 } 4436 if (s.bullets && s.bullets.length) { 4437 s.bullets.removeClass(s.params.bulletActiveClass); 4438 } 4439 4440 // Buttons 4441 if (s.params.prevButton) $(s.params.prevButton).removeClass(s.params.buttonDisabledClass); 4442 if (s.params.nextButton) $(s.params.nextButton).removeClass(s.params.buttonDisabledClass); 4443 4444 // Scrollbar 4445 if (s.params.scrollbar && s.scrollbar) { 4446 if (s.scrollbar.track && s.scrollbar.track.length) s.scrollbar.track.removeAttr('style'); 4447 if (s.scrollbar.drag && s.scrollbar.drag.length) s.scrollbar.drag.removeAttr('style'); 4448 } 4449 }; 4450 4451 // Destroy 4452 s.destroy = function (deleteInstance, cleanupStyles) { 4453 // Detach evebts 4454 s.detachEvents(); 4455 // Stop autoplay 4456 s.stopAutoplay(); 4457 // Disable draggable 4458 if (s.params.scrollbar && s.scrollbar) { 4459 if (s.params.scrollbarDraggable) { 4460 s.scrollbar.disableDraggable(); 4461 } 4462 } 4463 // Destroy loop 4464 if (s.params.loop) { 4465 s.destroyLoop(); 4466 } 4467 // Cleanup styles 4468 if (cleanupStyles) { 4469 s.cleanupStyles(); 4470 } 4471 // Disconnect observer 4472 s.disconnectObservers(); 4473 4474 // Destroy zoom 4475 if (s.params.zoom && s.zoom) { 4476 s.zoom.destroy(); 4477 } 4478 // Disable keyboard/mousewheel 4479 if (s.params.keyboardControl) { 4480 if (s.disableKeyboardControl) s.disableKeyboardControl(); 4481 } 4482 if (s.params.mousewheelControl) { 4483 if (s.disableMousewheelControl) s.disableMousewheelControl(); 4484 } 4485 // Disable a11y 4486 if (s.params.a11y && s.a11y) s.a11y.destroy(); 4487 // Delete history popstate 4488 if (s.params.history && !s.params.replaceState) { 4489 window.removeEventListener('popstate', s.history.setHistoryPopState); 4490 } 4491 if (s.params.hashnav && s.hashnav) { 4492 s.hashnav.destroy(); 4493 } 4494 // Destroy callback 4495 s.emit('onDestroy'); 4496 // Delete instance 4497 if (deleteInstance !== false) s = null; 4498 }; 4499 4500 s.init(); 4501 4502 4503 4504 // Return swiper instance 4505 return s; 4506 }; 4507 4508 4509 /*================================================== 4510 Prototype 4511 ====================================================*/ 4512 Swiper.prototype = { 4513 isSafari: (function () { 4514 var ua = window.navigator.userAgent.toLowerCase(); 4515 return (ua.indexOf('safari') >= 0 && ua.indexOf('chrome') < 0 && ua.indexOf('android') < 0); 4516 })(),
4517 isUiWebView: /(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(window.navigator.userAgent), 4518 isArray: function (arr) { 4519 return Object.prototype.toString.apply(arr) === '[object Array]'; 4520 }, 4521 /*================================================== 4522 Browser 4523 ====================================================*/ 4524 browser: { 4525 ie: window.navigator.pointerEnabled || window.navigator.msPointerEnabled, 4526 ieTouch: (window.navigator.msPointerEnabled && window.navigator.msMaxTouchPoints > 1) || (window.navigator.pointerEnabled && window.navigator.maxTouchPoints > 1), 4527 lteIE9: (function () { 4528 // create temporary DIV 4529 var div = document.createElement('div'); 4530 // add content to tmp DIV which is wrapped into the IE HTML conditional statement 4531 div.innerHTML = '<!--[if lte IE 9]><i></i><![endif]-->'; 4532 // return true / false value based on what will browser render 4533 return div.getElementsByTagName('i').length === 1; 4534 })() 4535 }, 4536 /*================================================== 4537 Devices 4538 ====================================================*/ 4539 device: (function () { 4540 var ua = window.navigator.userAgent; 4541 var android = ua.match(/(Android);?[\s\/]+([\d.]+)?/); 4542 var ipad = ua.match(/(iPad).*OS\s([\d_]+)/); 4543 var ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/); 4544 var iphone = !ipad && ua.match(/(iPhone\sOS|iOS)\s([\d_]+)/); 4545 return { 4546 ios: ipad || iphone || ipod, 4547 android: android 4548 }; 4549 })(), 4550 /*================================================== 4551 Feature Detection 4552 ====================================================*/ 4553 support: { 4554 touch: (window.Modernizr && Modernizr.touch === true) || (function () { 4555 return !!(('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch); 4556 })(), 4557 4558 transforms3d: (window.Modernizr && Modernizr.csstransforms3d === true) || (function () { 4559 var div = document.createElement('div').style; 4560 return ('webkitPerspective' in div || 'MozPerspective' in div || 'OPerspective' in div || 'MsPerspective' in div || 'perspective' in div); 4561 })(), 4562 4563 flexbox: (function () { 4564 var div = document.createElement('div').style; 4565 var styles = ('alignItems webkitAlignItems webkitBoxAlign msFlexAlign mozBoxAlign webkitFlexDirection msFlexDirection mozBoxDirection mozBoxOrient webkitBoxDirection webkitBoxOrient').split(' '); 4566 for (var i = 0; i < styles.length; i++) { 4567 if (styles[i] in div) return true; 4568 } 4569 })(), 4570 4571 observer: (function () { 4572 return ('MutationObserver' in window || 'WebkitMutationObserver' in window); 4573 })(), 4574 4575 passiveListener: (function () { 4576 var supportsPassive = false; 4577 try { 4578 var opts = Object.defineProperty({}, 'passive', { 4579 get: function () { 4580 supportsPassive = true; 4581 } 4582 }); 4583 window.addEventListener('testPassiveListener', null, opts); 4584 } catch (e) { } 4585 return supportsPassive; 4586 })(), 4587 4588 gestures: (function () { 4589 return 'ongesturestart' in window; 4590 })() 4591 }, 4592 /*================================================== 4593 Plugins 4594 ====================================================*/ 4595 plugins: {} 4596 }; 4597 4598 4599 /*=========================== 4600 Dom7 Library 4601 ===========================*/ 4602 var Dom7 = (function () { 4603 var Dom7 = function (arr) { 4604 var _this = this, i = 0; 4605 // Create array-like object 4606 for (i = 0; i < arr.length; i++) { 4607 _this[i] = arr[i]; 4608 } 4609 _this.length = arr.length; 4610 // Return collection with methods 4611 return this; 4612 }; 4613 var $ = function (selector, context) { 4614 var arr = [], i = 0; 4615 if (selector && !context) { 4616 if (selector instanceof Dom7) { 4617 return selector; 4618 } 4619 } 4620 if (selector) { 4621 // String 4622 if (typeof selector === 'string') { 4623 var els, tempParent, html = selector.trim(); 4624 if (html.indexOf('<') >= 0 && html.indexOf('>') >= 0) { 4625 var toCreate = 'div'; 4626 if (html.indexOf('<li') === 0) toCreate = 'ul'; 4627 if (html.indexOf('<tr') === 0) toCreate = 'tbody'; 4628 if (html.indexOf('<td') === 0 || html.indexOf('<th') === 0) toCreate = 'tr'; 4629 if (html.indexOf('<tbody') === 0) toCreate = 'table'; 4630 if (html.indexOf('<option') === 0) toCreate = 'select'; 4631 tempParent = document.createElement(toCreate); 4632 tempParent.innerHTML = selector; 4633 for (i = 0; i < tempParent.childNodes.length; i++) { 4634 arr.push(tempParent.childNodes[i]); 4635 } 4636 } 4637 else { 4638 if (!context && selector[0] === '#' && !selector.match(/[ .<>:~]/)) { 4639 // Pure ID selector 4640 els = [document.getElementById(selector.split('#')[1])]; 4641 } 4642 else { 4643 // Other selectors 4644 els = (context || document).querySelectorAll(selector); 4645 } 4646 for (i = 0; i < els.length; i++) { 4647 if (els[i]) arr.push(els[i]); 4648 } 4649 } 4650 } 4651 // Node/element 4652 else if (selector.nodeType || selector === window || selector === document) { 4653 arr.push(selector); 4654 } 4655 //Array of elements or instance of Dom 4656 else if (selector.length > 0 && selector[0].nodeType) { 4657 for (i = 0; i < selector.length; i++) { 4658 arr.push(selector[i]); 4659 } 4660 } 4661 } 4662 return new Dom7(arr); 4663 }; 4664 Dom7.prototype = { 4665 // Classes and attriutes 4666 addClass: function (className) { 4667 if (typeof className === 'undefined') { 4668 return this; 4669 } 4670 var classes = className.split(' '); 4671 for (var i = 0; i < classes.length; i++) { 4672 for (var j = 0; j < this.length; j++) { 4673 this[j].classList.add(classes[i]); 4674 } 4675 } 4676 return this; 4677 }, 4678 removeClass: function (className) { 4679 var classes = className.split(' '); 4680 for (var i = 0; i < classes.length; i++) { 4681 for (var j = 0; j < this.length; j++) { 4682 this[j].classList.remove(classes[i]); 4683 } 4684 } 4685 return this; 4686 }, 4687 hasClass: function (className) { 4688 if (!this[0]) return false;
4689 else return this[0].classList.contains(className); 4690 }, 4691 toggleClass: function (className) { 4692 var classes = className.split(' '); 4693 for (var i = 0; i < classes.length; i++) { 4694 for (var j = 0; j < this.length; j++) { 4695 this[j].classList.toggle(classes[i]); 4696 } 4697 } 4698 return this; 4699 }, 4700 attr: function (attrs, value) { 4701 if (arguments.length === 1 && typeof attrs === 'string') { 4702 // Get attr 4703 if (this[0]) return this[0].getAttribute(attrs); 4704 else return undefined; 4705 } 4706 else { 4707 // Set attrs 4708 for (var i = 0; i < this.length; i++) { 4709 if (arguments.length === 2) { 4710 // String 4711 this[i].setAttribute(attrs, value); 4712 } 4713 else { 4714 // Object 4715 for (var attrName in attrs) { 4716 this[i][attrName] = attrs[attrName]; 4717 this[i].setAttribute(attrName, attrs[attrName]); 4718 } 4719 } 4720 } 4721 return this; 4722 } 4723 }, 4724 removeAttr: function (attr) { 4725 for (var i = 0; i < this.length; i++) { 4726 this[i].removeAttribute(attr); 4727 } 4728 return this; 4729 }, 4730 data: function (key, value) { 4731 if (typeof value === 'undefined') { 4732 // Get value 4733 if (this[0]) { 4734 var dataKey = this[0].getAttribute('data-' + key); 4735 if (dataKey) return dataKey; 4736 else if (this[0].dom7ElementDataStorage && (key in this[0].dom7ElementDataStorage)) return this[0].dom7ElementDataStorage[key]; 4737 else return undefined; 4738 } 4739 else return undefined; 4740 } 4741 else { 4742 // Set value 4743 for (var i = 0; i < this.length; i++) { 4744 var el = this[i]; 4745 if (!el.dom7ElementDataStorage) el.dom7ElementDataStorage = {}; 4746 el.dom7ElementDataStorage[key] = value; 4747 } 4748 return this; 4749 } 4750 }, 4751 // Transforms 4752 transform: function (transform) { 4753 for (var i = 0; i < this.length; i++) { 4754 var elStyle = this[i].style; 4755 elStyle.webkitTransform = elStyle.MsTransform = elStyle.msTransform = elStyle.MozTransform = elStyle.OTransform = elStyle.transform = transform; 4756 } 4757 return this; 4758 }, 4759 transition: function (duration) { 4760 if (typeof duration !== 'string') { 4761 duration = duration + 'ms'; 4762 } 4763 for (var i = 0; i < this.length; i++) { 4764 var elStyle = this[i].style; 4765 elStyle.webkitTransitionDuration = elStyle.MsTransitionDuration = elStyle.msTransitionDuration = elStyle.MozTransitionDuration = elStyle.OTransitionDuration = elStyle.transitionDuration = duration; 4766 } 4767 return this; 4768 }, 4769 //Events 4770 on: function (eventName, targetSelector, listener, capture) { 4771 function handleLiveEvent(e) { 4772 var target = e.target; 4773 if ($(target).is(targetSelector)) listener.call(target, e); 4774 else { 4775 var parents = $(target).parents(); 4776 for (var k = 0; k < parents.length; k++) { 4777 if ($(parents[k]).is(targetSelector)) listener.call(parents[k], e); 4778 } 4779 } 4780 } 4781 var events = eventName.split(' '); 4782 var i, j; 4783 for (i = 0; i < this.length; i++) { 4784 if (typeof targetSelector === 'function' || targetSelector === false) { 4785 // Usual events 4786 if (typeof targetSelector === 'function') { 4787 listener = arguments[1]; 4788 capture = arguments[2] || false; 4789 } 4790 for (j = 0; j < events.length; j++) { 4791 this[i].addEventListener(events[j], listener, capture); 4792 } 4793 } 4794 else { 4795 //Live events 4796 for (j = 0; j < events.length; j++) { 4797 if (!this[i].dom7LiveListeners) this[i].dom7LiveListeners = []; 4798 this[i].dom7LiveListeners.push({ listener: listener, liveListener: handleLiveEvent }); 4799 this[i].addEventListener(events[j], handleLiveEvent, capture); 4800 } 4801 } 4802 } 4803 4804 return this; 4805 }, 4806 off: function (eventName, targetSelector, listener, capture) { 4807 var events = eventName.split(' '); 4808 for (var i = 0; i < events.length; i++) { 4809 for (var j = 0; j < this.length; j++) { 4810 if (typeof targetSelector === 'function' || targetSelector === false) { 4811 // Usual events 4812 if (typeof targetSelector === 'function') { 4813 listener = arguments[1]; 4814 capture = arguments[2] || false; 4815 } 4816 this[j].removeEventListener(events[i], listener, capture); 4817 } 4818 else { 4819 // Live event 4820 if (this[j].dom7LiveListeners) { 4821 for (var k = 0; k < this[j].dom7LiveListeners.length; k++) { 4822 if (this[j].dom7LiveListeners[k].listener === listener) { 4823 this[j].removeEventListener(events[i], this[j].dom7LiveListeners[k].liveListener, capture); 4824 } 4825 } 4826 } 4827 } 4828 } 4829 } 4830 return this; 4831 }, 4832 once: function (eventName, targetSelector, listener, capture) { 4833 var dom = this; 4834 if (typeof targetSelector === 'function') { 4835 targetSelector = false;
4836 listener = arguments[1]; 4837 capture = arguments[2]; 4838 } 4839 function proxy(e) { 4840 listener(e); 4841 dom.off(eventName, targetSelector, proxy, capture); 4842 } 4843 dom.on(eventName, targetSelector, proxy, capture); 4844 }, 4845 trigger: function (eventName, eventData) { 4846 for (var i = 0; i < this.length; i++) { 4847 var evt; 4848 try { 4849 evt = new window.CustomEvent(eventName, { detail: eventData, bubbles: true, cancelable: true }); 4850 } 4851 catch (e) { 4852 evt = document.createEvent('Event'); 4853 evt.initEvent(eventName, true, true); 4854 evt.detail = eventData; 4855 } 4856 this[i].dispatchEvent(evt); 4857 } 4858 return this; 4859 }, 4860 transitionEnd: function (callback) { 4861 var events = ['webkitTransitionEnd', 'transitionend', 'oTransitionEnd', 'MSTransitionEnd', 'msTransitionEnd'], 4862 i, j, dom = this; 4863 function fireCallBack(e) { 4864 /*jshint validthis:true */ 4865 if (e.target !== this) return; 4866 callback.call(this, e); 4867 for (i = 0; i < events.length; i++) { 4868 dom.off(events[i], fireCallBack); 4869 } 4870 } 4871 if (callback) { 4872 for (i = 0; i < events.length; i++) { 4873 dom.on(events[i], fireCallBack); 4874 } 4875 } 4876 return this; 4877 }, 4878 // Sizing/Styles 4879 width: function () { 4880 if (this[0] === window) { 4881 return window.innerWidth; 4882 } 4883 else { 4884 if (this.length > 0) { 4885 return parseFloat(this.css('width')); 4886 } 4887 else { 4888 return null; 4889 } 4890 } 4891 }, 4892 outerWidth: function (includeMargins) { 4893 if (this.length > 0) { 4894 if (includeMargins) 4895 return this[0].offsetWidth + parseFloat(this.css('margin-right')) + parseFloat(this.css('margin-left')); 4896 else 4897 return this[0].offsetWidth; 4898 } 4899 else return null; 4900 }, 4901 height: function () { 4902 if (this[0] === window) { 4903 return window.innerHeight; 4904 } 4905 else { 4906 if (this.length > 0) { 4907 return parseFloat(this.css('height')); 4908 } 4909 else { 4910 return null; 4911 } 4912 } 4913 }, 4914 outerHeight: function (includeMargins) { 4915 if (this.length > 0) { 4916 if (includeMargins) 4917 return this[0].offsetHeight + parseFloat(this.css('margin-top')) + parseFloat(this.css('margin-bottom')); 4918 else 4919 return this[0].offsetHeight; 4920 } 4921 else return null; 4922 }, 4923 offset: function () { 4924 if (this.length > 0) { 4925 var el = this[0]; 4926 var box = el.getBoundingClientRect(); 4927 var body = document.body; 4928 var clientTop = el.clientTop || body.clientTop || 0; 4929 var clientLeft = el.clientLeft || body.clientLeft || 0; 4930 var scrollTop = window.pageYOffset || el.scrollTop; 4931 var scrollLeft = window.pageXOffset || el.scrollLeft; 4932 return { 4933 top: box.top + scrollTop - clientTop, 4934 left: box.left + scrollLeft - clientLeft 4935 }; 4936 } 4937 else { 4938 return null; 4939 } 4940 }, 4941 css: function (props, value) { 4942 var i; 4943 if (arguments.length === 1) { 4944 if (typeof props === 'string') { 4945 if (this[0]) return window.getComputedStyle(this[0], null).getPropertyValue(props); 4946 } 4947 else { 4948 for (i = 0; i < this.length; i++) { 4949 for (var prop in props) { 4950 this[i].style[prop] = props[prop]; 4951 } 4952 } 4953 return this; 4954 } 4955 } 4956 if (arguments.length === 2 && typeof props === 'string') { 4957 for (i = 0; i < this.length; i++) { 4958 this[i].style[props] = value; 4959 } 4960 return this; 4961 } 4962 return this; 4963 }, 4964 4965 //Dom manipulation 4966 each: function (callback) { 4967 for (var i = 0; i < this.length; i++) { 4968 callback.call(this[i], i, this[i]); 4969 } 4970 return this; 4971 }, 4972 html: function (html) { 4973 if (typeof html === 'undefined') { 4974 return this[0] ? this[0].innerHTML : undefined; 4975 } 4976 else { 4977 for (var i = 0; i < this.length; i++) { 4978 this[i].innerHTML = html; 4979 } 4980 return this; 4981 } 4982 }, 4983 text: function (text) { 4984 if (typeof text === 'undefined') { 4985 if (this[0]) { 4986 return this[0].textContent.trim(); 4987 } 4988 else return null; 4989 } 4990 else { 4991 for (var i = 0; i < this.length; i++) { 4992 this[i].textContent = text; 4993 } 4994 return this; 4995 } 4996 }, 4997 is: function (selector) { 4998 if (!this[0]) return false;
4999 var compareWith, i; 5000 if (typeof selector === 'string') { 5001 var el = this[0]; 5002 if (el === document) return selector === document; 5003 if (el === window) return selector === window; 5004 5005 if (el.matches) return el.matches(selector); 5006 else if (el.webkitMatchesSelector) return el.webkitMatchesSelector(selector); 5007 else if (el.mozMatchesSelector) return el.mozMatchesSelector(selector); 5008 else if (el.msMatchesSelector) return el.msMatchesSelector(selector); 5009 else { 5010 compareWith = $(selector); 5011 for (i = 0; i < compareWith.length; i++) { 5012 if (compareWith[i] === this[0]) return true; 5013 } 5014 return false; 5015 } 5016 } 5017 else if (selector === document) return this[0] === document; 5018 else if (selector === window) return this[0] === window; 5019 else { 5020 if (selector.nodeType || selector instanceof Dom7) { 5021 compareWith = selector.nodeType ? [selector] : selector; 5022 for (i = 0; i < compareWith.length; i++) { 5023 if (compareWith[i] === this[0]) return true; 5024 } 5025 return false; 5026 } 5027 return false; 5028 } 5029 5030 }, 5031 index: function () { 5032 if (this[0]) { 5033 var child = this[0]; 5034 var i = 0; 5035 while ((child = child.previousSibling) !== null) { 5036 if (child.nodeType === 1) i++; 5037 } 5038 return i; 5039 } 5040 else return undefined; 5041 }, 5042 eq: function (index) { 5043 if (typeof index === 'undefined') return this; 5044 var length = this.length; 5045 var returnIndex; 5046 if (index > length - 1) { 5047 return new Dom7([]); 5048 } 5049 if (index < 0) { 5050 returnIndex = length + index; 5051 if (returnIndex < 0) return new Dom7([]); 5052 else return new Dom7([this[returnIndex]]); 5053 } 5054 return new Dom7([this[index]]); 5055 }, 5056 append: function (newChild) { 5057 var i, j; 5058 for (i = 0; i < this.length; i++) { 5059 if (typeof newChild === 'string') { 5060 var tempDiv = document.createElement('div'); 5061 tempDiv.innerHTML = newChild; 5062 while (tempDiv.firstChild) { 5063 this[i].appendChild(tempDiv.firstChild); 5064 } 5065 } 5066 else if (newChild instanceof Dom7) { 5067 for (j = 0; j < newChild.length; j++) { 5068 this[i].appendChild(newChild[j]); 5069 } 5070 } 5071 else { 5072 this[i].appendChild(newChild); 5073 } 5074 } 5075 return this; 5076 }, 5077 prepend: function (newChild) { 5078 var i, j; 5079 for (i = 0; i < this.length; i++) { 5080 if (typeof newChild === 'string') { 5081 var tempDiv = document.createElement('div'); 5082 tempDiv.innerHTML = newChild; 5083 for (j = tempDiv.childNodes.length - 1; j >= 0; j--) { 5084 this[i].insertBefore(tempDiv.childNodes[j], this[i].childNodes[0]); 5085 } 5086 // this[i].insertAdjacentHTML('afterbegin', newChild); 5087 } 5088 else if (newChild instanceof Dom7) { 5089 for (j = 0; j < newChild.length; j++) { 5090 this[i].insertBefore(newChild[j], this[i].childNodes[0]); 5091 } 5092 } 5093 else { 5094 this[i].insertBefore(newChild, this[i].childNodes[0]); 5095 } 5096 } 5097 return this; 5098 }, 5099 insertBefore: function (selector) { 5100 var before = $(selector); 5101 for (var i = 0; i < this.length; i++) { 5102 if (before.length === 1) { 5103 before[0].parentNode.insertBefore(this[i], before[0]); 5104 } 5105 else if (before.length > 1) { 5106 for (var j = 0; j < before.length; j++) { 5107 before[j].parentNode.insertBefore(this[i].cloneNode(true), before[j]); 5108 } 5109 } 5110 } 5111 }, 5112 insertAfter: function (selector) { 5113 var after = $(selector); 5114 for (var i = 0; i < this.length; i++) { 5115 if (after.length === 1) { 5116 after[0].parentNode.insertBefore(this[i], after[0].nextSibling); 5117 } 5118 else if (after.length > 1) { 5119 for (var j = 0; j < after.length; j++) { 5120 after[j].parentNode.insertBefore(this[i].cloneNode(true), after[j].nextSibling); 5121 } 5122 } 5123 } 5124 }, 5125 next: function (selector) { 5126 if (this.length > 0) { 5127 if (selector) { 5128 if (this[0].nextElementSibling && $(this[0].nextElementSibling).is(selector)) return new Dom7([this[0].nextElementSibling]); 5129 else return new Dom7([]); 5130 } 5131 else { 5132 if (this[0].nextElementSibling) return new Dom7([this[0].nextElementSibling]); 5133 else return new Dom7([]); 5134 } 5135 } 5136 else return new Dom7([]); 5137 }, 5138 nextAll: function (selector) { 5139 var nextEls = []; 5140 var el = this[0]; 5141 if (!el) return new Dom7([]); 5142 while (el.nextElementSibling) { 5143 var next = el.nextElementSibling; 5144 if (selector) { 5145 if ($(next).is(selector)) nextEls.push(next); 5146 } 5147 else nextEls.push(next); 5148 el = next; 5149 } 5150 return new Dom7(nextEls); 5151 }, 5152 prev: function (selector) { 5153 if (this.length > 0) { 5154 if (selector) { 5155 if (this[0].previousElementSibling && $(this[0].previousElementSibling).is(selector)) return new Dom7([this[0].previousElementSibling]); 5156 else return new Dom7([]); 5157 } 5158 else { 5159 if (this[0].previousElementSibling) return new Dom7([this[0].previousElementSibling]); 5160 else return new Dom7([]); 5161 } 5162 } 5163 else return new Dom7([]); 5164 }, 5165 prevAll: function (selector) { 5166 var prevEls = []; 5167 var el = this[0]; 5168 if (!el) return new Dom7([]); 5169 while (el.previousElementSibling) { 5170 var prev = el.previousElementSibling; 5171 if (selector) { 5172 if ($(prev).is(selector)) prevEls.push(prev); 5173 } 5174 else prevEls.push(prev); 5175 el = prev; 5176 } 5177 return new Dom7(prevEls); 5178 }, 5179 parent: function (selector) { 5180 var parents = []; 5181 for (var i = 0; i < this.length; i++) { 5182 if (selector) { 5183 if ($(this[i].parentNode).is(selector)) parents.push(this[i].parentNode); 5184 } 5185 else { 5186 parents.push(this[i].parentNode); 5187 } 5188 } 5189 return $($.unique(parents)); 5190 }, 5191 parents: function (selector) { 5192 var parents = []; 5193 for (var i = 0; i < this.length; i++) { 5194 var parent = this[i].parentNode; 5195 while (parent) { 5196 if (selector) { 5197 if ($(parent).is(selector)) parents.push(parent); 5198 } 5199 else { 5200 parents.push(parent); 5201 } 5202 parent = parent.parentNode; 5203 } 5204 } 5205 return $($.unique(parents)); 5206 }, 5207 find: function (selector) { 5208 var foundElements = []; 5209 for (var i = 0; i < this.length; i++) { 5210 var found = this[i].querySelectorAll(selector); 5211 for (var j = 0; j < found.length; j++) { 5212 foundElements.push(found[j]); 5213 } 5214 } 5215 return new Dom7(foundElements); 5216 }, 5217 children: function (selector) { 5218 var children = []; 5219 for (var i = 0; i < this.length; i++) { 5220 var childNodes = this[i].childNodes; 5221 5222 for (var j = 0; j < childNodes.length; j++) { 5223 if (!selector) { 5224 if (childNodes[j].nodeType === 1) children.push(childNodes[j]); 5225 } 5226 else { 5227 if (childNodes[j].nodeType === 1 && $(childNodes[j]).is(selector)) children.push(childNodes[j]); 5228 } 5229 } 5230 } 5231 return new Dom7($.unique(children)); 5232 }, 5233 remove: function () { 5234 for (var i = 0; i < this.length; i++) { 5235 if (this[i].parentNode) this[i].parentNode.removeChild(this[i]); 5236 } 5237 return this; 5238 }, 5239 add: function () { 5240 var dom = this; 5241 var i, j; 5242 for (i = 0; i < arguments.length; i++) { 5243 var toAdd = $(arguments[i]); 5244 for (j = 0; j < toAdd.length; j++) { 5245 dom[dom.length] = toAdd[j]; 5246 dom.length++; 5247 } 5248 } 5249 return dom; 5250 } 5251 }; 5252 $.fn = Dom7.prototype; 5253 $.unique = function (arr) { 5254 var unique = []; 5255 for (var i = 0; i < arr.length; i++) {
5256 if (unique.indexOf(arr[i]) === -1) unique.push(arr[i]); 5257 } 5258 return unique; 5259 }; 5260 5261 return $; 5262 })(); 5263 5264 5265 /*=========================== 5266 Get Dom libraries 5267 ===========================*/ 5268 var swiperDomPlugins = ['jQuery', 'Zepto', 'Dom7']; 5269 for (var i = 0; i < swiperDomPlugins.length; i++) { 5270 if (window[swiperDomPlugins[i]]) { 5271 addLibraryPlugin(window[swiperDomPlugins[i]]); 5272 } 5273 } 5274 // Required DOM Plugins 5275 var domLib; 5276 if (typeof Dom7 === 'undefined') { 5277 domLib = window.Dom7 || window.Zepto || window.jQuery; 5278 } 5279 else { 5280 domLib = Dom7; 5281 } 5282 5283 5284 /*=========================== 5285 Add .swiper plugin from Dom libraries 5286 ===========================*/ 5287 function addLibraryPlugin(lib) { 5288 lib.fn.swiper = function (params) { 5289 var firstInstance; 5290 lib(this).each(function () { 5291 var s = new Swiper(this, params); 5292 if (!firstInstance) firstInstance = s; 5293 }); 5294 return firstInstance; 5295 }; 5296 } 5297 5298 if (domLib) { 5299 if (!('transitionEnd' in domLib.fn)) { 5300 domLib.fn.transitionEnd = function (callback) { 5301 var events = ['webkitTransitionEnd', 'transitionend', 'oTransitionEnd', 'MSTransitionEnd', 'msTransitionEnd'], 5302 i, j, dom = this; 5303 function fireCallBack(e) { 5304 /*jshint validthis:true */ 5305 if (e.target !== this) return; 5306 callback.call(this, e); 5307 for (i = 0; i < events.length; i++) { 5308 dom.off(events[i], fireCallBack); 5309 } 5310 } 5311 if (callback) { 5312 for (i = 0; i < events.length; i++) { 5313 dom.on(events[i], fireCallBack); 5314 } 5315 } 5316 return this; 5317 }; 5318 } 5319 if (!('transform' in domLib.fn)) { 5320 domLib.fn.transform = function (transform) { 5321 for (var i = 0; i < this.length; i++) { 5322 var elStyle = this[i].style; 5323 elStyle.webkitTransform = elStyle.MsTransform = elStyle.msTransform = elStyle.MozTransform = elStyle.OTransform = elStyle.transform = transform; 5324 } 5325 return this; 5326 }; 5327 } 5328 if (!('transition' in domLib.fn)) { 5329 domLib.fn.transition = function (duration) { 5330 if (typeof duration !== 'string') { 5331 duration = duration + 'ms'; 5332 } 5333 for (var i = 0; i < this.length; i++) { 5334 var elStyle = this[i].style; 5335 elStyle.webkitTransitionDuration = elStyle.MsTransitionDuration = elStyle.msTransitionDuration = elStyle.MozTransitionDuration = elStyle.OTransitionDuration = elStyle.transitionDuration = duration; 5336 } 5337 return this; 5338 }; 5339 } 5340 if (!('outerWidth' in domLib.fn)) { 5341 domLib.fn.outerWidth = function (includeMargins) { 5342 if (this.length > 0) { 5343 if (includeMargins) 5344 return this[0].offsetWidth + parseFloat(this.css('margin-right')) + parseFloat(this.css('margin-left')); 5345 else 5346 return this[0].offsetWidth; 5347 } 5348 else return null; 5349 }; 5350 } 5351 } 5352 5353 5354 window.Swiper = Swiper; 5355})(); 5356 5357/*=========================== 5358Swiper AMD Export 5359===========================*/ 5360if (typeof (module) !== 'undefined') { 5361 module.exports = window.Swiper; 5362} 5363else if (typeof define === 'function' && define.amd) { 5364 define([], function () { 5365 'use strict'; 5366 return window.Swiper; 5367 }); 5368} 5369 5370//# sourceMappingURL=maps/swiper.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.