forked from mattbryson/TouchSwipe-Jquery-Plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
touchswipe.jquery.min.js
1 lines (1 loc) · 2.88 KB
/
touchswipe.jquery.min.js
1
(function(a){a.fn.swipe=function(p){if(!this){return false}var e={fingers:1,threshold:75,swipe:null,swipeLeft:null,swipeRight:null,swipeUp:null,swipeDown:null,swipeStatus:null,click:null,triggerOnTouchEnd:true,allowPageScroll:"auto"};var c="left";var i="right";var o="up";var l="down";var k="none";var d="horizontal";var g="vertical";var n="auto";var b="start";var h="move";var j="end";var f="cancel";var m="start";if(p.allowPageScroll==undefined&&(p.swipe!=undefined||p.swipeStatus!=undefined)){p.allowPageScroll=k}if(p){a.extend(e,p)}return this.each(function(){var B=a(this);var y=null;var C=0;var s={x:0,y:0};var v={x:0,y:0};var E={x:0,y:0};function u(G){m=b;C=G.touches.length;distance=0;direction=null;if(C==e.fingers){s.x=v.x=G.touches[0].pageX;s.y=v.y=G.touches[0].pageY;if(e.swipeStatus){t(G,m)}}else{x(G)}}function D(G){if(m==j||m==f){return}v.x=G.touches[0].pageX;v.y=G.touches[0].pageY;direction=q();C=G.touches.length;m=h;A(G,direction);if(C==e.fingers){distance=w();if(e.swipeStatus){t(G,m,direction,distance)}if(!e.triggerOnTouchEnd){if(distance>=e.threshold){m=j;t(G,m);x(G)}}}else{m=f;t(G,m);x(G)}}function F(G){G.preventDefault();distance=w();direction=q();if(e.triggerOnTouchEnd){m=j;if(C==e.fingers&&v.x!=0){if(distance>=e.threshold){t(G,m);x(G)}else{m=f;t(G,m);x(G)}}else{m=f;t(G,m);x(G)}}else{if(m==h){m=f;t(G,m);x(G)}}}function x(G){C=0;s.x=0;s.y=0;v.x=0;v.y=0;E.x=0;E.y=0}function t(H,G){if(e.swipeStatus){e.swipeStatus.call(B,H,G,direction||null,distance||0)}if(G==f){if(e.click&&C==1&&(isNaN(distance)||distance==0)){e.click.call(B,H,H.target)}}if(G==j){if(e.swipe){e.swipe.call(B,H,direction,distance)}switch(direction){case c:if(e.swipeLeft){e.swipeLeft.call(B,H,direction,distance)}break;case i:if(e.swipeRight){e.swipeRight.call(B,H,direction,distance)}break;case o:if(e.swipeUp){e.swipeUp.call(B,H,direction,distance)}break;case l:if(e.swipeDown){e.swipeDown.call(B,H,direction,distance)}break}}}function A(G,H){if(e.allowPageScroll==k){G.preventDefault()}else{var I=e.allowPageScroll==n;switch(H){case c:if((e.swipeLeft&&I)||(!I&&e.allowPageScroll!=d)){G.preventDefault()}break;case i:if((e.swipeRight&&I)||(!I&&e.allowPageScroll!=d)){G.preventDefault()}break;case o:if((e.swipeUp&&I)||(!I&&e.allowPageScroll!=g)){G.preventDefault()}break;case l:if((e.swipeDown&&I)||(!I&&e.allowPageScroll!=g)){G.preventDefault()}break}}}function w(){return Math.round(Math.sqrt(Math.pow(v.x-s.x,2)+Math.pow(v.y-s.y,2)))}function r(){var J=s.x-v.x;var I=v.y-s.y;var G=Math.atan2(I,J);var H=Math.round(G*180/Math.PI);if(H<0){H=360-Math.abs(H)}return H}function q(){var G=r();if((G<=45)&&(G>=0)){return c}else{if((G<=360)&&(G>=315)){return c}else{if((G>=135)&&(G<=225)){return i}else{if((G>45)&&(G<135)){return l}else{return o}}}}}try{this.addEventListener("touchstart",u,false);this.addEventListener("touchmove",D,false);this.addEventListener("touchend",F,false);this.addEventListener("touchcancel",x,false)}catch(z){}})}})(jQuery);