/* * touchSwipe - jQuery Plugin * https://github.com/mattbryson/TouchSwipe-Jquery-Plugin * http://labs.skinkers.com/touchSwipe/ * http://plugins.jquery.com/project/touchSwipe * * Copyright (c) 2010 Matt Bryson (www.skinkers.com) * Dual licensed under the MIT or GPL Version 2 licenses. * * $version: 1.3.3 */ !function(e){function n(n,v){var T,b,E,S;function m(e){e=e.originalEvent;var n,t=d?e.touches[0]:e;if(Q=p,d?V=e.touches.length:e.preventDefault(),j=0,I=null,_=0,d&&V!==v.fingers&&v.fingers!==c?M():(E=T=t.pageX,S=b=t.pageY,W=(new Date).getTime(),v.swipeStatus&&(n=O(e,Q))),!1===n)return O(e,Q=f),n;C.bind(x,D),C.bind(H,P)}function D(e){if(e=e.originalEvent,Q!==w&&Q!==f){var n,p=d?e.touches[0]:e;T=p.pageX,b=p.pageY,X=(new Date).getTime(),I=A(),d&&(V=e.touches.length),Q=h;p=e;var g=I;if(v.allowPageScroll===r)p.preventDefault();else{var E=v.allowPageScroll===s;switch(g){case t:(v.swipeLeft&&E||!E&&v.allowPageScroll!=o)&&p.preventDefault();break;case i:(v.swipeRight&&E||!E&&v.allowPageScroll!=o)&&p.preventDefault();break;case l:(v.swipeUp&&E||!E&&v.allowPageScroll!=u)&&p.preventDefault();break;case a:(v.swipeDown&&E||!E&&v.allowPageScroll!=u)&&p.preventDefault()}}V!==v.fingers&&v.fingers!==c&&d?O(e,Q=f):(j=y(),_=X-W,v.swipeStatus&&(n=O(e,Q)),v.triggerOnTouchEnd||(p=!(!v.maxTimeThreshold||!(_>=v.maxTimeThreshold)),!0===k()?n=O(e,Q=w):p&&O(e,Q=f))),!1===n&&O(e,Q=f)}}function P(e){if(C.cancelable&&(e=e.originalEvent).preventDefault(),X=(new Date).getTime(),j=y(),I=A(),_=X-W,v.triggerOnTouchEnd||!1===v.triggerOnTouchEnd&&Q===h)if(Q=w,V!==v.fingers&&v.fingers!==c&&d||0===T)O(e,Q=f);else{var n=!(!v.maxTimeThreshold||!(_>=v.maxTimeThreshold));!0!==k()&&null!==k()||n?(n||!1===k())&&O(e,Q=f):O(e,Q)}else Q===h&&O(e,Q=f);C.unbind(x,D,!1),C.unbind(H,P,!1)}function M(){W=X=b=T=S=E=V=0}function O(e,n){var r=void 0;if(v.swipeStatus&&(r=v.swipeStatus.call(C,e,n,I||null,j||0,_||0,V)),n!==f||!v.click||1!==V&&d||!isNaN(j)&&0!==j||(r=v.click.call(C,e,e.target)),n==w)switch(v.swipe&&(r=v.swipe.call(C,e,I,j,_,V)),I){case t:v.swipeLeft&&(r=v.swipeLeft.call(C,e,I,j,_,V));break;case i:v.swipeRight&&(r=v.swipeRight.call(C,e,I,j,_,V));break;case l:v.swipeUp&&(r=v.swipeUp.call(C,e,I,j,_,V));break;case a:v.swipeDown&&(r=v.swipeDown.call(C,e,I,j,_,V))}return(n===f||n===w)&&M(),r}function k(){return null!==v.threshold?j>=v.threshold:null}function y(){return Math.round(Math.sqrt(Math.pow(T-E,2)+Math.pow(b-S,2)))}function A(){var e;return e=Math.atan2(b-S,E-T),0>(e=Math.round(180*e/Math.PI))&&(e=360-Math.abs(e)),45>=e&&0<=e?t:360>=e&&315<=e?t:135<=e&&225>=e?i:45e?a:l}function L(){C.unbind(R,m),C.unbind(U,M),C.unbind(x,D),C.unbind(H,P)}var N=d||!v.fallbackToMouseEvents,R=N?"touchstart":"mousedown",x=N?"touchmove":"mousemove",H=N?"touchend":"mouseup",U="touchcancel",j=0,I=null,_=0,C=e(n),Q="start",V=0,W=b=T=S=E=0,X=0;try{C.bind(R,m),C.bind(U,M)}catch(n){e.error("events not supported "+R+","+U+" on jQuery.swipe")}this.enable=function(){return C.bind(R,m),C.bind(U,M),C},this.disable=function(){return L(),C},this.destroy=function(){return L(),C.data(g,null),C}}var t="left",i="right",l="up",a="down",r="none",s="auto",o="horizontal",u="vertical",c="all",p="start",h="move",w="end",f="cancel",d="ontouchstart"in window,g="TouchSwipe";e.fn.swipe=function(t){var i=e(this),l=i.data(g);if(l&&"string"==typeof t){if(l[t])return l[t].apply(this,Array.prototype.slice.call(arguments,1));e.error("Method "+t+" does not exist on jQuery.swipe")}else if(!(l||"object"!=typeof t&&t))return function(t){return!t||void 0!==t.allowPageScroll||void 0===t.swipe&&void 0===t.swipeStatus||(t.allowPageScroll=r),t||(t={}),t=e.extend({},e.fn.swipe.defaults,t),this.each(function(){var i=e(this),l=i.data(g);l||(l=new n(this,t),i.data(g,l))})}.apply(this,arguments);return i},e.fn.swipe.defaults={fingers:1,threshold:75,maxTimeThreshold:null,swipe:null,swipeLeft:null,swipeRight:null,swipeUp:null,swipeDown:null,swipeStatus:null,click:null,triggerOnTouchEnd:!0,allowPageScroll:"auto",fallbackToMouseEvents:!0},e.fn.swipe.phases={PHASE_START:p,PHASE_MOVE:h,PHASE_END:w,PHASE_CANCEL:f},e.fn.swipe.directions={LEFT:t,RIGHT:i,UP:l,DOWN:a},e.fn.swipe.pageScroll={NONE:r,HORIZONTAL:o,VERTICAL:u,AUTO:s},e.fn.swipe.fingers={ONE:1,TWO:2,THREE:3,ALL:c}}(jQuery);