forked from nolimits4web/swiper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
idangerous.swiper-1.5.min.js
35 lines (35 loc) · 11 KB
/
idangerous.swiper-1.5.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
* Swiper 1.5 - Mobile Touch Slider
* http://www.idangero.us/sliders/swiper/
*
* Copyright 2012, Vladimir Kharlampidi
* The iDangero.us
* http://www.idangero.us/
*
* Licensed under GPL & MIT
*
* Updated on: October 1, 2012
*/
Swiper=function(d,b){function e(a){return document.querySelectorAll(a)}function g(){var a=r-i*b.slidesPerSlide;b.loop&&(a-=m);return a}function s(){a.init();a.swipeTo(a.activeSlide,0,!1)}function n(c){if(a.isTouched||b.onlyExternal)return!1;if(!c.assignedToSwiper&&(c.assignedToSwiper=!0,a.isTouched=!0,!a.isSupportTouch()||1==c.targetTouches.length))if(b.loop&&a.fixLoop(),a.isSupportTouch()||c.preventDefault(),a.touches.startX=a.touches.currentX=a.isSupportTouch()?c.targetTouches[0].pageX:c.pageX,
a.touches.startY=a.touches.currentY=a.isSupportTouch()?c.targetTouches[0].pageY:c.pageY,a.touches.start=a.touches.current=f?a.touches.startX:a.touches.startY,a.setTransition(0),a.positions.start=a.positions.current=f?a.getTranslate("x"):a.getTranslate("y"),f?a.setTransform(a.positions.start,0,0):a.setTransform(0,a.positions.start,0),a.times.start=(new Date).getTime(),l=void 0,b.onTouchStart)b.onTouchStart(a)}function y(c){if(a.isTouched&&!b.onlyExternal){if(a.isSupportTouch()&&("undefined"==typeof l&&
f&&(l=!!(l||Math.abs(c.targetTouches[0].pageY-a.touches.startY)>Math.abs(c.targetTouches[0].pageX-a.touches.startX))),"undefined"==typeof l&&!f&&(l=!!(l||Math.abs(c.targetTouches[0].pageY-a.touches.startY)<Math.abs(c.targetTouches[0].pageX-a.touches.startX))),l))return;if(!c.assignedToSwiper&&(c.assignedToSwiper=!0,b.autoPlay&&a.stopAutoPlay(),!a.isSupportTouch()||1==c.touches.length)){c.preventDefault();if(b.onTouchMove)b.onTouchMove(a);a.touches.current=f?a.isSupportTouch()?c.targetTouches[0].pageX:
c.pageX:a.isSupportTouch()?c.targetTouches[0].pageY:c.pageY;a.positions.current=(a.touches.current-a.touches.start)*b.ratio+a.positions.start;if(0<a.positions.current&&(!b.freeMode||b.freeModeFluid))b.loop?(c=1,0<a.positions.current&&(a.positions.current=0)):c=(2*m-a.positions.current)/m/2,a.positions.current=0.5>c?m/2:a.positions.current*c;if(Math.abs(a.positions.current)>r-i*b.slidesPerSlide&&(!b.freeMode||b.freeModeFluid)){if(b.loop)var c=1,k=a.positions.current,d=-g()-m;else k=(a.touches.current-
a.touches.start)*b.ratio+(g()+a.positions.start),c=(m+k)/m,k=a.positions.current-k*(1-c)/2,d=-g()-m/2;a.positions.current=k<d||0>=c?d:k}b.followFinger&&(f?a.setTransform(a.positions.current,0,0):a.setTransform(0,a.positions.current,0),b.freeMode&&a.updateActiveSlide(a.positions.current))}}}function z(){if(!b.onlyExternal&&a.isTouched){a.isTouched=!1;!a.positions.current&&0!==a.positions.current&&(a.positions.current=a.positions.start);f?a.setTransform(a.positions.current,0,0):a.setTransform(0,a.positions.current,
0);a.times.end=(new Date).getTime();a.touches.diff=a.touches.current-a.touches.start;a.touches.abs=Math.abs(a.touches.diff);a.positions.diff=a.positions.current-a.positions.start;a.positions.abs=Math.abs(a.positions.diff);var c=a.positions.diff,d=a.positions.abs;5>d&&a.swipeReset();var e=r-i*b.slidesPerSlide;0<a.positions.current?a.swipeReset():Math.abs(a.positions.current)>e?a.swipeReset():b.freeMode?(300>a.times.end-a.times.start&&b.freeModeFluid&&(c=a.positions.current+2*a.touches.diff,c<-1*e&&
(c=-e),0<c&&(c=0),f?a.setTransform(c,0,0):a.setTransform(0,c,0),a.setTransition(2*(a.times.end-a.times.start)),a.updateActiveSlide(c)),(!b.freeModeFluid||300<=a.times.end-a.times.start)&&a.updateActiveSlide(a.positions.current)):(t=0>c?"toNext":"toPrev","toNext"==t&&300>=a.times.end-a.times.start&&(30>d?a.swipeReset():a.swipeNext(!0)),"toPrev"==t&&300>=a.times.end-a.times.start&&(30>d?a.swipeReset():a.swipePrev(!0)),"toNext"==t&&300<a.times.end-a.times.start&&(d>=0.5*i?a.swipeNext(!0):a.swipeReset()),
"toPrev"==t&&300<a.times.end-a.times.start&&(d>=0.5*i?a.swipePrev(!0):a.swipeReset()));if(b.onTouchEnd)b.onTouchEnd(a)}}function w(){if(b.onSlideChangeStart)b.onSlideChangeStart(a);b.onSlideChangeEnd&&a.transitionEnd(b.onSlideChangeEnd)}if(document.querySelectorAll&&0!=document.querySelectorAll(d).length){var a=this;a.touches={};a.positions={current:0};a.times={};a.isTouched=!1;a.realIndex=0;a.activeSlide=0;a.previousSlide=null;a.use3D=a.isSupport3D();b=b||{};a.params=b;b.mode=b.mode||"horizontal";
b.ratio=b.ratio||1;b.speed=b.speed||300;b.freeMode=b.freeMode||!1;b.freeModeFluid=b.freeModeFluid||!1;b.slidesPerSlide=b.slidesPerSlide||1;b.simulateTouch=!1===b.simulateTouch?!1:!0;b.followFinger=!1===b.followFinger?!1:!0;b.autoPlay=b.autoPlay||!1;b.onlyExternal=b.onlyExternal||!1;b.createPagination=!1===b.createPagination?!1:!0;b.pagination=b.pagination||!1;b.slideClass=b.slideClass||"swiper-slide";b.wrapperClass=b.wrapperClass||"swiper-wrapper";b.paginationClass=b.paginationClass||"swiper-pagination-switch";
b.paginationActiveClass=b.paginationActiveClass||"swiper-active-switch";var p=e(d+" ."+b.wrapperClass).item(0),f,i,h,r,t,l,m;a.wrapper=p;f="horizontal"==b.mode;var A=a.isSupportTouch()||!b.simulateTouch?"touchstart":"mousedown",B=a.isSupportTouch()||!b.simulateTouch?"touchmove":"mousemove",C=a.isSupportTouch()||!b.simulateTouch?"touchend":"mouseup";if(b.loop){h=e(d+" > ."+b.wrapperClass+" > ."+b.slideClass).length;for(var q="",u="",j=0;j<b.slidesPerSlide;j++)q+=e(d+" > ."+b.wrapperClass+" > ."+b.slideClass).item(j).outerHTML;
for(j=h-b.slidesPerSlide;j<h;j++)u+=e(d+" > ."+b.wrapperClass+" > ."+b.slideClass).item(j).outerHTML;p.innerHTML=u+p.innerHTML+q;setTimeout(function(){a.swipeTo(0,0)},0)}a.init=function(){var c=e(d).item(0).offsetWidth,k=e(d).item(0).offsetHeight;i=m=f?c:k;h=e(d+" > ."+b.wrapperClass+" > ."+b.slideClass).length;for(var g=f?1:b.slidesPerSlide,D=f?b.slidesPerSlide:1,j=0;j<h;j++){var l=e(d+" > ."+b.wrapperClass+" > ."+b.slideClass).item(j);l.style.width=c/D+"px";l.style.height=k/g+"px";if(b.onSlideInitialize)b.onSlideInitialize(a,
l)}c=h*c/D;k=h*k/g;r=f?c:k;f?p.style.width=c+"px":p.style.height=k+"px";b.slidesPerSlide&&1<b.slidesPerSlide&&(i/=b.slidesPerSlide)};a.init();if(b.pagination&&b.createPagination){q="";u=b.loop?h-2*b.slidesPerSlide:h;for(j=0;j<u;j++)q+='<span class="'+b.paginationClass+'"></span>';e(b.pagination)[0].innerHTML=q;setTimeout(function(){a.updatePagination()},0)}b.disableAutoResize||window.addEventListener("resize",s,!1);var x;a.startAutoPlay=function(){b.autoPlay&&(x=setInterval(function(){var b=a.realIndex+
1;b==h&&(b=0);a.swipeTo(b)},b.autoPlay))};a.stopAutoPlay=function(){x&&clearInterval(x)};b.autoPlay&&a.startAutoPlay();p.addEventListener(A,n,!1);var v=a.isSupportTouch()?p:document;v.addEventListener(B,y,!1);v.addEventListener(C,z,!1);a.destroy=function(a){(!1===a?a:1)&&window.removeEventListener("resize",s,!1);p.removeEventListener(A,n,!1);v.removeEventListener(B,y,!1);v.removeEventListener(C,z,!1)};a.swipeNext=function(c){!c&&b.loop&&a.fixLoop();c=f?a.getTranslate("x"):a.getTranslate("y");c=Math.floor(Math.abs(c)/
Math.floor(i))*i+i;if(c!=r&&(!(c>g())||b.loop))return b.loop&&c>=g()+m&&(c=g()+m),f?a.setTransform(-c,0,0):a.setTransform(0,-c,0),a.setTransition(b.speed),a.updateActiveSlide(-c),w(),!0};a.swipePrev=function(c){!c&&b.loop&&a.fixLoop();c=f?a.getTranslate("x"):a.getTranslate("y");c=(Math.ceil(-c/i)-1)*i;0>c&&(c=0);f?a.setTransform(-c,0,0):a.setTransform(0,-c,0);a.setTransition(b.speed);a.updateActiveSlide(-c);w();return!0};a.swipeReset=function(){var c=f?a.getTranslate("x"):a.getTranslate("y"),c=0>
c?Math.round(c/i)*i:0,d=-g();c<=d&&(c=d);"horizontal"==b.mode?a.setTransform(c,0,0):a.setTransform(0,c,0);a.setTransition(b.speed);a.updateActiveSlide(c);if(b.onSlideReset)b.onSlideReset(a);return!0};a.swipeTo=function(c,d,e){if(!(c>h-1)&&(!(0>c)||b.loop))return e=!1===e?!1:e||!0,d=0===d?d:d||b.speed,b.loop&&(c+=b.slidesPerSlide),c>h-b.slidesPerSlide&&(c=h-b.slidesPerSlide),c=-c*i,f?a.setTransform(c,0,0):a.setTransform(0,c,0),a.setTransition(d),a.updateActiveSlide(c),e&&w(),!0};a.updateActiveSlide=
function(c){a.previousSlide=a.realIndex;a.realIndex=Math.round(-c/i);b.loop?(a.activeSlide=a.realIndex-b.slidesPerSlide,a.activeSlide>=h-2*b.slidesPerSlide&&(a.activeSlide=h-2*b.slidesPerSlide-a.activeSlide),0>a.activeSlide&&(a.activeSlide=h-2*b.slidesPerSlide+a.activeSlide)):a.activeSlide=a.realIndex;a.realIndex==h&&(a.realIndex=h-1);0>a.realIndex&&(a.realIndex=0);b.pagination&&a.updatePagination()};a.updatePagination=function(){var c=e(b.pagination+" ."+b.paginationActiveClass);if(c){for(var d=
0;d<c.length;d++)0<=c.item(d).className.indexOf("active")&&(c.item(d).className=c.item(d).className.replace(b.paginationActiveClass,""));for(var c=e(b.pagination+" ."+b.paginationClass).length,d=b.loop?a.realIndex-b.slidesPerSlide:a.realIndex,g=d+(b.slidesPerSlide-1);d<=g;d++){var f=d;f>=c&&(f-=c);0>f&&(f=c+f);f<h&&(e(b.pagination+" ."+b.paginationClass).item(f).className=e(b.pagination+" ."+b.paginationClass).item(f).className+" "+b.paginationActiveClass)}}};a.fixLoop=function(){if(a.realIndex<b.slidesPerSlide){var c=
h-3*b.slidesPerSlide+a.realIndex;a.swipeTo(c,0)}a.realIndex>h-2*b.slidesPerSlide&&(c=-h+a.realIndex+b.slidesPerSlide,a.swipeTo(c,0))}}};
Swiper.prototype={transitionEnd:function(d){var b=this,e=b.wrapper,g=["webkitTransitionEnd","transitionend","oTransitionEnd","MSTransitionEnd","msTransitionEnd"];if(d)for(var s=function(){d(b);for(var n=0;n<g.length;n++)e.removeEventListener(g[n],s,!1)},n=0;n<g.length;n++)e.addEventListener(g[n],s,!1)},isSupportTouch:function(){return"ontouchstart"in window||window.DocumentTouch&&document instanceof DocumentTouch},isSupport3D:function(){var d=document.createElement("div");d.id="test3d";var b=!1;"webkitPerspective"in
d.style&&(b=!0);"MozPerspective"in d.style&&(b=!0);"OPerspective"in d.style&&(b=!0);"MsPerspective"in d.style&&(b=!0);"perspective"in d.style&&(b=!0);if(b&&"webkitPerspective"in d.style){var e=document.createElement("style");e.textContent="@media (-webkit-transform-3d), (transform-3d), (-moz-transform-3d), (-o-transform-3d), (-ms-transform-3d) {#test3d{height:5px}}";document.getElementsByTagName("head")[0].appendChild(e);document.body.appendChild(d);b=5===d.offsetHeight;e.parentNode.removeChild(e);
d.parentNode.removeChild(d)}return b},getTranslate:function(d){var b=this.wrapper,e,b=(window.WebKitCSSMatrix?new WebKitCSSMatrix(window.getComputedStyle(b,null).webkitTransform):window.getComputedStyle(b,null).MozTransform||window.getComputedStyle(b,null).OTransform||window.getComputedStyle(b,null).MsTransform||window.getComputedStyle(b,null).msTransform||window.getComputedStyle(b,null).transform).toString().split(",");"x"==d&&(e=16==b.length?parseInt(b[12],10):parseInt(b[4],10));"y"==d&&(e=16==
b.length?parseInt(b[13],10):parseInt(b[5],10));return e},setTransform:function(d,b,e){var g=this.wrapper.style,d=d||0,b=b||0;g.webkitTransform=this.use3D?g.MsTransform=g.msTransform=g.MozTransform=g.OTransform=g.transform="translate3d("+d+"px, "+b+"px, "+(e||0)+"px)":g.MsTransform=g.msTransform=g.MozTransform=g.OTransform=g.transform="translate("+d+"px, "+b+"px)"},setTransition:function(d){var b=this.wrapper.style;b.webkitTransitionDuration=b.MsTransitionDuration=b.msTransitionDuration=b.MozTransitionDuration=
b.OTransitionDuration=b.transitionDuration=d/1E3+"s"}};if(window.jQuery||window.Zepto)(function(d){d.fn.swiper=function(b){return new Swiper(d(this).selector,b)}})(window.jQuery||window.Zepto);