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