forked from nolimits4web/swiper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
idangerous.swiper-1.3.min.js
13 lines (13 loc) · 9.44 KB
/
idangerous.swiper-1.3.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
/*
* Swiper 1.3 - 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: April 15, 2012
*/
Swiper=function(d,b){function g(){a.init();a.swipeTo(a.activeSlide,0,!1)}function e(c){if(a.isTouched||b.onlyExternal)return!1;a.isTouched=!0;if(!a.isSupportTouch()||1==c.targetTouches.length)if(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=h?a.touches.startX:a.touches.startY,a.setTransition(0),a.positions.start=a.positions.current=h?a.getTranslate("x"):a.getTranslate("y"),h?a.setTransform(a.positions.start,0,0):a.setTransform(0,a.positions.start,0),a.times.start=(new Date).getTime(),i=void 0,b.onTouchStart)b.onTouchStart(a)}function o(c){if(a.isTouched&&!b.onlyExternal){if(a.isSupportTouch()&&("undefined"==typeof i&&h&&(i=!!(i||Math.abs(c.targetTouches[0].pageY-a.touches.startY)>Math.abs(c.targetTouches[0].pageX-a.touches.startX))),"undefined"==typeof i&&!h&&(i=!!(i||Math.abs(c.targetTouches[0].pageY-a.touches.startY)<Math.abs(c.targetTouches[0].pageX-a.touches.startX))),i))return;b.autoPlay&&a.stopAutoPlay();if(!a.isSupportTouch()||1==c.touches.length){c.preventDefault();if(b.onTouchMove)b.onTouchMove(a);a.touches.current=h?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))c=(2*f-a.positions.current)/f/2,a.positions.current=0.5>c?f/2:a.positions.current*c;if(Math.abs(a.positions.current)>k-f&&(!b.freeMode||b.freeModeFluid)){var c=(k-f+a.positions.current)/(k-f)/2,c=a.positions.current-f*c*(j-1),d=-(k-f/2);a.positions.current=c<d?d:c}b.followFinger&&(h?a.setTransform(a.positions.current,0,0):a.setTransform(0,a.positions.current,0),b.freeMode&&a.updateActiveSlide(a.positions.current))}}}function m(){if(!b.onlyExternal&&a.isTouched){a.isTouched=!1;a.positions.current||(a.positions.current=a.positions.start);h?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=k-f;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),h?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)):(p=0>c?"toNext":"toPrev","toNext"==p&&300>=a.times.end-a.times.start&&(30>d?a.swipeReset():a.swipeNext()),"toPrev"==p&&300>=a.times.end-a.times.start&&(30>d?a.swipeReset():a.swipePrev()),"toNext"==p&&300<a.times.end-a.times.start&&(d>=0.5*f?a.swipeNext():a.swipeReset()),"toPrev"==p&&300<a.times.end-a.times.start&&(d>=0.5*f?a.swipePrev():a.swipeReset()));if(b.onTouchEnd)b.onTouchEnd(a)}}function l(){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={};a.times={};a.isTouched=!1;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.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 n=document.querySelectorAll(d+" ."+b.wrapperClass).item(0),h,f,j,k,p,i;a.wrapper=n;h="horizontal"==b.mode;var u=a.isSupportTouch()||!b.simulateTouch?"touchstart":"mousedown",v=a.isSupportTouch()||!b.simulateTouch?"touchmove":"mousemove",w=a.isSupportTouch()||!b.simulateTouch?"touchend":"mouseup";a.init=function(){var c=document.querySelectorAll(d).item(0).offsetWidth,e=document.querySelectorAll(d).item(0).offsetHeight;f=h?c:e;j=document.querySelectorAll(d+" ."+b.slideClass).length;for(var g=0;g<j;g++){var i=document.querySelectorAll(d+" ."+b.slideClass).item(g);i.style.width=c+"px";i.style.height=e+"px";if(b.onSlideInitialize)b.onSlideInitialize(a,i)}c*=j;e*=j;k=h?c:e;h?n.style.width=c+"px":n.style.height=e+"px"};a.init();if(b.pagination&&b.createPagination){for(var r="",s=0;s<j;s++){var x="";0==s&&(x=" "+b.paginationActiveClass);r+='<span class="'+b.paginationClass+""+x+'"></span>'}document.querySelectorAll(b.pagination)[0].innerHTML=r}window.addEventListener("resize",g,!1);var t;a.startAutoPlay=function(){b.autoPlay&&(t=setInterval(function(){var b=a.activeSlide+1;b==j&&(b=0);a.swipeTo(b)},b.autoPlay))};a.stopAutoPlay=function(){t&&clearInterval(t)};b.autoPlay&&a.startAutoPlay();n.addEventListener(u,e,!1);var q=a.isSupportTouch()?n:document;q.addEventListener(v,o,!1);q.addEventListener(w,m,!1);a.destroy=function(a){(!1===a?a:1)&&window.removeEventListener("resize",g,!1);n.removeEventListener(u,e,!1);q.removeEventListener(v,o,!1);q.removeEventListener(w,m,!1)};a.swipeNext=function(){a.positions.current||(a.positions.current=-f);var c=Math.ceil(-a.positions.current/f)*f;if(c==k)return!1;h?a.setTransform(-c,0,0):a.setTransform(0,-c,0);a.setTransition(b.speed);a.touches.start=a.touches.current;a.positions.current-=f;a.updateActiveSlide(-c);l()};a.swipePrev=function(){var c=h?a.getTranslate("x"):a.getTranslate("y");if(0==c)return!1;var d=(Math.ceil(-a.positions.current/f)-1)*f;d==-c&&(d-=f,a.positions.current=-d);h?a.setTransform(-d,0,0):a.setTransform(0,-d,0);a.setTransition(b.speed);a.updateActiveSlide(-d);l()};a.swipeReset=function(){var c=0>a.positions.current?Math.round(a.positions.current/f)*f:0;c==-k&&(c+=f);"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)};a.swipeTo=function(c,d,e){if(0>c||c>j-1)return!1;e=!1===e?!1:e||!0;d=0===d?d:d||b.speed;c=-c*f;a.setTransform(c,0,0);a.setTransition(d);a.updateActiveSlide(c);e&&l();return!0};a.updateActiveSlide=function(c){a.previousSlide=a.activeSlide;a.activeSlide=Math.round(-c/f);a.activeSlide==j&&(a.activeSlide=j-1);0>a.activeSlide&&(a.activeSlide=0);b.pagination&&a.updatePagination()};a.updatePagination=function(){var c=document.querySelectorAll(b.pagination+" ."+b.paginationActiveClass).item(0);c&&(0<=c.className.indexOf("active")&&(c.className=c.className.replace(b.paginationActiveClass,"")),document.querySelectorAll(b.pagination+" ."+b.paginationClass).item(a.activeSlide).className=document.querySelectorAll(b.pagination+" ."+b.paginationClass).item(a.activeSlide).className+" "+b.paginationActiveClass)}}};Swiper.prototype={transitionEnd:function(d){var b=this,g=b.wrapper,e=["webkitTransitionEnd","transitionend","oTransitionEnd","MSTransitionEnd","msTransitionEnd"];if(d)for(var o=function(){d(b);for(var l=0;l<e.length;l++)g.removeEventListener(e[l],o,!1)},m=0;m<e.length;m++)g.addEventListener(e[m],o,!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 g=document.createElement("style");g.textContent="@media (-webkit-transform-3d), (transform-3d), (-moz-transform-3d), (-o-transform-3d), (-ms-transform-3d) {#test3d{height:5px}}";document.getElementsByTagName("head")[0].appendChild(g);document.body.appendChild(d);b=5===d.offsetHeight;g.parentNode.removeChild(g);d.parentNode.removeChild(d)}return b},getTranslate:function(d){var b=this.wrapper,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;if("x"==d)var g=parseInt(b.toString().split(",")[4],10);"y"==d&&(g=parseInt(b.toString().split(",")[5],10));return g},setTransform:function(d,b,g){var e=this.wrapper.style,d=d||0,b=b||0;e.webkitTransform=this.use3D?e.MsTransform=e.msTransform=e.MozTransform=e.OTransform=e.transform="translate3d("+d+"px, "+b+"px, "+(g||0)+"px)":e.MsTransform=e.msTransform=e.MozTransform=e.OTransform=e.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);