1/** 2 * Swiper 9.1.1 3 * Most modern mobile touch slider and framework with hardware accelerated transitions 4 * https://swiperjs.com 5 * 6 * Copyright 2014-2023 Vladimir Kharlampidi 7 * 8 * Released under the MIT License 9 * 10 * Released on: March 16, 2023 11 */ 12var Swiper = function (selector, params) { 13 'use strict'; 14 15 /*========================= 16 A little bit dirty but required part for IE8 and old FF support 17 ===========================*/ 18 if (!document.body.outerHTML && document.body.__defineGetter__) { 19 if (HTMLElement) { 20 var element = HTMLElement.prototype; 21 if (element.__defineGetter__) { 22 element.__defineGetter__('outerHTML', function () { return new XMLSerializer().serializeToString(this); }); 23 } 24 } 25 } 26 27 if (!window.getComputedStyle) { 28 window.getComputedStyle = function (el, pseudo) { 29 this.el = el; 30 this.getPropertyValue = function (prop) { 31 var re = /(\-([a-z]){1})/g; 32 if (prop === 'float') prop = 'styleFloat'; 33 if (re.test(prop)) { 34 prop = prop.replace(re, function () { 35 return arguments[2].toUpperCase(); 36 }); 37 } 38 return el.currentStyle[prop] ? el.currentStyle[prop] : null; 39 }; 40 return this; 41 }; 42 } 43 if (!Array.prototype.indexOf) { 44 Array.prototype.indexOf = function (obj, start) { 45 for (var i = (start || 0), j = this.length; i < j; i++) { 46 if (this[i] === obj) { return i; } 47 } 48 return -1; 49 }; 50 } 51 if (!document.querySelectorAll) { 52 if (!window.jQuery) return; 53 } 54 function $$(selector, context) { 55 if (document.querySelectorAll) 56 return (context || document).querySelectorAll(selector); 57 else 58 return jQuery(selector, context); 59 } 60 61 /*========================= 62 Check for correct selector 63 ===========================*/ 64 if (typeof selector === 'undefined') return; 65 66 if (!(selector.nodeType)) { 67 if ($$(selector).length === 0) return; 68 } 69 70 /*========================= 71 _this 72 ===========================*/ 73 var _this = this; 74 75 /*========================= 76 Default Flags and vars 77 ===========================*/ 78 _this.touches = { 79 start: 0, 80 startX: 0, 81 startY: 0, 82 current: 0, 83 currentX: 0, 84 currentY: 0, 85 diff: 0, 86 abs: 0 87 }; 88 _this.positions = { 89 start: 0, 90 abs: 0, 91 diff: 0, 92 current: 0 93 }; 94 _this.times = { 95 start: 0, 96 end: 0 97 }; 98 99 _this.id = (new Date()).getTime(); 100 _this.container = (selector.nodeType) ? selector : $$(selector)[0]; 101 _this.isTouched = false; 102 _this.isMoved = false; 103 _this.activeIndex = 0; 104 _this.centerIndex = 0; 105 _this.activeLoaderIndex = 0; 106 _this.activeLoopIndex = 0; 107 _this.previousIndex = null; 108 _this.velocity = 0; 109 _this.snapGrid = []; 110 _this.slidesGrid = []; 111 _this.imagesToLoad = []; 112 _this.imagesLoaded = 0; 113 _this.wrapperLeft = 0; 114 _this.wrapperRight = 0; 115 _this.wrapperTop = 0; 116 _this.wrapperBottom = 0; 117 _this.isAndroid = navigator.userAgent.toLowerCase().indexOf('android') >= 0; 118 var wrapper, slideSize, wrapperSize, direction, isScrolling, containerSize; 119 120 /*========================= 121 Default Parameters 122 ===========================*/ 123 var defaults = { 124 eventTarget: 'wrapper', // or 'container' 125 mode : 'horizontal', // or 'vertical' 126 touchRatio : 1, 127 speed : 300, 128 freeMode : false, 129 freeModeFluid : false, 130 momentumRatio: 1, 131 momentumBounce: true, 132 momentumBounceRatio: 1, 133 slidesPerView : 1, 134 slidesPerGroup : 1, 135 slidesPerViewFit: true, //Fit to slide when spv "auto" and slides larger than container 136 simulateTouch : true, 137 followFinger : true, 138 shortSwipes : true, 139 longSwipesRatio: 0.5, 140 moveStartThreshold: false, 141 onlyExternal : false, 142 createPagination : true, 143 pagination : false, 144 paginationElement: 'span', 145 paginationClickable: false, 146 paginationAsRange: true, 147 resistance : true, // or false or 100% 148 scrollContainer : false, 149 preventLinks : true, 150 preventLinksPropagation: false, 151 noSwiping : false, // or class 152 noSwipingClass : 'swiper-no-swiping', //:) 153 initialSlide: 0, 154 keyboardControl: false, 155 mousewheelControl : false, 156 mousewheelControlForceToAxis : false, 157 mousewheelAccelerator: 4, // Accelerator for FireFox 4+ by ThemeREX 158 useCSS3Transforms : true, 159 // Autoplay 160 autoplay: false, 161 autoplayDisableOnInteraction: true, 162 autoplayStopOnLast: false, 163 //Loop mode 164 loop: false, 165 loopAdditionalSlides: 0, 166 // Round length values 167 roundLengths: false, 168 //Auto Height 169 calculateHeight: false, 170 //Apply CSS for width and/or height 171 cssWidthAndHeight: false, // or true or 'width' or 'height' 172 //Images Preloader 173 updateOnImagesReady : true, 174 //Form elements 175 releaseFormElements : true, 176 //Watch for active slide, useful when use effects on different slide states
177 watchActiveIndex: false, 178 //Slides Visibility Fit 179 visibilityFullFit : false, 180 //Slides Offset 181 offsetPxBefore : 0, 182 offsetPxAfter : 0, 183 offsetSlidesBefore : 0, 184 offsetSlidesAfter : 0, 185 centeredSlides: false, 186 //Queue callbacks 187 queueStartCallbacks : false, 188 queueEndCallbacks : false, 189 //Auto Resize 190 autoResize : true, 191 resizeReInit : false, 192 //DOMAnimation 193 DOMAnimation : true, 194 //Slides Loader 195 loader: { 196 slides: [], //array with slides 197 slidesHTMLType: 'inner', // or 'outer' 198 surroundGroups: 1, //keep preloaded slides groups around view 199 logic: 'reload', //or 'change' 200 loadAllSlides: false 201 }, 202 // One way swipes 203 swipeToPrev: true, 204 swipeToNext: true, 205 //Namespace 206 slideElement: 'div', 207 slideClass: 'swiper-slide', 208 slideActiveClass: 'swiper-slide-active', 209 slideVisibleClass: 'swiper-slide-visible', 210 slideDuplicateClass: 'swiper-slide-duplicate', 211 wrapperClass: 'swiper-wrapper', 212 paginationElementClass: 'swiper-pagination-switch', 213 paginationActiveClass: 'swiper-active-switch', 214 paginationVisibleClass: 'swiper-visible-switch' 215 }; 216 params = params || {}; 217 for (var prop in defaults) { 218 if (prop in params && typeof params[prop] === 'object') { 219 for (var subProp in defaults[prop]) { 220 if (! (subProp in params[prop])) { 221 params[prop][subProp] = defaults[prop][subProp]; 222 } 223 } 224 } 225 else if (! (prop in params)) { 226 params[prop] = defaults[prop]; 227 } 228 } 229 _this.params = params; 230 if (params.scrollContainer) { 231 params.freeMode = true; 232 params.freeModeFluid = true; 233 } 234 if (params.loop) { 235 params.resistance = '100%'; 236 } 237 var isH = params.mode === 'horizontal'; 238 239 /*========================= 240 Define Touch Events 241 ===========================*/ 242 var desktopEvents = ['mousedown', 'mousemove', 'mouseup']; 243 if (_this.browser.ie10) desktopEvents = ['MSPointerDown', 'MSPointerMove', 'MSPointerUp']; 244 if (_this.browser.ie11) desktopEvents = ['pointerdown', 'pointermove', 'pointerup']; 245 246 _this.touchEvents = { 247 touchStart : _this.support.touch || !params.simulateTouch ? 'touchstart' : desktopEvents[0], 248 touchMove : _this.support.touch || !params.simulateTouch ? 'touchmove' : desktopEvents[1], 249 touchEnd : _this.support.touch || !params.simulateTouch ? 'touchend' : desktopEvents[2] 250 }; 251 252 /*========================= 253 Wrapper 254 ===========================*/ 255 for (var i = _this.container.childNodes.length - 1; i >= 0; i--) { 256 if (_this.container.childNodes[i].className) { 257 var _wrapperClasses = _this.container.childNodes[i].className.split(/\s+/); 258 for (var j = 0; j < _wrapperClasses.length; j++) { 259 if (_wrapperClasses[j] === params.wrapperClass) { 260 wrapper = _this.container.childNodes[i]; 261 } 262 } 263 } 264 } 265 266 _this.wrapper = wrapper; 267 /*========================= 268 Slide API 269 ===========================*/ 270 _this._extendSwiperSlide = function (el) { 271 el.append = function () { 272 if (params.loop) { 273 el.insertAfter(_this.slides.length - _this.loopedSlides); 274 } 275 else { 276 _this.wrapper.appendChild(el); 277 _this.reInit(); 278 } 279 280 return el; 281 }; 282 el.prepend = function () { 283 if (params.loop) { 284 _this.wrapper.insertBefore(el, _this.slides[_this.loopedSlides]); 285 _this.removeLoopedSlides(); 286 _this.calcSlides(); 287 _this.createLoop(); 288 } 289 else { 290 _this.wrapper.insertBefore(el, _this.wrapper.firstChild); 291 } 292 _this.reInit(); 293 return el; 294 }; 295 el.insertAfter = function (index) { 296 if (typeof index === 'undefined') return false;
297 var beforeSlide; 298 299 if (params.loop) { 300 beforeSlide = _this.slides[index + 1 + _this.loopedSlides]; 301 if (beforeSlide) { 302 _this.wrapper.insertBefore(el, beforeSlide); 303 } 304 else { 305 _this.wrapper.appendChild(el); 306 } 307 _this.removeLoopedSlides(); 308 _this.calcSlides(); 309 _this.createLoop(); 310 } 311 else { 312 beforeSlide = _this.slides[index + 1]; 313 _this.wrapper.insertBefore(el, beforeSlide); 314 } 315 _this.reInit(); 316 return el; 317 }; 318 el.clone = function () { 319 return _this._extendSwiperSlide(el.cloneNode(true)); 320 }; 321 el.remove = function () { 322 _this.wrapper.removeChild(el); 323 _this.reInit(); 324 }; 325 el.html = function (html) { 326 if (typeof html === 'undefined') { 327 return el.innerHTML; 328 } 329 else { 330 el.innerHTML = html; 331 return el; 332 } 333 }; 334 el.index = function () { 335 var index; 336 for (var i = _this.slides.length - 1; i >= 0; i--) { 337 if (el === _this.slides[i]) index = i; 338 } 339 return index; 340 }; 341 el.isActive = function () { 342 if (el.index() === _this.activeIndex) return true; 343 else return false; 344 }; 345 if (!el.swiperSlideDataStorage) el.swiperSlideDataStorage = {}; 346 el.getData = function (name) { 347 return el.swiperSlideDataStorage[name]; 348 }; 349 el.setData = function (name, value) { 350 el.swiperSlideDataStorage[name] = value; 351 return el; 352 }; 353 el.data = function (name, value) { 354 if (typeof value === 'undefined') { 355 return el.getAttribute('data-' + name); 356 } 357 else { 358 el.setAttribute('data-' + name, value); 359 return el; 360 } 361 }; 362 el.getWidth = function (outer, round) { 363 return _this.h.getWidth(el, outer, round); 364 }; 365 el.getHeight = function (outer, round) { 366 return _this.h.getHeight(el, outer, round); 367 }; 368 el.getOffset = function () { 369 return _this.h.getOffset(el); 370 }; 371 return el; 372 }; 373 374 //Calculate information about number of slides 375 _this.calcSlides = function (forceCalcSlides) { 376 var oldNumber = _this.slides ? _this.slides.length : false; 377 _this.slides = []; 378 _this.displaySlides = []; 379 for (var i = 0; i < _this.wrapper.childNodes.length; i++) { 380 if (_this.wrapper.childNodes[i].className) { 381 var _className = _this.wrapper.childNodes[i].className; 382 var _slideClasses = _className.split(/\s+/); 383 for (var j = 0; j < _slideClasses.length; j++) { 384 if (_slideClasses[j] === params.slideClass) { 385 _this.slides.push(_this.wrapper.childNodes[i]); 386 } 387 } 388 } 389 } 390 for (i = _this.slides.length - 1; i >= 0; i--) { 391 _this._extendSwiperSlide(_this.slides[i]); 392 } 393 if (oldNumber === false) return; 394 if (oldNumber !== _this.slides.length || forceCalcSlides) { 395 396 // Number of slides has been changed 397 removeSlideEvents(); 398 addSlideEvents(); 399 _this.updateActiveSlide(); 400 if (_this.params.pagination) _this.createPagination(); 401 _this.callPlugins('numberOfSlidesChanged'); 402 } 403 }; 404 405 //Create Slide 406 _this.createSlide = function (html, slideClassList, el) { 407 slideClassList = slideClassList || _this.params.slideClass; 408 el = el || params.slideElement; 409 var newSlide = document.createElement(el); 410 newSlide.innerHTML = html || ''; 411 newSlide.className = slideClassList; 412 return _this._extendSwiperSlide(newSlide); 413 }; 414 415 //Append Slide 416 _this.appendSlide = function (html, slideClassList, el) { 417 if (!html) return; 418 if (html.nodeType) { 419 return _this._extendSwiperSlide(html).append(); 420 } 421 else { 422 return _this.createSlide(html, slideClassList, el).append(); 423 } 424 }; 425 _this.prependSlide = function (html, slideClassList, el) { 426 if (!html) return; 427 if (html.nodeType) { 428 return _this._extendSwiperSlide(html).prepend(); 429 } 430 else { 431 return _this.createSlide(html, slideClassList, el).prepend(); 432 } 433 }; 434 _this.insertSlideAfter = function (index, html, slideClassList, el) { 435 if (typeof index === 'undefined') return false;
436 if (html.nodeType) { 437 return _this._extendSwiperSlide(html).insertAfter(index); 438 } 439 else { 440 return _this.createSlide(html, slideClassList, el).insertAfter(index); 441 } 442 }; 443 _this.removeSlide = function (index) { 444 if (_this.slides[index]) { 445 if (params.loop) { 446 if (!_this.slides[index + _this.loopedSlides]) return false; 447 _this.slides[index + _this.loopedSlides].remove(); 448 _this.removeLoopedSlides(); 449 _this.calcSlides(); 450 _this.createLoop(); 451 } 452 else _this.slides[index].remove(); 453 return true; 454 } 455 else return false; 456 }; 457 _this.removeLastSlide = function () { 458 if (_this.slides.length > 0) { 459 if (params.loop) { 460 _this.slides[_this.slides.length - 1 - _this.loopedSlides].remove(); 461 _this.removeLoopedSlides(); 462 _this.calcSlides(); 463 _this.createLoop(); 464 } 465 else _this.slides[_this.slides.length - 1].remove(); 466 return true; 467 } 468 else { 469 return false; 470 } 471 }; 472 _this.removeAllSlides = function () { 473 for (var i = _this.slides.length - 1; i >= 0; i--) { 474 _this.slides[i].remove(); 475 } 476 };
477 _this.getSlide = function (index) { 478 return _this.slides[index]; 479 }; 480 _this.getLastSlide = function () { 481 return _this.slides[_this.slides.length - 1]; 482 }; 483 _this.getFirstSlide = function () { 484 return _this.slides[0]; 485 }; 486 487 //Currently Active Slide 488 _this.activeSlide = function () { 489 return _this.slides[_this.activeIndex]; 490 }; 491 492 /*========================= 493 Wrapper for Callbacks : Allows additive callbacks via function arrays 494 ===========================*/ 495 _this.fireCallback = function () { 496 var callback = arguments[0]; 497 if (Object.prototype.toString.call(callback) === '[object Array]') { 498 for (var i = 0; i < callback.length; i++) { 499 if (typeof callback[i] === 'function') { 500 callback[i](arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]); 501 } 502 } 503 } else if (Object.prototype.toString.call(callback) === '[object String]') { 504 if (params['on' + callback]) _this.fireCallback(params['on' + callback], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]); 505 } else { 506 callback(arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]); 507 } 508 }; 509 function isArray(obj) { 510 if (Object.prototype.toString.apply(obj) === '[object Array]') return true; 511 return false; 512 } 513 514 /** 515 * Allows user to add callbacks, rather than replace them 516 * @param callback 517 * @param func 518 * @return {*} 519 */ 520 _this.addCallback = function (callback, func) { 521 var _this = this, tempFunc; 522 if (_this.params['on' + callback]) { 523 if (isArray(this.params['on' + callback])) { 524 return this.params['on' + callback].push(func); 525 } else if (typeof this.params['on' + callback] === 'function') { 526 tempFunc = this.params['on' + callback]; 527 this.params['on' + callback] = []; 528 this.params['on' + callback].push(tempFunc); 529 return this.params['on' + callback].push(func); 530 } 531 } else { 532 this.params['on' + callback] = []; 533 return this.params['on' + callback].push(func); 534 } 535 }; 536 _this.removeCallbacks = function (callback) { 537 if (_this.params['on' + callback]) { 538 _this.params['on' + callback] = null; 539 } 540 }; 541 542 /*========================= 543 Plugins API 544 ===========================*/ 545 var _plugins = []; 546 for (var plugin in _this.plugins) { 547 if (params[plugin]) { 548 var p = _this.plugins[plugin](_this, params[plugin]); 549 if (p) _plugins.push(p); 550 } 551 } 552 _this.callPlugins = function (method, args) { 553 if (!args) args = {}; 554 for (var i = 0; i < _plugins.length; i++) { 555 if (method in _plugins[i]) { 556 _plugins[i][method](args); 557 } 558 } 559 }; 560 561 /*========================= 562 Windows Phone 8 Fix 563 ===========================*/ 564 if ((_this.browser.ie10 || _this.browser.ie11) && !params.onlyExternal) { 565 _this.wrapper.classList.add('swiper-wp8-' + (isH ? 'horizontal' : 'vertical')); 566 } 567 568 /*========================= 569 Free Mode Class 570 ===========================*/ 571 if (params.freeMode) { 572 _this.container.className += ' swiper-free-mode'; 573 } 574 575 /*================================================== 576 Init/Re-init/Resize Fix 577 ====================================================*/ 578 _this.initialized = false; 579 _this.init = function (force, forceCalcSlides) { 580 var _width = _this.h.getWidth(_this.container, false, params.roundLengths); 581 var _height = _this.h.getHeight(_this.container, false, params.roundLengths); 582 if (_width === _this.width && _height === _this.height && !force) return; 583 584 _this.width = _width; 585 _this.height = _height; 586 587 var slideWidth, slideHeight, slideMaxHeight, wrapperWidth, wrapperHeight, slideLeft; 588 var i; // loop index variable to avoid JSHint W004 / W038 589 containerSize = isH ? _width : _height; 590 var wrapper = _this.wrapper; 591 592 if (force) { 593 _this.calcSlides(forceCalcSlides); 594 } 595 596 if (params.slidesPerView === 'auto') { 597 //Auto mode 598 var slidesWidth = 0; 599 var slidesHeight = 0; 600 601 //Unset Styles 602 if (params.slidesOffset > 0) { 603 wrapper.style.paddingLeft = ''; 604 wrapper.style.paddingRight = ''; 605 wrapper.style.paddingTop = ''; 606 wrapper.style.paddingBottom = ''; 607 } 608 wrapper.style.width = ''; 609 wrapper.style.height = ''; 610 if (params.offsetPxBefore > 0) { 611 if (isH) _this.wrapperLeft = params.offsetPxBefore; 612 else _this.wrapperTop = params.offsetPxBefore; 613 } 614 if (params.offsetPxAfter > 0) { 615 if (isH) _this.wrapperRight = params.offsetPxAfter; 616 else _this.wrapperBottom = params.offsetPxAfter; 617 } 618 619 if (params.centeredSlides) { 620 if (isH) { 621 _this.wrapperLeft = (containerSize - this.slides[0].getWidth(true, params.roundLengths)) / 2; 622 _this.wrapperRight = (containerSize - _this.slides[_this.slides.length - 1].getWidth(true, params.roundLengths)) / 2; 623 } 624 else { 625 _this.wrapperTop = (containerSize - _this.slides[0].getHeight(true, params.roundLengths)) / 2; 626 _this.wrapperBottom = (containerSize - _this.slides[_this.slides.length - 1].getHeight(true, params.roundLengths)) / 2; 627 } 628 } 629 630 if (isH) { 631 if (_this.wrapperLeft >= 0) wrapper.style.paddingLeft = _this.wrapperLeft + 'px'; 632 if (_this.wrapperRight >= 0) wrapper.style.paddingRight = _this.wrapperRight + 'px'; 633 } 634 else { 635 if (_this.wrapperTop >= 0) wrapper.style.paddingTop = _this.wrapperTop + 'px'; 636 if (_this.wrapperBottom >= 0) wrapper.style.paddingBottom = _this.wrapperBottom + 'px'; 637 } 638 slideLeft = 0; 639 var centeredSlideLeft = 0; 640 _this.snapGrid = []; 641 _this.slidesGrid = []; 642 643 slideMaxHeight = 0; 644 for (i = 0; i < _this.slides.length; i++) { 645 slideWidth = _this.slides[i].getWidth(true, params.roundLengths); 646 slideHeight = _this.slides[i].getHeight(true, params.roundLengths); 647 if (params.calculateHeight) { 648 slideMaxHeight = Math.max(slideMaxHeight, slideHeight); 649 } 650 var _slideSize = isH ? slideWidth : slideHeight; 651 if (params.centeredSlides) { 652 var nextSlideWidth = i === _this.slides.length - 1 ? 0 : _this.slides[i + 1].getWidth(true, params.roundLengths); 653 var nextSlideHeight = i === _this.slides.length - 1 ? 0 : _this.slides[i + 1].getHeight(true, params.roundLengths); 654 var nextSlideSize = isH ? nextSlideWidth : nextSlideHeight; 655 if (_slideSize > containerSize) { 656 if (params.slidesPerViewFit) { 657 _this.snapGrid.push(slideLeft + _this.wrapperLeft); 658 _this.snapGrid.push(slideLeft + _slideSize - containerSize + _this.wrapperLeft); 659 } 660 else { 661 for (var j = 0; j <= Math.floor(_slideSize / (containerSize + _this.wrapperLeft)); j++) { 662 if (j === 0) _this.snapGrid.push(slideLeft + _this.wrapperLeft); 663 else _this.snapGrid.push(slideLeft + _this.wrapperLeft + containerSize * j); 664 } 665 } 666 _this.slidesGrid.push(slideLeft + _this.wrapperLeft); 667 } 668 else { 669 _this.snapGrid.push(centeredSlideLeft); 670 _this.slidesGrid.push(centeredSlideLeft); 671 } 672 centeredSlideLeft += _slideSize / 2 + nextSlideSize / 2; 673 } 674 else { 675 if (_slideSize > containerSize) { 676 if (params.slidesPerViewFit) { 677 _this.snapGrid.push(slideLeft); 678 _this.snapGrid.push(slideLeft + _slideSize - containerSize); 679 } 680 else { 681 if (containerSize !== 0) { 682 for (var k = 0; k <= Math.floor(_slideSize / containerSize); k++) { 683 _this.snapGrid.push(slideLeft + containerSize * k); 684 } 685 } 686 else { 687 _this.snapGrid.push(slideLeft); 688 } 689 } 690 691 } 692 else { 693 _this.snapGrid.push(slideLeft); 694 } 695 _this.slidesGrid.push(slideLeft); 696 } 697 698 slideLeft += _slideSize; 699 700 slidesWidth += slideWidth; 701 slidesHeight += slideHeight; 702 } 703 if (params.calculateHeight) _this.height = slideMaxHeight; 704 if (isH) { 705 wrapperSize = slidesWidth + _this.wrapperRight + _this.wrapperLeft; 706 wrapper.style.width = (slidesWidth) + 'px'; 707 wrapper.style.height = (_this.height) + 'px'; 708 } 709 else { 710 wrapperSize = slidesHeight + _this.wrapperTop + _this.wrapperBottom; 711 wrapper.style.width = (_this.width) + 'px'; 712 wrapper.style.height = (slidesHeight) + 'px'; 713 } 714 715 } 716 else if (params.scrollContainer) { 717 //Scroll Container 718 wrapper.style.width = ''; 719 wrapper.style.height = '';
720 wrapperWidth = _this.slides[0].getWidth(true, params.roundLengths); 721 wrapperHeight = _this.slides[0].getHeight(true, params.roundLengths); 722 wrapperSize = isH ? wrapperWidth : wrapperHeight; 723 wrapper.style.width = wrapperWidth + 'px'; 724 wrapper.style.height = wrapperHeight + 'px'; 725 slideSize = isH ? wrapperWidth : wrapperHeight; 726 727 } 728 else { 729 //For usual slides 730 if (params.calculateHeight) { 731 slideMaxHeight = 0; 732 wrapperHeight = 0; 733 //ResetWrapperSize 734 if (!isH) _this.container.style.height = ''; 735 wrapper.style.height = ''; 736 737 for (i = 0; i < _this.slides.length; i++) { 738 //ResetSlideSize 739 _this.slides[i].style.height = ''; 740 slideMaxHeight = Math.max(_this.slides[i].getHeight(true), slideMaxHeight); 741 if (!isH) wrapperHeight += _this.slides[i].getHeight(true); 742 } 743 slideHeight = slideMaxHeight; 744 _this.height = slideHeight; 745 746 if (isH) wrapperHeight = slideHeight; 747 else { 748 containerSize = slideHeight; 749 _this.container.style.height = containerSize + 'px'; 750 } 751 } 752 else { 753 slideHeight = isH ? _this.height : _this.height / params.slidesPerView; 754 if (params.roundLengths) slideHeight = Math.ceil(slideHeight); 755 wrapperHeight = isH ? _this.height : _this.slides.length * slideHeight; 756 } 757 slideWidth = isH ? _this.width / params.slidesPerView : _this.width; 758 if (params.roundLengths) slideWidth = Math.ceil(slideWidth); 759 wrapperWidth = isH ? _this.slides.length * slideWidth : _this.width; 760 slideSize = isH ? slideWidth : slideHeight; 761 762 if (params.offsetSlidesBefore > 0) { 763 if (isH) _this.wrapperLeft = slideSize * params.offsetSlidesBefore; 764 else _this.wrapperTop = slideSize * params.offsetSlidesBefore; 765 } 766 if (params.offsetSlidesAfter > 0) { 767 if (isH) _this.wrapperRight = slideSize * params.offsetSlidesAfter; 768 else _this.wrapperBottom = slideSize * params.offsetSlidesAfter; 769 } 770 if (params.offsetPxBefore > 0) { 771 if (isH) _this.wrapperLeft = params.offsetPxBefore; 772 else _this.wrapperTop = params.offsetPxBefore; 773 } 774 if (params.offsetPxAfter > 0) { 775 if (isH) _this.wrapperRight = params.offsetPxAfter; 776 else _this.wrapperBottom = params.offsetPxAfter; 777 } 778 if (params.centeredSlides) { 779 if (isH) { 780 _this.wrapperLeft = (containerSize - slideSize) / 2; 781 _this.wrapperRight = (containerSize - slideSize) / 2; 782 } 783 else { 784 _this.wrapperTop = (containerSize - slideSize) / 2; 785 _this.wrapperBottom = (containerSize - slideSize) / 2; 786 } 787 } 788 if (isH) { 789 if (_this.wrapperLeft > 0) wrapper.style.paddingLeft = _this.wrapperLeft + 'px'; 790 if (_this.wrapperRight > 0) wrapper.style.paddingRight = _this.wrapperRight + 'px'; 791 } 792 else { 793 if (_this.wrapperTop > 0) wrapper.style.paddingTop = _this.wrapperTop + 'px'; 794 if (_this.wrapperBottom > 0) wrapper.style.paddingBottom = _this.wrapperBottom + 'px'; 795 } 796 797 wrapperSize = isH ? wrapperWidth + _this.wrapperRight + _this.wrapperLeft : wrapperHeight + _this.wrapperTop + _this.wrapperBottom; 798 if (parseFloat(wrapperWidth) > 0 && (!params.cssWidthAndHeight || params.cssWidthAndHeight === 'height')) { 799 wrapper.style.width = wrapperWidth + 'px'; 800 } 801 if (parseFloat(wrapperHeight) > 0 && (!params.cssWidthAndHeight || params.cssWidthAndHeight === 'width')) { 802 wrapper.style.height = wrapperHeight + 'px'; 803 } 804 slideLeft = 0; 805 _this.snapGrid = []; 806 _this.slidesGrid = []; 807 for (i = 0; i < _this.slides.length; i++) { 808 _this.snapGrid.push(slideLeft); 809 _this.slidesGrid.push(slideLeft); 810 slideLeft += slideSize; 811 if (parseFloat(slideWidth) > 0 && (!params.cssWidthAndHeight || params.cssWidthAndHeight === 'height')) { 812 _this.slides[i].style.width = slideWidth + 'px'; 813 } 814 if (parseFloat(slideHeight) > 0 && (!params.cssWidthAndHeight || params.cssWidthAndHeight === 'width')) { 815 _this.slides[i].style.height = slideHeight + 'px'; 816 } 817 } 818 819 } 820 821 if (!_this.initialized) { 822 _this.callPlugins('onFirstInit'); 823 if (params.onFirstInit) _this.fireCallback(params.onFirstInit, _this); 824 } 825 else { 826 _this.callPlugins('onInit'); 827 if (params.onInit) _this.fireCallback(params.onInit, _this); 828 } 829 _this.initialized = true; 830 }; 831 832 _this.reInit = function (forceCalcSlides) { 833 _this.init(true, forceCalcSlides); 834 }; 835 836 _this.resizeFix = function (reInit) { 837 _this.callPlugins('beforeResizeFix'); 838 839 _this.init(params.resizeReInit || reInit); 840 841 // swipe to active slide in fixed mode 842 if (!params.freeMode) { 843 _this.swipeTo((params.loop ? _this.activeLoopIndex : _this.activeIndex), 0, false); 844 // Fix autoplay 845 if (params.autoplay) { 846 if (_this.support.transitions && typeof autoplayTimeoutId !== 'undefined') { 847 if (typeof autoplayTimeoutId !== 'undefined') { 848 clearTimeout(autoplayTimeoutId); 849 autoplayTimeoutId = undefined; 850 _this.startAutoplay(); 851 } 852 } 853 else { 854 if (typeof autoplayIntervalId !== 'undefined') { 855 clearInterval(autoplayIntervalId); 856 autoplayIntervalId = undefined; 857 _this.startAutoplay(); 858 } 859 } 860 } 861 } 862 // move wrapper to the beginning in free mode 863 else if (_this.getWrapperTranslate() < -maxWrapperPosition()) { 864 _this.setWrapperTransition(0);
865 _this.setWrapperTranslate(-maxWrapperPosition()); 866 } 867 868 _this.callPlugins('afterResizeFix'); 869 }; 870 871 /*========================================== 872 Max and Min Positions 873 ============================================*/ 874 function maxWrapperPosition() { 875 var a = (wrapperSize - containerSize); 876 if (params.freeMode) { 877 a = wrapperSize - containerSize; 878 } 879 if (params.slidesPerView > _this.slides.length && !params.centeredSlides) { 880 a = 0; 881 } 882 if (a < 0) a = 0; 883 return a; 884 } 885 886 /*========================================== 887 Event Listeners 888 ============================================*/ 889 function initEvents() { 890 var bind = _this.h.addEventListener; 891 var eventTarget = params.eventTarget === 'wrapper' ? _this.wrapper : _this.container; 892 //Touch Events 893 if (! (_this.browser.ie10 || _this.browser.ie11)) { 894 if (_this.support.touch) { 895 bind(eventTarget, 'touchstart', onTouchStart); 896 bind(eventTarget, 'touchmove', onTouchMove); 897 bind(eventTarget, 'touchend', onTouchEnd); 898 } 899 if (params.simulateTouch) { 900 bind(eventTarget, 'mousedown', onTouchStart); 901 bind(document, 'mousemove', onTouchMove); 902 bind(document, 'mouseup', onTouchEnd); 903 } 904 } 905 else { 906 bind(eventTarget, _this.touchEvents.touchStart, onTouchStart); 907 bind(document, _this.touchEvents.touchMove, onTouchMove); 908 bind(document, _this.touchEvents.touchEnd, onTouchEnd); 909 } 910 911 //Resize Event 912 if (params.autoResize) { 913 bind(window, 'resize', _this.resizeFix); 914 } 915 //Slide Events 916 addSlideEvents(); 917 //Mousewheel 918 _this._wheelEvent = false; 919 if (params.mousewheelControl) { 920 if (document.onmousewheel !== undefined) { 921 _this._wheelEvent = 'mousewheel'; 922 } 923 if (!_this._wheelEvent) { 924 try { 925 new WheelEvent('wheel'); 926 _this._wheelEvent = 'wheel'; 927 } catch (e) {} 928 } 929 if (!_this._wheelEvent) { 930 _this._wheelEvent = 'DOMMouseScroll'; 931 } 932 if (_this._wheelEvent) { 933 bind(_this.container, _this._wheelEvent, handleMousewheel); 934 } 935 } 936 937 //Keyboard 938 function _loadImage(src) { 939 var image = new Image(); 940 image.onload = function () { 941 if (typeof _this === 'undefined' || _this === null) return; 942 if (_this.imagesLoaded !== undefined) _this.imagesLoaded++; 943 if (_this.imagesLoaded === _this.imagesToLoad.length) { 944 _this.reInit(); 945 if (params.onImagesReady) _this.fireCallback(params.onImagesReady, _this); 946 } 947 }; 948 image.src = src; 949 } 950 951 if (params.keyboardControl) { 952 bind(document, 'keydown', handleKeyboardKeys); 953 } 954 if (params.updateOnImagesReady) { 955 _this.imagesToLoad = $$('img', _this.container); 956 957 for (var i = 0; i < _this.imagesToLoad.length; i++) { 958 _loadImage(_this.imagesToLoad[i].getAttribute('src')); 959 } 960 } 961 } 962 963 //Remove Event Listeners 964 _this.destroy = function () { 965 var unbind = _this.h.removeEventListener; 966 var eventTarget = params.eventTarget === 'wrapper' ? _this.wrapper : _this.container; 967 //Touch Events 968 if (! (_this.browser.ie10 || _this.browser.ie11)) { 969 if (_this.support.touch) { 970 unbind(eventTarget, 'touchstart', onTouchStart); 971 unbind(eventTarget, 'touchmove', onTouchMove); 972 unbind(eventTarget, 'touchend', onTouchEnd); 973 } 974 if (params.simulateTouch) { 975 unbind(eventTarget, 'mousedown', onTouchStart); 976 unbind(document, 'mousemove', onTouchMove); 977 unbind(document, 'mouseup', onTouchEnd); 978 } 979 } 980 else { 981 unbind(eventTarget, _this.touchEvents.touchStart, onTouchStart); 982 unbind(document, _this.touchEvents.touchMove, onTouchMove); 983 unbind(document, _this.touchEvents.touchEnd, onTouchEnd); 984 } 985 986 //Resize Event 987 if (params.autoResize) { 988 unbind(window, 'resize', _this.resizeFix); 989 } 990 991 //Init Slide Events 992 removeSlideEvents(); 993 994 //Pagination 995 if (params.paginationClickable) { 996 removePaginationEvents(); 997 } 998 999 //Mousewheel 1000 if (params.mousewheelControl && _this._wheelEvent) { 1001 unbind(_this.container, _this._wheelEvent, handleMousewheel); 1002 } 1003 1004 //Keyboard 1005 if (params.keyboardControl) { 1006 unbind(document, 'keydown', handleKeyboardKeys); 1007 } 1008 1009 //Stop autoplay 1010 if (params.autoplay) { 1011 _this.stopAutoplay(); 1012 } 1013 _this.callPlugins('onDestroy'); 1014 1015 //Destroy variable 1016 _this = null; 1017 }; 1018 1019 function addSlideEvents() { 1020 var bind = _this.h.addEventListener, 1021 i; 1022 1023 //Prevent Links Events 1024 if (params.preventLinks) { 1025 var links = $$('a', _this.container); 1026 for (i = 0; i < links.length; i++) { 1027 bind(links[i], 'click', preventClick); 1028 } 1029 } 1030 //Release Form Elements 1031 if (params.releaseFormElements) { 1032 var formElements = $$('input, textarea, select', _this.container); 1033 for (i = 0; i < formElements.length; i++) { 1034 bind(formElements[i], _this.touchEvents.touchStart, releaseForms, true); 1035 } 1036 } 1037 1038 //Slide Clicks & Touches 1039 if (params.onSlideClick) { 1040 for (i = 0; i < _this.slides.length; i++) { 1041 bind(_this.slides[i], 'click', slideClick); 1042 } 1043 } 1044 if (params.onSlideTouch) { 1045 for (i = 0; i < _this.slides.length; i++) { 1046 bind(_this.slides[i], _this.touchEvents.touchStart, slideTouch); 1047 } 1048 } 1049 } 1050 function removeSlideEvents() { 1051 var unbind = _this.h.removeEventListener, 1052 i; 1053 1054 //Slide Clicks & Touches 1055 if (params.onSlideClick) { 1056 for (i = 0; i < _this.slides.length; i++) { 1057 unbind(_this.slides[i], 'click', slideClick); 1058 } 1059 } 1060 if (params.onSlideTouch) { 1061 for (i = 0; i < _this.slides.length; i++) { 1062 unbind(_this.slides[i], _this.touchEvents.touchStart, slideTouch); 1063 } 1064 } 1065 //Release Form Elements 1066 if (params.releaseFormElements) { 1067 var formElements = $$('input, textarea, select', _this.container); 1068 for (i = 0; i < formElements.length; i++) { 1069 unbind(formElements[i], _this.touchEvents.touchStart, releaseForms, true); 1070 } 1071 } 1072 //Prevent Links Events 1073 if (params.preventLinks) { 1074 var links = $$('a', _this.container); 1075 for (i = 0; i < links.length; i++) { 1076 unbind(links[i], 'click', preventClick); 1077 } 1078 } 1079 } 1080 /*========================================== 1081 Keyboard Control 1082 ============================================*/ 1083 function handleKeyboardKeys(e) { 1084 var kc = e.keyCode || e.charCode; 1085 if (e.shiftKey || e.altKey || e.ctrlKey || e.metaKey) return; 1086 if (kc === 37 || kc === 39 || kc === 38 || kc === 40) { 1087 var inView = false;
1088 //Check that swiper should be inside of visible area of window 1089 var swiperOffset = _this.h.getOffset(_this.container); 1090 var scrollLeft = _this.h.windowScroll().left; 1091 var scrollTop = _this.h.windowScroll().top; 1092 var windowWidth = _this.h.windowWidth(); 1093 var windowHeight = _this.h.windowHeight(); 1094 var swiperCoord = [ 1095 [swiperOffset.left, swiperOffset.top], 1096 [swiperOffset.left + _this.width, swiperOffset.top], 1097 [swiperOffset.left, swiperOffset.top + _this.height], 1098 [swiperOffset.left + _this.width, swiperOffset.top + _this.height] 1099 ]; 1100 for (var i = 0; i < swiperCoord.length; i++) { 1101 var point = swiperCoord[i]; 1102 if ( 1103 point[0] >= scrollLeft && point[0] <= scrollLeft + windowWidth && 1104 point[1] >= scrollTop && point[1] <= scrollTop + windowHeight 1105 ) { 1106 inView = true; 1107 } 1108 1109 } 1110 if (!inView) return; 1111 } 1112 if (isH) { 1113 if (kc === 37 || kc === 39) { 1114 if (e.preventDefault) e.preventDefault(); 1115 else e.returnValue = false; 1116 } 1117 if (kc === 39) _this.swipeNext(); 1118 if (kc === 37) _this.swipePrev(); 1119 } 1120 else { 1121 if (kc === 38 || kc === 40) { 1122 if (e.preventDefault) e.preventDefault(); 1123 else e.returnValue = false; 1124 } 1125 if (kc === 40) _this.swipeNext(); 1126 if (kc === 38) _this.swipePrev(); 1127 } 1128 } 1129 1130 _this.disableKeyboardControl = function () { 1131 params.keyboardControl = false; 1132 _this.h.removeEventListener(document, 'keydown', handleKeyboardKeys); 1133 }; 1134 1135 _this.enableKeyboardControl = function () { 1136 params.keyboardControl = true; 1137 _this.h.addEventListener(document, 'keydown', handleKeyboardKeys); 1138 }; 1139 1140 /*========================================== 1141 Mousewheel Control 1142 ============================================*/ 1143 var lastScrollTime = (new Date()).getTime(); 1144 function handleMousewheel(e) { 1145 var we = _this._wheelEvent; 1146 var delta = 0; 1147 1148 //Opera & IE 1149 if (e.detail) delta = -e.detail; 1150 //WebKits 1151 else if (we === 'mousewheel') { 1152 if (params.mousewheelControlForceToAxis) { 1153 if (isH) { 1154 if (Math.abs(e.wheelDeltaX) > Math.abs(e.wheelDeltaY)) delta = e.wheelDeltaX; 1155 else return; 1156 } 1157 else { 1158 if (Math.abs(e.wheelDeltaY) > Math.abs(e.wheelDeltaX)) delta = e.wheelDeltaY; 1159 else return; 1160 } 1161 } 1162 else { 1163 delta = e.wheelDelta; 1164 } 1165 } 1166 //Old FireFox 1167 else if (we === 'DOMMouseScroll') delta = -e.detail; 1168 //New FireFox 1169 else if (we === 'wheel') { 1170 if (params.mousewheelControlForceToAxis) { 1171 if (isH) { 1172 if (Math.abs(e.deltaX) > Math.abs(e.deltaY)) delta = -e.deltaX; 1173 else return; 1174 } 1175 else { 1176 if (Math.abs(e.deltaY) > Math.abs(e.deltaX)) delta = -e.deltaY; 1177 else return; 1178 } 1179 } 1180 else { 1181 delta = Math.abs(e.deltaX) > Math.abs(e.deltaY) ? - e.deltaX : - e.deltaY; 1182 } 1183 // Accelerate mouse wheel by ThemeREX 1184 delta *= params.mousewheelAccelerator; 1185 } 1186 1187 if (!params.freeMode) { 1188 if ((new Date()).getTime() - lastScrollTime > 60) { 1189 if (delta < 0) _this.swipeNext(); 1190 else _this.swipePrev(); 1191 } 1192 lastScrollTime = (new Date()).getTime(); 1193 1194 } 1195 else { 1196 //Freemode or scrollContainer: 1197 var position = _this.getWrapperTranslate() + delta; 1198 1199 if (position > 0) position = 0; 1200 if (position < -maxWrapperPosition()) position = -maxWrapperPosition(); 1201 1202 _this.setWrapperTransition(0); 1203 _this.setWrapperTranslate(position); 1204 _this.updateActiveSlide(position); 1205 1206 // Return page scroll on edge positions 1207 if (position === 0 || position === -maxWrapperPosition()) return; 1208 } 1209 if (params.autoplay) _this.stopAutoplay(true); 1210 1211 if (e.preventDefault) e.preventDefault(); 1212 else e.returnValue = false;
1213 return false; 1214 } 1215 _this.disableMousewheelControl = function () { 1216 if (!_this._wheelEvent) return false; 1217 params.mousewheelControl = false; 1218 _this.h.removeEventListener(_this.container, _this._wheelEvent, handleMousewheel); 1219 return true; 1220 }; 1221 1222 _this.enableMousewheelControl = function () { 1223 if (!_this._wheelEvent) return false; 1224 params.mousewheelControl = true; 1225 _this.h.addEventListener(_this.container, _this._wheelEvent, handleMousewheel); 1226 return true; 1227 }; 1228 1229 /*========================= 1230 Grab Cursor 1231 ===========================*/ 1232 if (params.grabCursor) { 1233 var containerStyle = _this.container.style; 1234 containerStyle.cursor = 'move'; 1235 containerStyle.cursor = 'grab'; 1236 containerStyle.cursor = '-moz-grab'; 1237 containerStyle.cursor = '-webkit-grab'; 1238 } 1239 1240 /*========================= 1241 Slides Events Handlers 1242 ===========================*/ 1243 1244 _this.allowSlideClick = true; 1245 function slideClick(event) { 1246 if (_this.allowSlideClick) { 1247 setClickedSlide(event); 1248 _this.fireCallback(params.onSlideClick, _this, event); 1249 } 1250 } 1251 1252 function slideTouch(event) { 1253 setClickedSlide(event); 1254 _this.fireCallback(params.onSlideTouch, _this, event); 1255 } 1256 1257 function setClickedSlide(event) { 1258 1259 // IE 6-8 support 1260 if (!event.currentTarget) { 1261 var element = event.srcElement; 1262 do { 1263 if (element.className.indexOf(params.slideClass) > -1) { 1264 break; 1265 } 1266 element = element.parentNode; 1267 } while (element); 1268 _this.clickedSlide = element; 1269 } 1270 else { 1271 _this.clickedSlide = event.currentTarget; 1272 } 1273 1274 _this.clickedSlideIndex = _this.slides.indexOf(_this.clickedSlide); 1275 _this.clickedSlideLoopIndex = _this.clickedSlideIndex - (_this.loopedSlides || 0); 1276 } 1277 1278 _this.allowLinks = true; 1279 function preventClick(e) { 1280 if (!_this.allowLinks) { 1281 if (e.preventDefault) e.preventDefault(); 1282 else e.returnValue = false; 1283 if (params.preventLinksPropagation && 'stopPropagation' in e) { 1284 e.stopPropagation(); 1285 } 1286 return false; 1287 } 1288 } 1289 function releaseForms(e) { 1290 if (e.stopPropagation) e.stopPropagation(); 1291 else e.returnValue = false; 1292 return false; 1293 1294 } 1295 1296 /*================================================== 1297 Event Handlers 1298 ====================================================*/ 1299 var isTouchEvent = false; 1300 var allowThresholdMove; 1301 var allowMomentumBounce = true; 1302 function onTouchStart(event) { 1303 if (params.preventLinks) _this.allowLinks = true; 1304 //Exit if slider is already was touched 1305 if (_this.isTouched || params.onlyExternal) { 1306 return false; 1307 } 1308 1309 // Blur active elements 1310 var eventTarget = event.target || event.srcElement; 1311 if (document.activeElement) { 1312 if (document.activeElement !== eventTarget) document.activeElement.blur(); 1313 } 1314 1315 // Form tag names 1316 var formTagNames = ('input select textarea').split(' '); 1317 1318 // Check for no swiping 1319 if (params.noSwiping && (eventTarget) && noSwipingSlide(eventTarget)) return false; 1320 allowMomentumBounce = false; 1321 //Check For Nested Swipers 1322 _this.isTouched = true; 1323 isTouchEvent = event.type === 'touchstart'; 1324 1325 // prevent user enter with right and the swiper move (needs isTouchEvent) 1326 if (!isTouchEvent && 'which' in event && event.which === 3) return false; 1327 1328 if (!isTouchEvent || event.targetTouches.length === 1) { 1329 _this.callPlugins('onTouchStartBegin'); 1330 if (!isTouchEvent && !_this.isAndroid && formTagNames.indexOf(eventTarget.tagName.toLowerCase()) < 0) { 1331 1332 if (event.preventDefault) event.preventDefault(); 1333 else event.returnValue = false; 1334 } 1335 1336 var pageX = isTouchEvent ? event.targetTouches[0].pageX : (event.pageX || event.clientX); 1337 var pageY = isTouchEvent ? event.targetTouches[0].pageY : (event.pageY || event.clientY); 1338 1339 //Start Touches to check the scrolling 1340 _this.touches.startX = _this.touches.currentX = pageX; 1341 _this.touches.startY = _this.touches.currentY = pageY; 1342 1343 _this.touches.start = _this.touches.current = isH ? pageX : pageY; 1344 1345 //Set Transition Time to 0 1346 _this.setWrapperTransition(0); 1347 1348 //Get Start Translate Position 1349 _this.positions.start = _this.positions.current = _this.getWrapperTranslate(); 1350 1351 //Set Transform 1352 _this.setWrapperTranslate(_this.positions.start); 1353 1354 //TouchStartTime 1355 _this.times.start = (new Date()).getTime(); 1356 1357 //Unset Scrolling 1358 isScrolling = undefined; 1359 1360 //Set Treshold 1361 if (params.moveStartThreshold > 0) { 1362 allowThresholdMove = false;
1363 } 1364 1365 //CallBack 1366 if (params.onTouchStart) _this.fireCallback(params.onTouchStart, _this, event); 1367 _this.callPlugins('onTouchStartEnd'); 1368 1369 } 1370 } 1371 var velocityPrevPosition, velocityPrevTime; 1372 function onTouchMove(event) { 1373 // If slider is not touched - exit 1374 if (!_this.isTouched || params.onlyExternal) return; 1375 if (isTouchEvent && event.type === 'mousemove') return; 1376 1377 var pageX = isTouchEvent ? event.targetTouches[0].pageX : (event.pageX || event.clientX); 1378 var pageY = isTouchEvent ? event.targetTouches[0].pageY : (event.pageY || event.clientY); 1379 1380 //check for scrolling 1381 if (typeof isScrolling === 'undefined' && isH) { 1382 isScrolling = !!(isScrolling || Math.abs(pageY - _this.touches.startY) > Math.abs(pageX - _this.touches.startX)); 1383 } 1384 if (typeof isScrolling === 'undefined' && !isH) { 1385 isScrolling = !!(isScrolling || Math.abs(pageY - _this.touches.startY) < Math.abs(pageX - _this.touches.startX)); 1386 } 1387 if (isScrolling) { 1388 _this.isTouched = false; 1389 return; 1390 } 1391 1392 // One way swipes 1393 if (isH) { 1394 if ((!params.swipeToNext && pageX < _this.touches.startX) || ((!params.swipeToPrev && pageX > _this.touches.startX))) { 1395 return; 1396 } 1397 } 1398 else { 1399 if ((!params.swipeToNext && pageY < _this.touches.startY) || ((!params.swipeToPrev && pageY > _this.touches.startY))) { 1400 return; 1401 } 1402 } 1403 1404 //Check For Nested Swipers 1405 if (event.assignedToSwiper) { 1406 _this.isTouched = false; 1407 return; 1408 } 1409 event.assignedToSwiper = true; 1410 1411 //Block inner links 1412 if (params.preventLinks) { 1413 _this.allowLinks = false; 1414 } 1415 if (params.onSlideClick) { 1416 _this.allowSlideClick = false; 1417 } 1418 1419 //Stop AutoPlay if exist 1420 if (params.autoplay) { 1421 _this.stopAutoplay(true); 1422 } 1423 if (!isTouchEvent || event.touches.length === 1) { 1424 1425 //Moved Flag 1426 if (!_this.isMoved) { 1427 _this.callPlugins('onTouchMoveStart'); 1428 1429 if (params.loop) { 1430 _this.fixLoop(); 1431 _this.positions.start = _this.getWrapperTranslate(); 1432 } 1433 if (params.onTouchMoveStart) _this.fireCallback(params.onTouchMoveStart, _this); 1434 } 1435 _this.isMoved = true; 1436 1437 // cancel event 1438 if (event.preventDefault) event.preventDefault(); 1439 else event.returnValue = false; 1440 1441 _this.touches.current = isH ? pageX : pageY; 1442 1443 _this.positions.current = (_this.touches.current - _this.touches.start) * params.touchRatio + _this.positions.start; 1444 1445 //Resistance Callbacks 1446 if (_this.positions.current > 0 && params.onResistanceBefore) { 1447 _this.fireCallback(params.onResistanceBefore, _this, _this.positions.current); 1448 } 1449 if (_this.positions.current < -maxWrapperPosition() && params.onResistanceAfter) { 1450 _this.fireCallback(params.onResistanceAfter, _this, Math.abs(_this.positions.current + maxWrapperPosition())); 1451 } 1452 //Resistance 1453 if (params.resistance && params.resistance !== '100%') { 1454 var resistance; 1455 //Resistance for Negative-Back sliding 1456 if (_this.positions.current > 0) { 1457 resistance = 1 - _this.positions.current / containerSize / 2; 1458 if (resistance < 0.5) 1459 _this.positions.current = (containerSize / 2); 1460 else 1461 _this.positions.current = _this.positions.current * resistance; 1462 } 1463 //Resistance for After-End Sliding 1464 if (_this.positions.current < -maxWrapperPosition()) { 1465 1466 var diff = (_this.touches.current - _this.touches.start) * params.touchRatio + (maxWrapperPosition() + _this.positions.start); 1467 resistance = (containerSize + diff) / (containerSize); 1468 var newPos = _this.positions.current - diff * (1 - resistance) / 2; 1469 var stopPos = -maxWrapperPosition() - containerSize / 2; 1470 1471 if (newPos < stopPos || resistance <= 0) 1472 _this.positions.current = stopPos; 1473 else 1474 _this.positions.current = newPos; 1475 } 1476 } 1477 if (params.resistance && params.resistance === '100%') { 1478 //Resistance for Negative-Back sliding 1479 if (_this.positions.current > 0 && !(params.freeMode && !params.freeModeFluid)) { 1480 _this.positions.current = 0; 1481 } 1482 //Resistance for After-End Sliding 1483 if (_this.positions.current < -maxWrapperPosition() && !(params.freeMode && !params.freeModeFluid)) { 1484 _this.positions.current = -maxWrapperPosition(); 1485 } 1486 } 1487 //Move Slides 1488 if (!params.followFinger) return; 1489 1490 if (!params.moveStartThreshold) { 1491 _this.setWrapperTranslate(_this.positions.current); 1492 } 1493 else { 1494 if (Math.abs(_this.touches.current - _this.touches.start) > params.moveStartThreshold || allowThresholdMove) { 1495 if (!allowThresholdMove) { 1496 allowThresholdMove = true; 1497 _this.touches.start = _this.touches.current; 1498 return; 1499 } 1500 _this.setWrapperTranslate(_this.positions.current); 1501 } 1502 else { 1503 _this.positions.current = _this.positions.start; 1504 } 1505 } 1506 1507 if (params.freeMode || params.watchActiveIndex) { 1508 _this.updateActiveSlide(_this.positions.current); 1509 } 1510 1511 //Grab Cursor 1512 if (params.grabCursor) { 1513 _this.container.style.cursor = 'move'; 1514 _this.container.style.cursor = 'grabbing'; 1515 _this.container.style.cursor = '-moz-grabbin'; 1516 _this.container.style.cursor = '-webkit-grabbing'; 1517 } 1518 //Velocity 1519 if (!velocityPrevPosition) velocityPrevPosition = _this.touches.current; 1520 if (!velocityPrevTime) velocityPrevTime = (new Date()).getTime(); 1521 _this.velocity = (_this.touches.current - velocityPrevPosition) / ((new Date()).getTime() - velocityPrevTime) / 2; 1522 if (Math.abs(_this.touches.current - velocityPrevPosition) < 2) _this.velocity = 0; 1523 velocityPrevPosition = _this.touches.current; 1524 velocityPrevTime = (new Date()).getTime(); 1525 //Callbacks 1526 _this.callPlugins('onTouchMoveEnd'); 1527 if (params.onTouchMove) _this.fireCallback(params.onTouchMove, _this, event); 1528 1529 return false;
1530 } 1531 } 1532 function onTouchEnd(event) { 1533 //Check For scrolling 1534 if (isScrolling) { 1535 _this.swipeReset(); 1536 } 1537 // If slider is not touched exit 1538 if (params.onlyExternal || !_this.isTouched) return; 1539 _this.isTouched = false; 1540 1541 //Return Grab Cursor 1542 if (params.grabCursor) { 1543 _this.container.style.cursor = 'move'; 1544 _this.container.style.cursor = 'grab'; 1545 _this.container.style.cursor = '-moz-grab'; 1546 _this.container.style.cursor = '-webkit-grab'; 1547 } 1548 1549 //Check for Current Position 1550 if (!_this.positions.current && _this.positions.current !== 0) { 1551 _this.positions.current = _this.positions.start; 1552 } 1553 1554 //For case if slider touched but not moved 1555 if (params.followFinger) { 1556 _this.setWrapperTranslate(_this.positions.current); 1557 } 1558 1559 // TouchEndTime 1560 _this.times.end = (new Date()).getTime(); 1561 1562 //Difference 1563 _this.touches.diff = _this.touches.current - _this.touches.start; 1564 _this.touches.abs = Math.abs(_this.touches.diff); 1565 1566 _this.positions.diff = _this.positions.current - _this.positions.start; 1567 _this.positions.abs = Math.abs(_this.positions.diff); 1568 1569 var diff = _this.positions.diff; 1570 var diffAbs = _this.positions.abs; 1571 var timeDiff = _this.times.end - _this.times.start; 1572 1573 if (diffAbs < 5 && (timeDiff) < 300 && _this.allowLinks === false) { 1574 if (!params.freeMode && diffAbs !== 0) _this.swipeReset(); 1575 //Release inner links 1576 if (params.preventLinks) { 1577 _this.allowLinks = true; 1578 } 1579 if (params.onSlideClick) { 1580 _this.allowSlideClick = true; 1581 } 1582 } 1583 1584 setTimeout(function () { 1585 //Release inner links 1586 if (typeof _this === 'undefined' || _this === null) return; 1587 if (params.preventLinks) { 1588 _this.allowLinks = true; 1589 } 1590 if (params.onSlideClick) { 1591 _this.allowSlideClick = true; 1592 } 1593 }, 100); 1594 1595 var maxPosition = maxWrapperPosition(); 1596 1597 //Not moved or Prevent Negative Back Sliding/After-End Sliding 1598 if (!_this.isMoved && params.freeMode) { 1599 _this.isMoved = false; 1600 if (params.onTouchEnd) _this.fireCallback(params.onTouchEnd, _this, event); 1601 _this.callPlugins('onTouchEnd'); 1602 return; 1603 } 1604 if (!_this.isMoved || _this.positions.current > 0 || _this.positions.current < -maxPosition) { 1605 _this.swipeReset(); 1606 if (params.onTouchEnd) _this.fireCallback(params.onTouchEnd, _this, event); 1607 _this.callPlugins('onTouchEnd'); 1608 return; 1609 } 1610 1611 _this.isMoved = false; 1612 1613 //Free Mode 1614 if (params.freeMode) { 1615 if (params.freeModeFluid) { 1616 var momentumDuration = 1000 * params.momentumRatio; 1617 var momentumDistance = _this.velocity * momentumDuration; 1618 var newPosition = _this.positions.current + momentumDistance; 1619 var doBounce = false; 1620 var afterBouncePosition; 1621 var bounceAmount = Math.abs(_this.velocity) * 20 * params.momentumBounceRatio; 1622 if (newPosition < -maxPosition) { 1623 if (params.momentumBounce && _this.support.transitions) { 1624 if (newPosition + maxPosition < -bounceAmount) newPosition = -maxPosition - bounceAmount; 1625 afterBouncePosition = -maxPosition; 1626 doBounce = true; 1627 allowMomentumBounce = true; 1628 } 1629 else newPosition = -maxPosition; 1630 } 1631 if (newPosition > 0) { 1632 if (params.momentumBounce && _this.support.transitions) { 1633 if (newPosition > bounceAmount) newPosition = bounceAmount; 1634 afterBouncePosition = 0; 1635 doBounce = true; 1636 allowMomentumBounce = true; 1637 } 1638 else newPosition = 0; 1639 } 1640 //Fix duration 1641 if (_this.velocity !== 0) momentumDuration = Math.abs((newPosition - _this.positions.current) / _this.velocity); 1642 1643 _this.setWrapperTranslate(newPosition); 1644 1645 _this.setWrapperTransition(momentumDuration); 1646 1647 if (params.momentumBounce && doBounce) { 1648 _this.wrapperTransitionEnd(function () { 1649 if (!allowMomentumBounce) return; 1650 if (params.onMomentumBounce) _this.fireCallback(params.onMomentumBounce, _this); 1651 _this.callPlugins('onMomentumBounce'); 1652 1653 _this.setWrapperTranslate(afterBouncePosition); 1654 _this.setWrapperTransition(300); 1655 }); 1656 } 1657 1658 _this.updateActiveSlide(newPosition); 1659 } 1660 if (!params.freeModeFluid || timeDiff >= 300) _this.updateActiveSlide(_this.positions.current); 1661 1662 if (params.onTouchEnd) _this.fireCallback(params.onTouchEnd, _this, event); 1663 _this.callPlugins('onTouchEnd'); 1664 return; 1665 } 1666 1667 //Direction 1668 direction = diff < 0 ? 'toNext' : 'toPrev'; 1669 1670 //Short Touches 1671 if (direction === 'toNext' && (timeDiff <= 300)) { 1672 if (diffAbs < 30 || !params.shortSwipes) _this.swipeReset(); 1673 else _this.swipeNext(true); 1674 } 1675 1676 if (direction === 'toPrev' && (timeDiff <= 300)) { 1677 if (diffAbs < 30 || !params.shortSwipes) _this.swipeReset(); 1678 else _this.swipePrev(true); 1679 } 1680 1681 //Long Touches 1682 var targetSlideSize = 0; 1683 if (params.slidesPerView === 'auto') { 1684 //Define current slide's width 1685 var currentPosition = Math.abs(_this.getWrapperTranslate()); 1686 var slidesOffset = 0; 1687 var _slideSize; 1688 for (var i = 0; i < _this.slides.length; i++) { 1689 _slideSize = isH ? _this.slides[i].getWidth(true, params.roundLengths) : _this.slides[i].getHeight(true, params.roundLengths); 1690 slidesOffset += _slideSize; 1691 if (slidesOffset > currentPosition) { 1692 targetSlideSize = _slideSize; 1693 break; 1694 } 1695 }
1696 if (targetSlideSize > containerSize) targetSlideSize = containerSize; 1697 } 1698 else { 1699 targetSlideSize = slideSize * params.slidesPerView; 1700 } 1701 if (direction === 'toNext' && (timeDiff > 300)) { 1702 if (diffAbs >= targetSlideSize * params.longSwipesRatio) { 1703 _this.swipeNext(true); 1704 } 1705 else { 1706 _this.swipeReset(); 1707 } 1708 } 1709 if (direction === 'toPrev' && (timeDiff > 300)) { 1710 if (diffAbs >= targetSlideSize * params.longSwipesRatio) { 1711 _this.swipePrev(true); 1712 } 1713 else { 1714 _this.swipeReset(); 1715 } 1716 } 1717 if (params.onTouchEnd) _this.fireCallback(params.onTouchEnd, _this, event); 1718 _this.callPlugins('onTouchEnd'); 1719 } 1720 1721 1722 /*================================================== 1723 noSwiping Bubble Check by Isaac Strack 1724 ====================================================*/ 1725 function noSwipingSlide(el) { 1726 /*This function is specifically designed to check the parent elements for the noSwiping class, up to the wrapper. 1727 We need to check parents because while onTouchStart bubbles, _this.isTouched is checked in onTouchStart, which stops the bubbling. 1728 So, if a text box, for example, is the initial target, and the parent slide container has the noSwiping class, the _this.isTouched 1729 check will never find it, and what was supposed to be noSwiping is able to be swiped. 1730 This function will iterate up and check for the noSwiping class in parents, up through the wrapperClass.*/ 1731 1732 // First we create a truthy variable, which is that swiping is allowd (noSwiping = false) 1733 var noSwiping = false; 1734 1735 // Now we iterate up (parentElements) until we reach the node with the wrapperClass. 1736 do { 1737 1738 // Each time, we check to see if there's a 'swiper-no-swiping' class (noSwipingClass). 1739 if (el.className.indexOf(params.noSwipingClass) > -1) 1740 { 1741 noSwiping = true; // If there is, we set noSwiping = true; 1742 } 1743 1744 el = el.parentElement; // now we iterate up (parent node) 1745 1746 } while (!noSwiping && el.parentElement && el.className.indexOf(params.wrapperClass) === -1); // also include el.parentElement truthy, just in case. 1747 1748 // because we didn't check the wrapper itself, we do so now, if noSwiping is false: 1749 if (!noSwiping && el.className.indexOf(params.wrapperClass) > -1 && el.className.indexOf(params.noSwipingClass) > -1) 1750 noSwiping = true; // if the wrapper has the noSwipingClass, we set noSwiping = true; 1751 1752 return noSwiping; 1753 } 1754 1755 function addClassToHtmlString(klass, outerHtml) { 1756 var par = document.createElement('div'); 1757 var child; 1758 1759 par.innerHTML = outerHtml; 1760 child = par.firstChild; 1761 child.className += ' ' + klass; 1762 1763 return child.outerHTML; 1764 } 1765 1766 1767 /*================================================== 1768 Swipe Functions 1769 ====================================================*/ 1770 _this.swipeNext = function (internal) { 1771 if (!internal && params.loop) _this.fixLoop(); 1772 if (!internal && params.autoplay) _this.stopAutoplay(true); 1773 _this.callPlugins('onSwipeNext'); 1774 var currentPosition = _this.getWrapperTranslate(); 1775 var newPosition = currentPosition; 1776 if (params.slidesPerView === 'auto') { 1777 for (var i = 0; i < _this.snapGrid.length; i++) { 1778 if (-currentPosition >= _this.snapGrid[i] && -currentPosition < _this.snapGrid[i + 1]) { 1779 newPosition = -_this.snapGrid[i + 1]; 1780 break; 1781 } 1782 } 1783 } 1784 else { 1785 var groupSize = slideSize * params.slidesPerGroup; 1786 newPosition = -(Math.floor(Math.abs(currentPosition) / Math.floor(groupSize)) * groupSize + groupSize); 1787 } 1788 if (newPosition < -maxWrapperPosition()) { 1789 newPosition = -maxWrapperPosition(); 1790 } 1791 if (newPosition === currentPosition) return false;
1792 swipeToPosition(newPosition, 'next'); 1793 return true; 1794 }; 1795 _this.swipePrev = function (internal) { 1796 if (!internal && params.loop) _this.fixLoop(); 1797 if (!internal && params.autoplay) _this.stopAutoplay(true); 1798 _this.callPlugins('onSwipePrev'); 1799 1800 var currentPosition = Math.ceil(_this.getWrapperTranslate()); 1801 var newPosition; 1802 if (params.slidesPerView === 'auto') { 1803 newPosition = 0; 1804 for (var i = 1; i < _this.snapGrid.length; i++) { 1805 if (-currentPosition === _this.snapGrid[i]) { 1806 newPosition = -_this.snapGrid[i - 1]; 1807 break; 1808 } 1809 if (-currentPosition > _this.snapGrid[i] && -currentPosition < _this.snapGrid[i + 1]) { 1810 newPosition = -_this.snapGrid[i]; 1811 break; 1812 } 1813 } 1814 } 1815 else { 1816 var groupSize = slideSize * params.slidesPerGroup; 1817 newPosition = -(Math.ceil(-currentPosition / groupSize) - 1) * groupSize; 1818 } 1819 1820 if (newPosition > 0) newPosition = 0; 1821 1822 if (newPosition === currentPosition) return false; 1823 swipeToPosition(newPosition, 'prev'); 1824 return true; 1825 1826 }; 1827 _this.swipeReset = function () { 1828 _this.callPlugins('onSwipeReset'); 1829 var currentPosition = _this.getWrapperTranslate(); 1830 var groupSize = slideSize * params.slidesPerGroup; 1831 var newPosition; 1832 var maxPosition = -maxWrapperPosition(); 1833 if (params.slidesPerView === 'auto') { 1834 newPosition = 0; 1835 for (var i = 0; i < _this.snapGrid.length; i++) { 1836 if (-currentPosition === _this.snapGrid[i]) return; 1837 if (-currentPosition >= _this.snapGrid[i] && -currentPosition < _this.snapGrid[i + 1]) { 1838 if (_this.positions.diff > 0) newPosition = -_this.snapGrid[i + 1]; 1839 else newPosition = -_this.snapGrid[i]; 1840 break; 1841 } 1842 } 1843 if (-currentPosition >= _this.snapGrid[_this.snapGrid.length - 1]) newPosition = -_this.snapGrid[_this.snapGrid.length - 1]; 1844 if (currentPosition <= -maxWrapperPosition()) newPosition = -maxWrapperPosition(); 1845 } 1846 else { 1847 newPosition = currentPosition < 0 ? Math.round(currentPosition / groupSize) * groupSize : 0; 1848 if (currentPosition <= -maxWrapperPosition()) newPosition = -maxWrapperPosition(); 1849 } 1850 if (params.scrollContainer) { 1851 newPosition = currentPosition < 0 ? currentPosition : 0; 1852 } 1853 if (newPosition < -maxWrapperPosition()) { 1854 newPosition = -maxWrapperPosition(); 1855 } 1856 if (params.scrollContainer && (containerSize > slideSize)) { 1857 newPosition = 0; 1858 } 1859 1860 if (newPosition === currentPosition) return false; 1861 1862 swipeToPosition(newPosition, 'reset'); 1863 return true; 1864 }; 1865 1866 _this.swipeTo = function (index, speed, runCallbacks) { 1867 index = parseInt(index, 10); 1868 _this.callPlugins('onSwipeTo', {index: index, speed: speed}); 1869 if (params.loop) index = index + _this.loopedSlides; 1870 var currentPosition = _this.getWrapperTranslate(); 1871 if (index > (_this.slides.length - 1) || index < 0) return; 1872 var newPosition; 1873 if (params.slidesPerView === 'auto') { 1874 newPosition = -_this.slidesGrid[index]; 1875 } 1876 else { 1877 newPosition = -index * slideSize; 1878 } 1879 if (newPosition < - maxWrapperPosition()) { 1880 newPosition = - maxWrapperPosition(); 1881 } 1882 1883 if (newPosition === currentPosition) return false; 1884 1885 runCallbacks = runCallbacks === false ? false : true; 1886 swipeToPosition(newPosition, 'to', {index: index, speed: speed, runCallbacks: runCallbacks}); 1887 return true; 1888 }; 1889 1890 function swipeToPosition(newPosition, action, toOptions) { 1891 var speed = (action === 'to' && toOptions.speed >= 0) ? toOptions.speed : params.speed; 1892 var timeOld = + new Date(); 1893 1894 function anim() { 1895 var timeNew = + new Date(); 1896 var time = timeNew - timeOld; 1897 currentPosition += animationStep * time / (1000 / 60); 1898 condition = direction === 'toNext' ? currentPosition > newPosition : currentPosition < newPosition; 1899 if (condition) { 1900 _this.setWrapperTranslate(Math.ceil(currentPosition)); 1901 _this._DOMAnimating = true; 1902 window.setTimeout(function () { 1903 anim(); 1904 }, 1000 / 60); 1905 } 1906 else { 1907 if (params.onSlideChangeEnd) { 1908 if (action === 'to') { 1909 if (toOptions.runCallbacks === true) _this.fireCallback(params.onSlideChangeEnd, _this, direction); 1910 } 1911 else { 1912 _this.fireCallback(params.onSlideChangeEnd, _this, direction); 1913 } 1914 1915 } 1916 _this.setWrapperTranslate(newPosition); 1917 _this._DOMAnimating = false;
1918 } 1919 } 1920 1921 if (_this.support.transitions || !params.DOMAnimation) { 1922 _this.setWrapperTranslate(newPosition); 1923 _this.setWrapperTransition(speed); 1924 } 1925 else { 1926 //Try the DOM animation 1927 var currentPosition = _this.getWrapperTranslate(); 1928 var animationStep = Math.ceil((newPosition - currentPosition) / speed * (1000 / 60)); 1929 var direction = currentPosition > newPosition ? 'toNext' : 'toPrev'; 1930 var condition = direction === 'toNext' ? currentPosition > newPosition : currentPosition < newPosition; 1931 if (_this._DOMAnimating) return; 1932 1933 anim(); 1934 } 1935 1936 //Update Active Slide Index 1937 _this.updateActiveSlide(newPosition); 1938 1939 //Callbacks 1940 if (params.onSlideNext && action === 'next') { 1941 _this.fireCallback(params.onSlideNext, _this, newPosition); 1942 } 1943 if (params.onSlidePrev && action === 'prev') { 1944 _this.fireCallback(params.onSlidePrev, _this, newPosition); 1945 } 1946 //'Reset' Callback 1947 if (params.onSlideReset && action === 'reset') { 1948 _this.fireCallback(params.onSlideReset, _this, newPosition); 1949 } 1950 1951 //'Next', 'Prev' and 'To' Callbacks 1952 if (action === 'next' || action === 'prev' || (action === 'to' && toOptions.runCallbacks === true)) 1953 slideChangeCallbacks(action); 1954 } 1955 /*================================================== 1956 Transition Callbacks 1957 ====================================================*/ 1958 //Prevent Multiple Callbacks 1959 _this._queueStartCallbacks = false; 1960 _this._queueEndCallbacks = false; 1961 function slideChangeCallbacks(direction) { 1962 //Transition Start Callback 1963 _this.callPlugins('onSlideChangeStart'); 1964 if (params.onSlideChangeStart) { 1965 if (params.queueStartCallbacks && _this.support.transitions) { 1966 if (_this._queueStartCallbacks) return; 1967 _this._queueStartCallbacks = true; 1968 _this.fireCallback(params.onSlideChangeStart, _this, direction); 1969 _this.wrapperTransitionEnd(function () { 1970 _this._queueStartCallbacks = false; 1971 }); 1972 } 1973 else _this.fireCallback(params.onSlideChangeStart, _this, direction); 1974 } 1975 //Transition End Callback 1976 if (params.onSlideChangeEnd) { 1977 if (_this.support.transitions) { 1978 if (params.queueEndCallbacks) { 1979 if (_this._queueEndCallbacks) return; 1980 _this._queueEndCallbacks = true; 1981 _this.wrapperTransitionEnd(function (swiper) { 1982 _this.fireCallback(params.onSlideChangeEnd, swiper, direction); 1983 }); 1984 } 1985 else { 1986 _this.wrapperTransitionEnd(function (swiper) { 1987 _this.fireCallback(params.onSlideChangeEnd, swiper, direction); 1988 }); 1989 } 1990 } 1991 else { 1992 if (!params.DOMAnimation) { 1993 setTimeout(function () { 1994 _this.fireCallback(params.onSlideChangeEnd, _this, direction); 1995 }, 10); 1996 } 1997 } 1998 } 1999 } 2000 2001 /*================================================== 2002 Update Active Slide Index 2003 ====================================================*/ 2004 _this.updateActiveSlide = function (position) { 2005 if (!_this.initialized) return; 2006 if (_this.slides.length === 0) return; 2007 _this.previousIndex = _this.activeIndex; 2008 if (typeof position === 'undefined') position = _this.getWrapperTranslate(); 2009 if (position > 0) position = 0; 2010 var i; 2011 if (params.slidesPerView === 'auto') { 2012 var slidesOffset = 0; 2013 _this.activeIndex = _this.slidesGrid.indexOf(-position); 2014 if (_this.activeIndex < 0) { 2015 for (i = 0; i < _this.slidesGrid.length - 1; i++) { 2016 if (-position > _this.slidesGrid[i] && -position < _this.slidesGrid[i + 1]) { 2017 break; 2018 } 2019 } 2020 var leftDistance = Math.abs(_this.slidesGrid[i] + position); 2021 var rightDistance = Math.abs(_this.slidesGrid[i + 1] + position); 2022 if (leftDistance <= rightDistance) _this.activeIndex = i; 2023 else _this.activeIndex = i + 1; 2024 } 2025 } 2026 else { 2027 _this.activeIndex = Math[params.visibilityFullFit ? 'ceil' : 'round'](-position / slideSize); 2028 } 2029 2030 if (_this.activeIndex === _this.slides.length) _this.activeIndex = _this.slides.length - 1; 2031 if (_this.activeIndex < 0) _this.activeIndex = 0; 2032 2033 // Check for slide 2034 if (!_this.slides[_this.activeIndex]) return; 2035 2036 // Calc Visible slides 2037 _this.calcVisibleSlides(position); 2038 2039 // Mark visible and active slides with additonal classes 2040 if (_this.support.classList) { 2041 var slide; 2042 for (i = 0; i < _this.slides.length; i++) { 2043 slide = _this.slides[i]; 2044 slide.classList.remove(params.slideActiveClass); 2045 if (_this.visibleSlides.indexOf(slide) >= 0) { 2046 slide.classList.add(params.slideVisibleClass); 2047 } else { 2048 slide.classList.remove(params.slideVisibleClass); 2049 } 2050 } 2051 _this.slides[_this.activeIndex].classList.add(params.slideActiveClass); 2052 } else { 2053 var activeClassRegexp = new RegExp('\\s*' + params.slideActiveClass); 2054 var inViewClassRegexp = new RegExp('\\s*' + params.slideVisibleClass); 2055 2056 for (i = 0; i < _this.slides.length; i++) { 2057 _this.slides[i].className = _this.slides[i].className.replace(activeClassRegexp, '').replace(inViewClassRegexp, ''); 2058 if (_this.visibleSlides.indexOf(_this.slides[i]) >= 0) { 2059 _this.slides[i].className += ' ' + params.slideVisibleClass; 2060 } 2061 } 2062 _this.slides[_this.activeIndex].className += ' ' + params.slideActiveClass; 2063 } 2064 2065 //Update loop index 2066 if (params.loop) { 2067 var ls = _this.loopedSlides; 2068 _this.activeLoopIndex = _this.activeIndex - ls; 2069 if (_this.activeLoopIndex >= _this.slides.length - ls * 2) { 2070 _this.activeLoopIndex = _this.slides.length - ls * 2 - _this.activeLoopIndex; 2071 } 2072 if (_this.activeLoopIndex < 0) { 2073 _this.activeLoopIndex = _this.slides.length - ls * 2 + _this.activeLoopIndex; 2074 } 2075 if (_this.activeLoopIndex < 0) _this.activeLoopIndex = 0; 2076 } 2077 else { 2078 _this.activeLoopIndex = _this.activeIndex; 2079 } 2080 //Update Pagination 2081 if (params.pagination) { 2082 _this.updatePagination(position); 2083 } 2084 }; 2085 /*================================================== 2086 Pagination 2087 ====================================================*/ 2088 _this.createPagination = function (firstInit) { 2089 if (params.paginationClickable && _this.paginationButtons) { 2090 removePaginationEvents(); 2091 } 2092 _this.paginationContainer = params.pagination.nodeType ? params.pagination : $$(params.pagination)[0]; 2093 if (params.createPagination) { 2094 var paginationHTML = ''; 2095 var numOfSlides = _this.slides.length; 2096 var numOfButtons = numOfSlides; 2097 if (params.loop) numOfButtons -= _this.loopedSlides * 2; 2098 for (var i = 0; i < numOfButtons; i++) { 2099 paginationHTML += '<' + params.paginationElement + ' class="' + params.paginationElementClass + '"></' + params.paginationElement + '>'; 2100 } 2101 _this.paginationContainer.innerHTML = paginationHTML; 2102 } 2103 _this.paginationButtons = $$('.' + params.paginationElementClass, _this.paginationContainer); 2104 if (!firstInit) _this.updatePagination(); 2105 _this.callPlugins('onCreatePagination'); 2106 if (params.paginationClickable) { 2107 addPaginationEvents(); 2108 } 2109 }; 2110 function removePaginationEvents() { 2111 var pagers = _this.paginationButtons; 2112 if (pagers) { 2113 for (var i = 0; i < pagers.length; i++) {
2114 _this.h.removeEventListener(pagers[i], 'click', paginationClick); 2115 } 2116 } 2117 } 2118 function addPaginationEvents() { 2119 var pagers = _this.paginationButtons; 2120 if (pagers) { 2121 for (var i = 0; i < pagers.length; i++) { 2122 _this.h.addEventListener(pagers[i], 'click', paginationClick); 2123 } 2124 } 2125 } 2126 function paginationClick(e) { 2127 var index; 2128 var target = e.target || e.srcElement; 2129 var pagers = _this.paginationButtons; 2130 for (var i = 0; i < pagers.length; i++) { 2131 if (target === pagers[i]) index = i; 2132 } 2133 if (params.autoplay) _this.stopAutoplay(true); 2134 _this.swipeTo(index); 2135 } 2136 _this.updatePagination = function (position) { 2137 if (!params.pagination) return; 2138 if (_this.slides.length < 1) return; 2139 var activePagers = $$('.' + params.paginationActiveClass, _this.paginationContainer); 2140 if (!activePagers) return; 2141 2142 //Reset all Buttons' class to not active 2143 var pagers = _this.paginationButtons; 2144 if (pagers.length === 0) return; 2145 for (var i = 0; i < pagers.length; i++) { 2146 pagers[i].className = params.paginationElementClass; 2147 } 2148 2149 var indexOffset = params.loop ? _this.loopedSlides : 0; 2150 if (params.paginationAsRange) { 2151 if (!_this.visibleSlides) _this.calcVisibleSlides(position); 2152 //Get Visible Indexes 2153 var visibleIndexes = []; 2154 var j; // lopp index - avoid JSHint W004 / W038 2155 for (j = 0; j < _this.visibleSlides.length; j++) { 2156 var visIndex = _this.slides.indexOf(_this.visibleSlides[j]) - indexOffset; 2157 2158 if (params.loop && visIndex < 0) { 2159 visIndex = _this.slides.length - _this.loopedSlides * 2 + visIndex; 2160 } 2161 if (params.loop && visIndex >= _this.slides.length - _this.loopedSlides * 2) { 2162 visIndex = _this.slides.length - _this.loopedSlides * 2 - visIndex; 2163 visIndex = Math.abs(visIndex); 2164 } 2165 visibleIndexes.push(visIndex); 2166 } 2167 2168 for (j = 0; j < visibleIndexes.length; j++) { 2169 if (pagers[visibleIndexes[j]]) pagers[visibleIndexes[j]].className += ' ' + params.paginationVisibleClass; 2170 } 2171 2172 if (params.loop) { 2173 if (pagers[_this.activeLoopIndex] !== undefined) { 2174 pagers[_this.activeLoopIndex].className += ' ' + params.paginationActiveClass; 2175 } 2176 } 2177 else { 2178 pagers[_this.activeIndex].className += ' ' + params.paginationActiveClass; 2179 } 2180 } 2181 else { 2182 if (params.loop) { 2183 if (pagers[_this.activeLoopIndex]) pagers[_this.activeLoopIndex].className += ' ' + params.paginationActiveClass + ' ' + params.paginationVisibleClass; 2184 } 2185 else { 2186 pagers[_this.activeIndex].className += ' ' + params.paginationActiveClass + ' ' + params.paginationVisibleClass; 2187 } 2188 } 2189 }; 2190 _this.calcVisibleSlides = function (position) { 2191 var visibleSlides = []; 2192 var _slideLeft = 0, _slideSize = 0, _slideRight = 0; 2193 if (isH && _this.wrapperLeft > 0) position = position + _this.wrapperLeft; 2194 if (!isH && _this.wrapperTop > 0) position = position + _this.wrapperTop; 2195 2196 for (var i = 0; i < _this.slides.length; i++) { 2197 _slideLeft += _slideSize; 2198 if (params.slidesPerView === 'auto') 2199 _slideSize = isH ? _this.h.getWidth(_this.slides[i], true, params.roundLengths) : _this.h.getHeight(_this.slides[i], true, params.roundLengths); 2200 else _slideSize = slideSize; 2201 2202 _slideRight = _slideLeft + _slideSize; 2203 var isVisibile = false; 2204 if (params.visibilityFullFit) { 2205 if (_slideLeft >= -position && _slideRight <= -position + containerSize) isVisibile = true; 2206 if (_slideLeft <= -position && _slideRight >= -position + containerSize) isVisibile = true; 2207 } 2208 else { 2209 if (_slideRight > -position && _slideRight <= ((-position + containerSize))) isVisibile = true; 2210 if (_slideLeft >= -position && _slideLeft < ((-position + containerSize))) isVisibile = true; 2211 if (_slideLeft < -position && _slideRight > ((-position + containerSize))) isVisibile = true; 2212 } 2213 2214 if (isVisibile) visibleSlides.push(_this.slides[i]); 2215 2216 } 2217 if (visibleSlides.length === 0) visibleSlides = [_this.slides[_this.activeIndex]]; 2218 2219 _this.visibleSlides = visibleSlides; 2220 }; 2221 2222 /*========================================== 2223 Autoplay 2224 ============================================*/ 2225 var autoplayTimeoutId, autoplayIntervalId; 2226 _this.startAutoplay = function () { 2227 if (_this.support.transitions) { 2228 if (typeof autoplayTimeoutId !== 'undefined') return false;
2229 if (!params.autoplay) return; 2230 _this.callPlugins('onAutoplayStart'); 2231 if (params.onAutoplayStart) _this.fireCallback(params.onAutoplayStart, _this); 2232 autoplay(); 2233 } 2234 else { 2235 if (typeof autoplayIntervalId !== 'undefined') return false; 2236 if (!params.autoplay) return; 2237 _this.callPlugins('onAutoplayStart'); 2238 if (params.onAutoplayStart) _this.fireCallback(params.onAutoplayStart, _this); 2239 autoplayIntervalId = setInterval(function () { 2240 if (params.loop) { 2241 _this.fixLoop(); 2242 _this.swipeNext(true); 2243 } 2244 else if (!_this.swipeNext(true)) { 2245 if (!params.autoplayStopOnLast) _this.swipeTo(0); 2246 else { 2247 clearInterval(autoplayIntervalId); 2248 autoplayIntervalId = undefined; 2249 } 2250 } 2251 }, params.autoplay); 2252 } 2253 }; 2254 _this.stopAutoplay = function (internal) { 2255 if (_this.support.transitions) { 2256 if (!autoplayTimeoutId) return; 2257 if (autoplayTimeoutId) clearTimeout(autoplayTimeoutId); 2258 autoplayTimeoutId = undefined; 2259 if (internal && !params.autoplayDisableOnInteraction) { 2260 _this.wrapperTransitionEnd(function () { 2261 autoplay(); 2262 }); 2263 } 2264 _this.callPlugins('onAutoplayStop'); 2265 if (params.onAutoplayStop) _this.fireCallback(params.onAutoplayStop, _this); 2266 } 2267 else { 2268 if (autoplayIntervalId) clearInterval(autoplayIntervalId); 2269 autoplayIntervalId = undefined; 2270 _this.callPlugins('onAutoplayStop'); 2271 if (params.onAutoplayStop) _this.fireCallback(params.onAutoplayStop, _this); 2272 } 2273 }; 2274 function autoplay() { 2275 autoplayTimeoutId = setTimeout(function () { 2276 if (params.loop) { 2277 _this.fixLoop(); 2278 _this.swipeNext(true); 2279 } 2280 else if (!_this.swipeNext(true)) { 2281 if (!params.autoplayStopOnLast) _this.swipeTo(0); 2282 else { 2283 clearTimeout(autoplayTimeoutId); 2284 autoplayTimeoutId = undefined; 2285 } 2286 } 2287 _this.wrapperTransitionEnd(function () { 2288 if (typeof autoplayTimeoutId !== 'undefined') autoplay(); 2289 }); 2290 }, params.autoplay); 2291 } 2292 /*================================================== 2293 Loop 2294 ====================================================*/ 2295 _this.loopCreated = false; 2296 _this.removeLoopedSlides = function () { 2297 if (_this.loopCreated) { 2298 for (var i = 0; i < _this.slides.length; i++) { 2299 if (_this.slides[i].getData('looped') === true) _this.wrapper.removeChild(_this.slides[i]); 2300 } 2301 } 2302 }; 2303 2304 _this.createLoop = function () { 2305 if (_this.slides.length === 0) return; 2306 if (params.slidesPerView === 'auto') { 2307 _this.loopedSlides = params.loopedSlides || 1; 2308 } 2309 else { 2310 _this.loopedSlides = params.slidesPerView + params.loopAdditionalSlides; 2311 } 2312 2313 if (_this.loopedSlides > _this.slides.length) { 2314 _this.loopedSlides = _this.slides.length; 2315 } 2316 2317 var slideFirstHTML = '', 2318 slideLastHTML = '', 2319 i; 2320 var slidesSetFullHTML = ''; 2321 /** 2322 loopedSlides is too large if loopAdditionalSlides are set. 2323 Need to divide the slides by maximum number of slides existing. 2324 2325 @author Tomaz Lovrec <[email protected]> 2326 */ 2327 var numSlides = _this.slides.length; 2328 var fullSlideSets = Math.floor(_this.loopedSlides / numSlides); 2329 var remainderSlides = _this.loopedSlides % numSlides; 2330 // assemble full sets of slides 2331 for (i = 0; i < (fullSlideSets * numSlides); i++) { 2332 var j = i; 2333 if (i >= numSlides) { 2334 var over = Math.floor(i / numSlides);
2335 j = i - (numSlides * over); 2336 } 2337 slidesSetFullHTML += _this.slides[j].outerHTML; 2338 } 2339 // assemble remainder slides 2340 // assemble remainder appended to existing slides 2341 for (i = 0; i < remainderSlides;i++) { 2342 slideLastHTML += addClassToHtmlString(params.slideDuplicateClass, _this.slides[i].outerHTML); 2343 } 2344 // assemble slides that get preppended to existing slides 2345 for (i = numSlides - remainderSlides; i < numSlides;i++) { 2346 slideFirstHTML += addClassToHtmlString(params.slideDuplicateClass, _this.slides[i].outerHTML); 2347 } 2348 // assemble all slides 2349 var slides = slideFirstHTML + slidesSetFullHTML + wrapper.innerHTML + slidesSetFullHTML + slideLastHTML; 2350 // set the slides 2351 wrapper.innerHTML = slides; 2352 2353 _this.loopCreated = true; 2354 _this.calcSlides(); 2355 2356 //Update Looped Slides with special class 2357 for (i = 0; i < _this.slides.length; i++) { 2358 if (i < _this.loopedSlides || i >= _this.slides.length - _this.loopedSlides) _this.slides[i].setData('looped', true); 2359 } 2360 _this.callPlugins('onCreateLoop'); 2361 2362 }; 2363 2364 _this.fixLoop = function () { 2365 var newIndex; 2366 //Fix For Negative Oversliding 2367 if (_this.activeIndex < _this.loopedSlides) { 2368 newIndex = _this.slides.length - _this.loopedSlides * 3 + _this.activeIndex; 2369 _this.swipeTo(newIndex, 0, false); 2370 } 2371 //Fix For Positive Oversliding 2372 else if ((params.slidesPerView === 'auto' && _this.activeIndex >= _this.loopedSlides * 2) || (_this.activeIndex > _this.slides.length - params.slidesPerView * 2)) { 2373 newIndex = -_this.slides.length + _this.activeIndex + _this.loopedSlides; 2374 _this.swipeTo(newIndex, 0, false); 2375 } 2376 }; 2377 2378 /*================================================== 2379 Slides Loader 2380 ====================================================*/ 2381 _this.loadSlides = function () { 2382 var slidesHTML = ''; 2383 _this.activeLoaderIndex = 0; 2384 var slides = params.loader.slides; 2385 var slidesToLoad = params.loader.loadAllSlides ? slides.length : params.slidesPerView * (1 + params.loader.surroundGroups); 2386 for (var i = 0; i < slidesToLoad; i++) { 2387 if (params.loader.slidesHTMLType === 'outer') slidesHTML += slides[i]; 2388 else { 2389 slidesHTML += '<' + params.slideElement + ' class="' + params.slideClass + '" data-swiperindex="' + i + '">' + slides[i] + '</' + params.slideElement + '>'; 2390 } 2391 } 2392 _this.wrapper.innerHTML = slidesHTML; 2393 _this.calcSlides(true); 2394 //Add permanent transitionEnd callback 2395 if (!params.loader.loadAllSlides) { 2396 _this.wrapperTransitionEnd(_this.reloadSlides, true); 2397 } 2398 }; 2399 2400 _this.reloadSlides = function () { 2401 var slides = params.loader.slides; 2402 var newActiveIndex = parseInt(_this.activeSlide().data('swiperindex'), 10); 2403 if (newActiveIndex < 0 || newActiveIndex > slides.length - 1) return; //<-- Exit 2404 _this.activeLoaderIndex = newActiveIndex; 2405 var firstIndex = Math.max(0, newActiveIndex - params.slidesPerView * params.loader.surroundGroups); 2406 var lastIndex = Math.min(newActiveIndex + params.slidesPerView * (1 + params.loader.surroundGroups) - 1, slides.length - 1); 2407 //Update Transforms 2408 if (newActiveIndex > 0) { 2409 var newTransform = -slideSize * (newActiveIndex - firstIndex); 2410 _this.setWrapperTranslate(newTransform); 2411 _this.setWrapperTransition(0); 2412 } 2413 var i; // loop index 2414 //New Slides 2415 if (params.loader.logic === 'reload') { 2416 _this.wrapper.innerHTML = ''; 2417 var slidesHTML = ''; 2418 for (i = firstIndex; i <= lastIndex; i++) { 2419 slidesHTML += params.loader.slidesHTMLType === 'outer' ? slides[i] : '<' + params.slideElement + ' class="' + params.slideClass + '" data-swiperindex="' + i + '">' + slides[i] + '</' + params.slideElement + '>'; 2420 } 2421 _this.wrapper.innerHTML = slidesHTML; 2422 } 2423 else { 2424 var minExistIndex = 1000; 2425 var maxExistIndex = 0; 2426 2427 for (i = 0; i < _this.slides.length; i++) { 2428 var index = _this.slides[i].data('swiperindex'); 2429 if (index < firstIndex || index > lastIndex) { 2430 _this.wrapper.removeChild(_this.slides[i]); 2431 } 2432 else { 2433 minExistIndex = Math.min(index, minExistIndex); 2434 maxExistIndex = Math.max(index, maxExistIndex); 2435 } 2436 } 2437 for (i = firstIndex; i <= lastIndex; i++) { 2438 var newSlide; 2439 if (i < minExistIndex) { 2440 newSlide = document.createElement(params.slideElement); 2441 newSlide.className = params.slideClass; 2442 newSlide.setAttribute('data-swiperindex', i); 2443 newSlide.innerHTML = slides[i]; 2444 _this.wrapper.insertBefore(newSlide, _this.wrapper.firstChild); 2445 } 2446 if (i > maxExistIndex) { 2447 newSlide = document.createElement(params.slideElement); 2448 newSlide.className = params.slideClass; 2449 newSlide.setAttribute('data-swiperindex', i); 2450 newSlide.innerHTML = slides[i]; 2451 _this.wrapper.appendChild(newSlide); 2452 } 2453 } 2454 } 2455 //reInit 2456 _this.reInit(true); 2457 }; 2458 2459 /*================================================== 2460 Make Swiper 2461 ====================================================*/ 2462 function makeSwiper() { 2463 _this.calcSlides(); 2464 if (params.loader.slides.length > 0 && _this.slides.length === 0) { 2465 _this.loadSlides(); 2466 } 2467 if (params.loop) { 2468 _this.createLoop(); 2469 } 2470 _this.init(); 2471 initEvents(); 2472 if (params.pagination) { 2473 _this.createPagination(true); 2474 } 2475 2476 if (params.loop || params.initialSlide > 0) { 2477 _this.swipeTo(params.initialSlide, 0, false); 2478 } 2479 else { 2480 _this.updateActiveSlide(0); 2481 } 2482 if (params.autoplay) { 2483 _this.startAutoplay(); 2484 } 2485 /** 2486 * Set center slide index. 2487 * 2488 * @author Tomaz Lovrec <[email protected]> 2489 */ 2490 _this.centerIndex = _this.activeIndex; 2491 2492 // Callbacks 2493 if (params.onSwiperCreated) _this.fireCallback(params.onSwiperCreated, _this); 2494 _this.callPlugins('onSwiperCreated'); 2495 } 2496 2497 makeSwiper(); 2498}; 2499 2500Swiper.prototype = { 2501 plugins : {}, 2502 2503 /*================================================== 2504 Wrapper Operations 2505 ====================================================*/ 2506 wrapperTransitionEnd : function (callback, permanent) { 2507 'use strict'; 2508 var a = this, 2509 el = a.wrapper,
2510 events = ['webkitTransitionEnd', 'transitionend', 'oTransitionEnd', 'MSTransitionEnd', 'msTransitionEnd'], 2511 i; 2512 2513 function fireCallBack(e) { 2514 if (e.target !== el) return; 2515 callback(a); 2516 if (a.params.queueEndCallbacks) a._queueEndCallbacks = false; 2517 if (!permanent) { 2518 for (i = 0; i < events.length; i++) { 2519 a.h.removeEventListener(el, events[i], fireCallBack); 2520 } 2521 } 2522 } 2523 2524 if (callback) { 2525 for (i = 0; i < events.length; i++) { 2526 a.h.addEventListener(el, events[i], fireCallBack); 2527 } 2528 } 2529 }, 2530 2531 getWrapperTranslate : function (axis) { 2532 'use strict'; 2533 var el = this.wrapper, 2534 matrix, curTransform, curStyle, transformMatrix; 2535 2536 // automatic axis detection 2537 if (typeof axis === 'undefined') { 2538 axis = this.params.mode === 'horizontal' ? 'x' : 'y'; 2539 } 2540 2541 if (this.support.transforms && this.params.useCSS3Transforms) { 2542 curStyle = window.getComputedStyle(el, null); 2543 if (window.WebKitCSSMatrix) { 2544 // Some old versions of Webkit choke when 'none' is passed; pass 2545 // empty string instead in this case 2546 transformMatrix = new WebKitCSSMatrix(curStyle.webkitTransform === 'none' ? '' : curStyle.webkitTransform); 2547 } 2548 else { 2549 transformMatrix = curStyle.MozTransform || curStyle.OTransform || curStyle.MsTransform || curStyle.msTransform || curStyle.transform || curStyle.getPropertyValue('transform').replace('translate(', 'matrix(1, 0, 0, 1,'); 2550 matrix = transformMatrix.toString().split(','); 2551 } 2552 2553 if (axis === 'x') { 2554 //Latest Chrome and webkits Fix 2555 if (window.WebKitCSSMatrix) 2556 curTransform = transformMatrix.m41; 2557 //Crazy IE10 Matrix 2558 else if (matrix.length === 16) 2559 curTransform = parseFloat(matrix[12]); 2560 //Normal Browsers 2561 else 2562 curTransform = parseFloat(matrix[4]); 2563 } 2564 if (axis === 'y') { 2565 //Latest Chrome and webkits Fix 2566 if (window.WebKitCSSMatrix) 2567 curTransform = transformMatrix.m42; 2568 //Crazy IE10 Matrix 2569 else if (matrix.length === 16) 2570 curTransform = parseFloat(matrix[13]); 2571 //Normal Browsers 2572 else 2573 curTransform = parseFloat(matrix[5]); 2574 } 2575 } 2576 else { 2577 if (axis === 'x') curTransform = parseFloat(el.style.left, 10) || 0; 2578 if (axis === 'y') curTransform = parseFloat(el.style.top, 10) || 0; 2579 } 2580 return curTransform || 0; 2581 }, 2582 2583 setWrapperTranslate : function (x, y, z) { 2584 'use strict'; 2585 var es = this.wrapper.style, 2586 coords = {x: 0, y: 0, z: 0}, 2587 translate; 2588 2589 // passed all coordinates 2590 if (arguments.length === 3) { 2591 coords.x = x; 2592 coords.y = y; 2593 coords.z = z; 2594 } 2595 2596 // passed one coordinate and optional axis 2597 else { 2598 if (typeof y === 'undefined') { 2599 y = this.params.mode === 'horizontal' ? 'x' : 'y'; 2600 } 2601 coords[y] = x; 2602 } 2603 2604 if (this.support.transforms && this.params.useCSS3Transforms) { 2605 translate = this.support.transforms3d ? 'translate3d(' + coords.x + 'px, ' + coords.y + 'px, ' + coords.z + 'px)' : 'translate(' + coords.x + 'px, ' + coords.y + 'px)'; 2606 es.webkitTransform = es.MsTransform = es.msTransform = es.MozTransform = es.OTransform = es.transform = translate; 2607 } 2608 else { 2609 es.left = coords.x + 'px'; 2610 es.top = coords.y + 'px'; 2611 } 2612 this.callPlugins('onSetWrapperTransform', coords); 2613 if (this.params.onSetWrapperTransform) this.fireCallback(this.params.onSetWrapperTransform, this, coords); 2614 }, 2615 2616 setWrapperTransition : function (duration) { 2617 'use strict'; 2618 var es = this.wrapper.style; 2619 es.webkitTransitionDuration = es.MsTransitionDuration = es.msTransitionDuration = es.MozTransitionDuration = es.OTransitionDuration = es.transitionDuration = (duration / 1000) + 's'; 2620 this.callPlugins('onSetWrapperTransition', {duration: duration}); 2621 if (this.params.onSetWrapperTransition) this.fireCallback(this.params.onSetWrapperTransition, this, duration); 2622 2623 }, 2624 2625 /*================================================== 2626 Helpers 2627 ====================================================*/ 2628 h : { 2629 getWidth: function (el, outer, round) { 2630 'use strict'; 2631 var width = window.getComputedStyle(el, null).getPropertyValue('width'); 2632 var returnWidth = parseFloat(width); 2633 //IE Fixes 2634 if (isNaN(returnWidth) || width.indexOf('%') > 0 || returnWidth < 0) { 2635 returnWidth = el.offsetWidth - parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-left')) - parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-right')); 2636 } 2637 if (outer) returnWidth += parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-left')) + parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-right')); 2638 if (round) return Math.ceil(returnWidth); 2639 else return returnWidth; 2640 }, 2641 getHeight: function (el, outer, round) { 2642 'use strict'; 2643 if (outer) return el.offsetHeight; 2644 2645 var height = window.getComputedStyle(el, null).getPropertyValue('height'); 2646 var returnHeight = parseFloat(height); 2647 //IE Fixes 2648 if (isNaN(returnHeight) || height.indexOf('%') > 0 || returnHeight < 0) { 2649 returnHeight = el.offsetHeight - parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-top')) - parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-bottom')); 2650 } 2651 if (outer) returnHeight += parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-top')) + parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-bottom')); 2652 if (round) return Math.ceil(returnHeight); 2653 else return returnHeight; 2654 }, 2655 getOffset: function (el) { 2656 'use strict'; 2657 var box = el.getBoundingClientRect(); 2658 var body = document.body; 2659 var clientTop = el.clientTop || body.clientTop || 0; 2660 var clientLeft = el.clientLeft || body.clientLeft || 0; 2661 var scrollTop = window.pageYOffset || el.scrollTop; 2662 var scrollLeft = window.pageXOffset || el.scrollLeft; 2663 if (document.documentElement && !window.pageYOffset) { 2664 //IE7-8 2665 scrollTop = document.documentElement.scrollTop; 2666 scrollLeft = document.documentElement.scrollLeft; 2667 } 2668 return { 2669 top: box.top + scrollTop - clientTop, 2670 left: box.left + scrollLeft - clientLeft 2671 }; 2672 }, 2673 windowWidth : function () { 2674 'use strict'; 2675 if (window.innerWidth) return window.innerWidth; 2676 else if (document.documentElement && document.documentElement.clientWidth) return document.documentElement.clientWidth; 2677 }, 2678 windowHeight : function () { 2679 'use strict'; 2680 if (window.innerHeight) return window.innerHeight; 2681 else if (document.documentElement && document.documentElement.clientHeight) return document.documentElement.clientHeight; 2682 }, 2683 windowScroll : function () { 2684 'use strict'; 2685 if (typeof pageYOffset !== 'undefined') { 2686 return { 2687 left: window.pageXOffset, 2688 top: window.pageYOffset 2689 }; 2690 } 2691 else if (document.documentElement) { 2692 return { 2693 left: document.documentElement.scrollLeft, 2694 top: document.documentElement.scrollTop 2695 }; 2696 } 2697 }, 2698 2699 addEventListener : function (el, event, listener, useCapture) { 2700 'use strict'; 2701 if (typeof useCapture === 'undefined') { 2702 useCapture = false;
2703 } 2704 2705 if (el.addEventListener) { 2706 el.addEventListener(event, listener, useCapture); 2707 } 2708 else if (el.attachEvent) { 2709 el.attachEvent('on' + event, listener); 2710 } 2711 }, 2712 2713 removeEventListener : function (el, event, listener, useCapture) { 2714 'use strict'; 2715 if (typeof useCapture === 'undefined') { 2716 useCapture = false; 2717 } 2718 2719 if (el.removeEventListener) { 2720 el.removeEventListener(event, listener, useCapture); 2721 } 2722 else if (el.detachEvent) { 2723 el.detachEvent('on' + event, listener); 2724 } 2725 } 2726 }, 2727 setTransform : function (el, transform) { 2728 'use strict'; 2729 var es = el.style; 2730 es.webkitTransform = es.MsTransform = es.msTransform = es.MozTransform = es.OTransform = es.transform = transform; 2731 }, 2732 setTranslate : function (el, translate) { 2733 'use strict'; 2734 var es = el.style; 2735 var pos = { 2736 x : translate.x || 0, 2737 y : translate.y || 0, 2738 z : translate.z || 0 2739 }; 2740 var transformString = this.support.transforms3d ? 'translate3d(' + (pos.x) + 'px,' + (pos.y) + 'px,' + (pos.z) + 'px)' : 'translate(' + (pos.x) + 'px,' + (pos.y) + 'px)'; 2741 es.webkitTransform = es.MsTransform = es.msTransform = es.MozTransform = es.OTransform = es.transform = transformString; 2742 if (!this.support.transforms) { 2743 es.left = pos.x + 'px'; 2744 es.top = pos.y + 'px'; 2745 } 2746 }, 2747 setTransition : function (el, duration) { 2748 'use strict'; 2749 var es = el.style; 2750 es.webkitTransitionDuration = es.MsTransitionDuration = es.msTransitionDuration = es.MozTransitionDuration = es.OTransitionDuration = es.transitionDuration = duration + 'ms'; 2751 }, 2752 /*================================================== 2753 Feature Detection 2754 ====================================================*/ 2755 support: { 2756 2757 touch : (window.Modernizr && Modernizr.touch === true) || (function () { 2758 'use strict'; 2759 return !!(('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch); 2760 })(), 2761 2762 transforms3d : (window.Modernizr && Modernizr.csstransforms3d === true) || (function () { 2763 'use strict'; 2764 var div = document.createElement('div').style; 2765 return ('webkitPerspective' in div || 'MozPerspective' in div || 'OPerspective' in div || 'MsPerspective' in div || 'perspective' in div); 2766 })(), 2767 2768 transforms : (window.Modernizr && Modernizr.csstransforms === true) || (function () { 2769 'use strict'; 2770 var div = document.createElement('div').style; 2771 return ('transform' in div || 'WebkitTransform' in div || 'MozTransform' in div || 'msTransform' in div || 'MsTransform' in div || 'OTransform' in div); 2772 })(), 2773 2774 transitions : (window.Modernizr && Modernizr.csstransitions === true) || (function () { 2775 'use strict'; 2776 var div = document.createElement('div').style; 2777 return ('transition' in div || 'WebkitTransition' in div || 'MozTransition' in div || 'msTransition' in div || 'MsTransition' in div || 'OTransition' in div); 2778 })(), 2779 2780 classList : (function () { 2781 'use strict'; 2782 var div = document.createElement('div'); 2783 return 'classList' in div; 2784 })() 2785 }, 2786 2787 browser : { 2788 2789 ie8 : (function () { 2790 'use strict'; 2791 var rv = -1; // Return value assumes failure. 2792 if (navigator.appName === 'Microsoft Internet Explorer') { 2793 var ua = navigator.userAgent; 2794 var re = new RegExp(/MSIE ([0-9]{1,}[\.0-9]{0,})/); 2795 if (re.exec(ua) !== null) 2796 rv = parseFloat(RegExp.$1); 2797 } 2798 return rv !== -1 && rv < 9; 2799 })(), 2800 2801 ie10 : window.navigator.msPointerEnabled, 2802 ie11 : window.navigator.pointerEnabled 2803 } 2804}; 2805 2806/*========================= 2807 jQuery & Zepto Plugins 2808 ===========================*/ 2809if (window.jQuery || window.Zepto) { 2810 (function ($) { 2811 'use strict'; 2812 $.fn.swiper = function (params) { 2813 var firstInstance; 2814 this.each(function (i) { 2815 var that = $(this); 2816 if (!that.data('swiper')) { 2817 var s = new Swiper(that[0], params); 2818 if (!i) firstInstance = s; 2819 that.data('swiper', s); 2820 } 2821 }); 2822 return firstInstance; 2823 }; 2824 })(window.jQuery || window.Zepto); 2825} 2826 2827// component 2828if (typeof(module) !== 'undefined') 2829{ 2830 module.exports = Swiper; 2831} 2832 2833// requirejs support 2834if (typeof define === 'function' && define.amd) { 2835 define([], function () { 2836 'use strict'; 2837 return Swiper; 2838 }); 2839}
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.