forked from nolimits4web/swiper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidangerous.swiper-1.5.5.min.js
13 lines (13 loc) · 12.4 KB
/
idangerous.swiper-1.5.5.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
/*
* Swiper 1.5.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 20, 2012
*/
Swiper=function(d,b){function g(a){return document.querySelectorAll(a)}function e(){var a=r-j*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)){b.loop&&a.fixLoop();a.isSupportTouch()||(c.preventDefault?c.preventDefault():c.returnValue=!1);var h=a.isSupportTouch()?c.targetTouches[0].pageX:c.pageX?c.pageX:c.clientX,c=a.isSupportTouch()?c.targetTouches[0].pageY:c.pageY?c.pageY:c.clientY;a.touches.startX=a.touches.currentX=h;a.touches.startY=a.touches.currentY=c;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();p=void 0;if(b.onTouchStart)b.onTouchStart(a)}}function y(c){if(a.isTouched&&!b.onlyExternal){if(a.isSupportTouch()&&("undefined"==typeof p&&f&&(p=!!(p||Math.abs(c.targetTouches[0].pageY-a.touches.startY)>Math.abs(c.targetTouches[0].pageX-a.touches.startX))),"undefined"==typeof p&&!f&&(p=!!(p||Math.abs(c.targetTouches[0].pageY-a.touches.startY)<Math.abs(c.targetTouches[0].pageX-a.touches.startX))),p))return;if(!c.assignedToSwiper&&(c.assignedToSwiper=!0,b.autoPlay&&a.stopAutoPlay(),!a.isSupportTouch()||1==c.touches.length)){c.preventDefault?c.preventDefault():c.returnValue=!1;if(b.onTouchMove)b.onTouchMove(a);var h=a.isSupportTouch()?c.targetTouches[0].pageX:c.pageX?c.pageX:c.clientX,c=a.isSupportTouch()?c.targetTouches[0].pageY:c.pageY?c.pageY:c.clientY;a.touches.current=f?h:c;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?(h=1,0<a.positions.current&&(a.positions.current=0)):h=(2*m-a.positions.current)/m/2,a.positions.current=0.5>h?m/2:a.positions.current*h;if(Math.abs(a.positions.current)>r-j*b.slidesPerSlide&&(!b.freeMode||b.freeModeFluid)){if(b.loop)var h=1,c=a.positions.current,d=-e()-m;else c=(a.touches.current-a.touches.start)*b.ratio+(e()+a.positions.start),h=(m+c)/m,c=a.positions.current-c*(1-h)/2,d=-e()-m/2;a.positions.current=c<d||0>=h?d:c}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,h=a.positions.abs;5>h&&a.swipeReset();var d=r-j*b.slidesPerSlide;0<a.positions.current?a.swipeReset():Math.abs(a.positions.current)>d?a.swipeReset():b.freeMode?(300>a.times.end-a.times.start&&b.freeModeFluid&&(c=a.positions.current+2*a.touches.diff,c<-1*d&&(c=-d),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>h?a.swipeReset():a.swipeNext(!0)),"toPrev"==t&&300>=a.times.end-a.times.start&&(30>h?a.swipeReset():a.swipePrev(!0)),"toNext"==t&&300<a.times.end-a.times.start&&(h>=0.5*j?a.swipeNext(!0):a.swipeReset()),"toPrev"==t&&300<a.times.end-a.times.start&&(h>=0.5*j?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)}window.addEventListener||(window.Element||(Element=function(){}),Element.prototype.addEventListener=HTMLDocument.prototype.addEventListener=addEventListener=function(a,b){this.attachEvent("on"+a,b)},Element.prototype.removeEventListener=HTMLDocument.prototype.removeEventListener=removeEventListener=function(a,b){this.detachEvent("on"+a,b)});if(document.body.__defineGetter__&&HTMLElement){var k=HTMLElement.prototype;k.__defineGetter__&&k.__defineGetter__("outerHTML",function(){return(new XMLSerializer).serializeToString(this)})}window.getComputedStyle||(window.getComputedStyle=function(a){this.el=a;this.getPropertyValue=function(b){var d=/(\-([a-z]){1})/g;"float"==b&&(b="styleFloat");d.test(b)&&(b=b.replace(d,function(a,b,c){return c.toUpperCase()}));return a.currentStyle[b]?a.currentStyle[b]:null};return this});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 q=g(d+" ."+b.wrapperClass).item(0),f,j,i,r,t,p,m;a.wrapper=q;f="horizontal"==b.mode;var B=a.isSupportTouch()||!b.simulateTouch?"touchstart":"mousedown",C=a.isSupportTouch()||!b.simulateTouch?"touchmove":"mousemove",D=a.isSupportTouch()||!b.simulateTouch?"touchend":"mouseup";if(b.loop){i=g(d+" > ."+b.wrapperClass+" > ."+b.slideClass).length;for(var u=k="",l=0;l<b.slidesPerSlide;l++)k+=g(d+" > ."+b.wrapperClass+" > ."+b.slideClass).item(l).outerHTML;for(l=i-b.slidesPerSlide;l<i;l++)u+=g(d+" > ."+b.wrapperClass+" > ."+b.slideClass).item(l).outerHTML;q.innerHTML=u+q.innerHTML+k;setTimeout(function(){a.swipeTo(0,0)},0)}a.init=function(){var c=g(d).item(0).offsetWidth,h=g(d).item(0).offsetHeight;j=m=f?c:h;i=g(d+" > ."+b.wrapperClass+" > ."+b.slideClass).length;for(var e=f?1:b.slidesPerSlide,A=f?b.slidesPerSlide:1,k=0;k<i;k++){var l=g(d+" > ."+b.wrapperClass+" > ."+b.slideClass).item(k);l.style.width=c/A+"px";l.style.height=h/e+"px";if(b.onSlideInitialize)b.onSlideInitialize(a,l)}c=i*c/A;h=i*h/e;r=f?c:h;f?q.style.width=c+"px":q.style.height=h+"px";b.slidesPerSlide&&1<b.slidesPerSlide&&(j/=b.slidesPerSlide)};a.init();if(b.pagination&&b.createPagination){k="";u=b.loop?i-2*b.slidesPerSlide:i;for(l=0;l<u;l++)k+='<span class="'+b.paginationClass+'"></span>';g(b.pagination)[0].innerHTML=k;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==i&&(b=0);a.swipeTo(b)},b.autoPlay))};a.stopAutoPlay=function(){x&&clearInterval(x)};b.autoPlay&&a.startAutoPlay();q.addEventListener(B,n,!1);var v=a.isSupportTouch()?q:document;v.addEventListener(C,y,!1);v.addEventListener(D,z,!1);a.destroy=function(a){(!1===a?a:1)&&window.removeEventListener("resize",s,!1);q.removeEventListener(B,n,!1);v.removeEventListener(C,y,!1);v.removeEventListener(D,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(j))*j+j;if(c!=r&&(!(c>e())||b.loop))return b.loop&&c>=e()+m&&(c=e()+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/j)-1)*j;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/j)*j:0,d=-e();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>i-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>i-b.slidesPerSlide&&(c=i-b.slidesPerSlide),c=-c*j,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/j);b.loop?(a.activeSlide=a.realIndex-b.slidesPerSlide,a.activeSlide>=i-2*b.slidesPerSlide&&(a.activeSlide=i-2*b.slidesPerSlide-a.activeSlide),0>a.activeSlide&&(a.activeSlide=i-2*b.slidesPerSlide+a.activeSlide)):a.activeSlide=a.realIndex;a.realIndex==i&&(a.realIndex=i-1);0>a.realIndex&&(a.realIndex=0);b.pagination&&a.updatePagination()};a.updatePagination=function(){var c=g(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=g(b.pagination+" ."+b.paginationClass).length,d=b.loop?a.realIndex-b.slidesPerSlide:a.realIndex,e=d+(b.slidesPerSlide-1);d<=e;d++){var f=d;f>=c&&(f-=c);0>f&&(f=c+f);f<i&&(g(b.pagination+" ."+b.paginationClass).item(f).className=g(b.pagination+" ."+b.paginationClass).item(f).className+" "+b.paginationActiveClass)}}};a.fixLoop=function(){if(a.realIndex<b.slidesPerSlide){var c=i-3*b.slidesPerSlide+a.realIndex;a.swipeTo(c,0)}a.realIndex>i-2*b.slidesPerSlide&&(c=-i+a.realIndex+b.slidesPerSlide,a.swipeTo(c,0))}}};Swiper.prototype={transitionEnd:function(d){var b=this,g=b.wrapper,e=["webkitTransitionEnd","transitionend","oTransitionEnd","MSTransitionEnd","msTransitionEnd"];if(d)for(var s=function(){d(b);for(var n=0;n<e.length;n++)g.removeEventListener(e[n],s,!1)},n=0;n<e.length;n++)g.addEventListener(e[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 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,g,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||window.getComputedStyle(b,null).getPropertyValue("transform").replace("translate(","matrix(1, 0, 0, 1,")).toString().split(",");"x"==d&&(g=16==b.length?parseInt(b[12],10):parseInt(b[4],10));"y"==d&&(g=16==b.length?parseInt(b[13],10):parseInt(b[5],10));return g},setTransform:function(d,b,g){var e=this.wrapper.style,d=d||0,b=b||0;this.use3D?e.webkitTransform=e.MsTransform=e.msTransform=e.MozTransform=e.OTransform=e.transform="translate3d("+d+"px, "+b+"px, "+(g||0)+"px)":(e.webkitTransform=e.MsTransform=e.msTransform=e.MozTransform=e.OTransform=e.transform="translate("+d+"px, "+b+"px)",this.ie8&&(e.filter="progid:DXImageTransform.Microsoft.Matrix(Dx="+d+",Dy="+b+")"))},setTransition:function(d){var b=this.wrapper.style;b.webkitTransitionDuration=b.MsTransitionDuration=b.msTransitionDuration=b.MozTransitionDuration=b.OTransitionDuration=b.transitionDuration=d/1E3+"s"},ie8:function(){var d=-1;"Microsoft Internet Explorer"==navigator.appName&&null!=/MSIE ([0-9]{1,}[.0-9]{0,})/.exec(navigator.userAgent)&&(d=parseFloat(RegExp.$1));return-1!=d&&9>d}()};if(window.jQuery||window.Zepto)(function(d){d.fn.swiper=function(b){return new Swiper(d(this).selector,b)}})(window.jQuery||window.Zepto);