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