forked from voronianski/swipe-js-iso
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswipe.min.js
1 lines (1 loc) · 5.11 KB
/
swipe.min.js
1
!function(a,b){"undefined"!=typeof module&&module.exports?module.exports=b():a.Swipe=b()}(this,function(){"use strict";return function(a,b){function c(){p=t.children,s=p.length,y=p.length<2?!1:b.continuous,o.transitions&&y&&p.length<3&&(t.appendChild(p[0].cloneNode(!0)),t.appendChild(t.children[1].cloneNode(!0)),p=t.children),q=new Array(p.length),r=a.getBoundingClientRect().width||a.offsetWidth,t.style.width=p.length*r+"px";for(var c=p.length;c--;){var d=p[c];d.style.width=r+"px",d.setAttribute("data-index",c),o.transitions&&(d.style.left=c*-r+"px",h(c,w>c?-r:c>w?r:0,0))}y&&o.transitions&&(h(f(w-1),-r,0),h(f(w+1),r,0)),o.transitions||(t.style.left=w*-r+"px"),a.style.visibility="visible"}function d(){y?g(w-1):w&&g(w-1)}function e(){y?g(w+1):w<p.length-1&&g(w+1)}function f(a){return(p.length+a%p.length)%p.length}function g(a,c){if(w!=a){if(o.transitions){var d=Math.abs(w-a)/(w-a);if(y){var e=d;d=-q[f(a)]/r,d!==e&&(a=-d*p.length+a)}for(var g=Math.abs(w-a)-1;g--;)h(f((a>w?a:w)-g-1),r*d,0);a=f(a),h(w,r*d,c||x),h(a,0,c||x),y&&h(f(a-d),-(r*d),0)}else a=f(a),j(w*-r,a*-r,c||x);w=a,n(b.callback&&b.callback(w,p[w]))}}function h(a,b,c){i(a,b,c),q[a]=b}function i(a,b,c){var d=p[a],e=d&&d.style;e&&(e.webkitTransitionDuration=e.MozTransitionDuration=e.msTransitionDuration=e.OTransitionDuration=e.transitionDuration=c+"ms",e.webkitTransform="translate("+b+"px,0)translateZ(0)",e.msTransform=e.MozTransform=e.OTransform="translateX("+b+"px)")}function j(a,c,d){if(!d)return void(t.style.left=c+"px");var e=+new Date,f=setInterval(function(){var g=+new Date-e;return g>d?(t.style.left=c+"px",z&&k(),b.transitionEnd&&b.transitionEnd.call(event,w,p[w]),void clearInterval(f)):void(t.style.left=(c-a)*(Math.floor(g/d*100)/100)+a+"px")},4)}function k(){u=setTimeout(e,z)}function l(){z=0,clearTimeout(u)}var m=function(){},n=function(a){setTimeout(a||m,0)},o={addEventListener:!!window.addEventListener,touch:"ontouchstart"in window||window.DocumentTouch&&document instanceof window.DocumentTouch,transitions:function(a){var b=["transitionProperty","WebkitTransition","MozTransition","OTransition","msTransition"];for(var c in b)if(void 0!==a.style[b[c]])return!0;return!1}(document.createElement("swipe"))};if(a){var p,q,r,s,t=a.children[0];b=b||{};var u,v,w=parseInt(b.startSlide,10)||0,x=b.speed||300,y=b.continuous=void 0!==b.continuous?b.continuous:!0,z=b.auto||0,A={},B={},C={handleEvent:function(a){switch(a.type){case"touchstart":this.start(a);break;case"touchmove":this.move(a);break;case"touchend":n(this.end(a));break;case"webkitTransitionEnd":case"msTransitionEnd":case"oTransitionEnd":case"otransitionend":case"transitionend":n(this.transitionEnd(a));break;case"resize":n(c)}b.stopPropagation&&a.stopPropagation()},start:function(a){var b=a.touches[0];A={x:b.pageX,y:b.pageY,time:+new Date},v=void 0,B={},t.addEventListener("touchmove",this,!1),t.addEventListener("touchend",this,!1)},move:function(a){if(!(a.touches.length>1||a.scale&&1!==a.scale)){b.disableScroll&&a.preventDefault();var c=a.touches[0];B={x:c.pageX-A.x,y:c.pageY-A.y},"undefined"==typeof v&&(v=!!(v||Math.abs(B.x)<Math.abs(B.y))),v||(a.preventDefault(),l(),y?(i(f(w-1),B.x+q[f(w-1)],0),i(w,B.x+q[w],0),i(f(w+1),B.x+q[f(w+1)],0)):(B.x=B.x/(!w&&B.x>0||w==p.length-1&&B.x<0?Math.abs(B.x)/r+1:1),i(w-1,B.x+q[w-1],0),i(w,B.x+q[w],0),i(w+1,B.x+q[w+1],0)),b.swiping&&b.swiping(-B.x/r))}},end:function(a){var c=+new Date-A.time,d=Number(c)<250&&Math.abs(B.x)>20||Math.abs(B.x)>r/2,e=!w&&B.x>0||w==p.length-1&&B.x<0;y&&(e=!1);var g=B.x<0;v||(d&&!e?(g?(y?(h(f(w-1),-r,0),h(f(w+2),r,0)):h(w-1,-r,0),h(w,q[w]-r,x),h(f(w+1),q[f(w+1)]-r,x),w=f(w+1)):(y?(h(f(w+1),r,0),h(f(w-2),-r,0)):h(w+1,r,0),h(w,q[w]+r,x),h(f(w-1),q[f(w-1)]+r,x),w=f(w-1)),b.callback&&b.callback(w,p[w])):y?(h(f(w-1),-r,x),h(w,0,x),h(f(w+1),r,x)):(h(w-1,-r,x),h(w,0,x),h(w+1,r,x))),t.removeEventListener("touchmove",C,!1),t.removeEventListener("touchend",C,!1),t.removeEventListener("touchforcechange",function(){},!1)},transitionEnd:function(a){parseInt(a.target.getAttribute("data-index"),10)==w&&(z&&k(),b.transitionEnd&&b.transitionEnd.call(a,w,p[w]))}};return c(),z&&k(),o.addEventListener?(o.touch&&(t.addEventListener("touchstart",C,!1),t.addEventListener("touchforcechange",function(){},!1)),o.transitions&&(t.addEventListener("webkitTransitionEnd",C,!1),t.addEventListener("msTransitionEnd",C,!1),t.addEventListener("oTransitionEnd",C,!1),t.addEventListener("otransitionend",C,!1),t.addEventListener("transitionend",C,!1)),window.addEventListener("resize",C,!1)):window.onresize=function(){c()},{setup:function(){c()},slide:function(a,b){l(),g(a,b)},prev:function(){l(),d()},next:function(){l(),e()},stop:function(){l()},getPos:function(){return w},getNumSlides:function(){return s},kill:function(){l(),t.style.width="",t.style.left="";for(var a=p.length;a--;){var b=p[a];b.style.width="",b.style.left="",o.transitions&&i(a,0,0)}o.addEventListener?(t.removeEventListener("touchstart",C,!1),t.removeEventListener("webkitTransitionEnd",C,!1),t.removeEventListener("msTransitionEnd",C,!1),t.removeEventListener("oTransitionEnd",C,!1),t.removeEventListener("otransitionend",C,!1),t.removeEventListener("transitionend",C,!1),window.removeEventListener("resize",C,!1)):window.onresize=null}}}}});