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