You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
10 KiB

!function(n){"function"==typeof define&&define.amd&&define.amd.jQuery?define(["jquery.touchSwipe.js"],n):n(jQuery)}(function(n){"use strict";function e(e){return!e||void 0!==e.allowPageScroll||void 0===e.swipe&&void 0===e.swipeStatus||(e.allowPageScroll=c),void 0!==e.click&&void 0===e.tap&&(e.tap=e.click),e||(e={}),e=n.extend({},n.fn.swipe.defaults,e),this.each(function(){var r=n(this),i=r.data(P);i||(i=new t(this,e),r.data(P,i))})}function t(e,t){function D(e){if(!(sn()||n(e.target).closest(t.excludedElements,Fn).length>0)){var r,i=e.originalEvent?e.originalEvent:e,o=O?i.touches[0]:i;return Vn=S,(O?zn=i.touches.length:e.preventDefault(),jn=0,Hn=null,qn=null,_n=0,Qn=0,Cn=0,Xn=1,Yn=0,Gn=gn(),Wn=Tn(),an(),!O||zn===t.fingers||t.fingers===T||q()?(hn(0,o),Zn=Pn(),2==zn&&(hn(1,i.touches[1]),Qn=Cn=En(Gn[0].start,Gn[1].start)),(t.swipeStatus||t.pinchStatus)&&(r=U(i,Vn))):r=!1,!1===r)?(Vn=y,U(i,Vn),r):(t.hold&&(ee=setTimeout(n.proxy(function(){Fn.trigger("hold",[i.target]),t.hold&&(r=t.hold.call(Fn,i,i.target))},this),t.longTapThreshold)),pn(!0),null)}}function L(n){var e=n.originalEvent?n.originalEvent:n;if(Vn!==m&&Vn!==y&&!cn()){var r,i=O?e.touches[0]:e,o=fn(i);if(Bn=Pn(),O&&(zn=e.touches.length),t.hold&&clearTimeout(ee),Vn=E,2==zn&&(0==Qn?(hn(1,e.touches[1]),Qn=Cn=En(Gn[0].start,Gn[1].start)):(fn(e.touches[1]),Cn=En(Gn[0].end,Gn[1].end),qn=yn(Gn[0].end,Gn[1].end)),Xn=mn(Qn,Cn),Yn=Math.abs(Qn-Cn)),zn===t.fingers||t.fingers===T||!O||q()){if(Hn=Mn(o.start,o.end),X(n,Hn),jn=On(o.start,o.end),_n=Sn(),wn(Hn,jn),(t.swipeStatus||t.pinchStatus)&&(r=U(e,Vn)),!t.triggerOnTouchEnd||t.triggerOnTouchLeave){var u=!0;if(t.triggerOnTouchLeave){var l=Dn(this);u=Ln(o.end,l)}!t.triggerOnTouchEnd&&u?Vn=N(E):t.triggerOnTouchLeave&&!u&&(Vn=N(m)),Vn!=y&&Vn!=m||U(e,Vn)}}else Vn=y,U(e,Vn);!1===r&&(Vn=y,U(e,Vn))}}function R(n){var e=n.originalEvent;return O&&e.touches.length>0?(ln(),!0):(cn()&&(zn=Kn),Bn=Pn(),_n=Sn(),_()||!H()?(Vn=y,U(e,Vn)):t.triggerOnTouchEnd||0==t.triggerOnTouchEnd&&Vn===E?(n.preventDefault(),Vn=m,U(e,Vn)):!t.triggerOnTouchEnd&&B()?(Vn=m,j(e,Vn,f)):Vn===E&&(Vn=y,U(e,Vn)),pn(!1),null)}function k(){zn=0,Bn=0,Zn=0,Qn=0,Cn=0,Xn=1,an(),pn(!1)}function A(n){var e=n.originalEvent;t.triggerOnTouchLeave&&(Vn=N(m),U(e,Vn))}function I(){Fn.unbind(kn,D),Fn.unbind(Un,k),Fn.unbind(An,L),Fn.unbind(In,R),Nn&&Fn.unbind(Nn,A),pn(!1)}function N(n){var e=n,r=C(),i=H(),o=_();return!r||o?e=y:!i||n!=E||t.triggerOnTouchEnd&&!t.triggerOnTouchLeave?!i&&n==m&&t.triggerOnTouchLeave&&(e=y):e=m,e}function U(n,e){var t=void 0;return z()||V()||W()||q()?((z()||V())&&(t=j(n,e,p)),(W()||q())&&!1!==t&&(t=j(n,e,h))):on()&&!1!==t?t=j(n,e,d):un()&&!1!==t?t=j(n,e,g):rn()&&!1!==t&&(t=j(n,e,f)),e===y&&k(n),e===m&&(O?0==n.touches.length&&k(n):k(n)),t}function j(e,c,s){var w=void 0;if(s==p){if(Fn.trigger("swipeStatus",[c,Hn||null,jn||0,_n||0,zn,Gn]),t.swipeStatus&&!1===(w=t.swipeStatus.call(Fn,e,c,Hn||null,jn||0,_n||0,zn,Gn)))return!1;if(c==m&&F()){if(Fn.trigger("swipe",[Hn,jn,_n,zn,Gn]),t.swipe&&!1===(w=t.swipe.call(Fn,e,Hn,jn,_n,zn,Gn)))return!1;switch(Hn){case r:Fn.trigger("swipeLeft",[Hn,jn,_n,zn,Gn]),t.swipeLeft&&(w=t.swipeLeft.call(Fn,e,Hn,jn,_n,zn,Gn));break;case i:Fn.trigger("swipeRight",[Hn,jn,_n,zn,Gn]),t.swipeRight&&(w=t.swipeRight.call(Fn,e,Hn,jn,_n,zn,Gn));break;case o:Fn.trigger("swipeUp",[Hn,jn,_n,zn,Gn]),t.swipeUp&&(w=t.swipeUp.call(Fn,e,Hn,jn,_n,zn,Gn));break;case u:Fn.trigger("swipeDown",[Hn,jn,_n,zn,Gn]),t.swipeDown&&(w=t.swipeDown.call(Fn,e,Hn,jn,_n,zn,Gn))}}}if(s==h){if(Fn.trigger("pinchStatus",[c,qn||null,Yn||0,_n||0,zn,Xn,Gn]),t.pinchStatus&&!1===(w=t.pinchStatus.call(Fn,e,c,qn||null,Yn||0,_n||0,zn,Xn,Gn)))return!1;if(c==m&&Y())switch(qn){case l:Fn.trigger("pinchIn",[qn||null,Yn||0,_n||0,zn,Xn,Gn]),t.pinchIn&&(w=t.pinchIn.call(Fn,e,qn||null,Yn||0,_n||0,zn,Xn,Gn));break;case a:Fn.trigger("pinchOut",[qn||null,Yn||0,_n||0,zn,Xn,Gn]),t.pinchOut&&(w=t.pinchOut.call(Fn,e,qn||null,Yn||0,_n||0,zn,Xn,Gn))}}return s==f?c!==y&&c!==m||(clearTimeout(ne),clearTimeout(ee),J()&&!nn()?($n=Pn(),ne=setTimeout(n.proxy(function(){$n=null,Fn.trigger("tap",[e.target]),t.tap&&(w=t.tap.call(Fn,e,e.target))},this),t.doubleTapThreshold)):($n=null,Fn.trigger("tap",[e.target]),t.tap&&(w=t.tap.call(Fn,e,e.target)))):s==d?c!==y&&c!==m||(clearTimeout(ne),$n=null,Fn.trigger("doubletap",[e.target]),t.doubleTap&&(w=t.doubleTap.call(Fn,e,e.target))):s==g&&(c!==y&&c!==m||(clearTimeout(ne),$n=null,Fn.trigger("longtap",[e.target]),t.longTap&&(w=t.longTap.call(Fn,e,e.target)))),w}function H(){var n=!0;return null!==t.threshold&&(n=jn>=t.threshold),n}function _(){var n=!1;return null!==t.cancelThreshold&&null!==Hn&&(n=vn(Hn)-jn>=t.cancelThreshold),n}function Q(){return null===t.pinchThreshold||Yn>=t.pinchThreshold}function C(){return!t.maxTimeThreshold||!(_n>=t.maxTimeThreshold)}function X(n,e){if(!1!==t.preventDefaultEvents)if(t.allowPageScroll===c)n.preventDefault();else{var l=t.allowPageScroll===s;switch(e){case r:(t.swipeLeft&&l||!l&&t.allowPageScroll!=w)&&n.preventDefault();break;case i:(t.swipeRight&&l||!l&&t.allowPageScroll!=w)&&n.preventDefault();break;case o:(t.swipeUp&&l||!l&&t.allowPageScroll!=v)&&n.preventDefault();break;case u:(t.swipeDown&&l||!l&&t.allowPageScroll!=v)&&n.preventDefault()}}}function Y(){var n=G(),e=Z(),t=Q();return n&&e&&t}function q(){return!!(t.pinchStatus||t.pinchIn||t.pinchOut)}function W(){return!(!Y()||!q())}function F(){var n=C(),e=H(),t=G(),r=Z();return!_()&&r&&t&&e&&n}function V(){return!!(t.swipe||t.swipeStatus||t.swipeLeft||t.swipeRight||t.swipeUp||t.swipeDown)}function z(){return!(!F()||!V())}function G(){return zn===t.fingers||t.fingers===T||!O}function Z(){return 0!==Gn[0].end.x}function B(){return!!t.tap}function J(){return!!t.doubleTap}function K(){return!!t.longTap}function $(){if(null==$n)return!1;var n=Pn();return J()&&n-$n<=t.doubleTapThreshold}function nn(){return $()}function en(){return(1===zn||!O)&&(isNaN(jn)||jn<t.threshold)}function tn(){return _n>t.longTapThreshold&&jn<b}function rn(){return!(!en()||!B())}function on(){return!(!$()||!J())}function un(){return!(!tn()||!K())}function ln(){Jn=Pn(),Kn=event.touches.length+1}function an(){Jn=0,Kn=0}function cn(){var n=!1;if(Jn){Pn()-Jn<=t.fingerReleaseThreshold&&(n=!0)}return n}function sn(){return!(!0!==Fn.data(P+"_intouch"))}function pn(n){!0===n?(Fn.bind(An,L),Fn.bind(In,R),Nn&&Fn.bind(Nn,A)):(Fn.unbind(An,L,!1),Fn.unbind(In,R,!1),Nn&&Fn.unbind(Nn,A,!1)),Fn.data(P+"_intouch",!0===n)}function hn(n,e){var t=void 0!==e.identifier?e.identifier:0;return Gn[n].identifier=t,Gn[n].start.x=Gn[n].end.x=e.pageX||e.clientX,Gn[n].start.y=Gn[n].end.y=e.pageY||e.clientY,Gn[n]}function fn(n){var e=void 0!==n.identifier?n.identifier:0,t=dn(e);return t.end.x=n.pageX||n.clientX,t.end.y=n.pageY||n.clientY,t}function dn(n){for(var e=0;e<Gn.length;e++)if(Gn[e].identifier==n)return Gn[e]}function gn(){for(var n=[],e=0;e<=5;e++)n.push({start:{x:0,y:0},end:{x:0,y:0},identifier:0});return n}function wn(n,e){e=Math.max(e,vn(n)),Wn[n].distance=e}function vn(n){if(Wn[n])return Wn[n].distance}function Tn(){var n={};return n[r]=bn(r),n[i]=bn(i),n[o]=bn(o),n[u]=bn(u),n}function bn(n){return{direction:n,distance:0}}function Sn(){return Bn-Zn}function En(n,e){var t=Math.abs(n.x-e.x),r=Math.abs(n.y-e.y);return Math.round(Math.sqrt(t*t+r*r))}function mn(n,e){return(e/n*1).toFixed(2)}function yn(){return Xn<1?a:l}function On(n,e){return Math.round(Math.sqrt(Math.pow(e.x-n.x,2)+Math.pow(e.y-n.y,2)))}function xn(n,e){var t=n.x-e.x,r=e.y-n.y,i=Math.atan2(r,t),o=Math.round(180*i/Math.PI);return o<0&&(o=360-Math.abs(o)),o}function Mn(n,e){var t=xn(n,e);return t<=45&&t>=0?r:t<=360&&t>=315?r:t>=135&&t<=225?i:t>45&&t<135?u:o}function Pn(){return(new Date).getTime()}function Dn(e){e=n(e);var t=e.offset();return{left:t.left,right:t.left+e.outerWidth(),top:t.top,bottom:t.top+e.outerHeight()}}function Ln(n,e){return n.x>e.left&&n.x<e.right&&n.y>e.top&&n.y<e.bottom}var Rn=O||M||!t.fallbackToMouseEvents,kn=Rn?M?x?"MSPointerDown":"pointerdown":"touchstart":"mousedown",An=Rn?M?x?"MSPointerMove":"pointermove":"touchmove":"mousemove",In=Rn?M?x?"MSPointerUp":"pointerup":"touchend":"mouseup",Nn=Rn?null:"mouseleave",Un=M?x?"MSPointerCancel":"pointercancel":"touchcancel",jn=0,Hn=null,_n=0,Qn=0,Cn=0,Xn=1,Yn=0,qn=0,Wn=null,Fn=n(e),Vn="start",zn=0,Gn=null,Zn=0,Bn=0,Jn=0,Kn=0,$n=0,ne=null,ee=null;try{Fn.bind(kn,D),Fn.bind(Un,k)}catch(e){n.error("events not supported "+kn+","+Un+" on jQuery.swipe")}this.enable=function(){return Fn.bind(kn,D),Fn.bind(Un,k),Fn},this.disable=function(){return I(),Fn},this.destroy=function(){I(),Fn.data(P,null),Fn=null},this.option=function(e,r){if(void 0!==t[e]){if(void 0===r)return t[e];t[e]=r}else n.error("Option "+e+" does not exist on jQuery.swipe.options");return null}}var r="left",i="right",o="up",u="down",l="in",a="out",c="none",s="auto",p="swipe",h="pinch",f="tap",d="doubletap",g="longtap",w="horizontal",v="vertical",T="all",b=10,S="start",E="move",m="end",y="cancel",O="ontouchstart"in window,x=window.navigator.msPointerEnabled&&!window.navigator.pointerEnabled,M=window.navigator.pointerEnabled||window.navigator.msPointerEnabled,P="TouchSwipe",D={fingers:1,threshold:75,cancelThreshold:null,pinchThreshold:20,maxTimeThreshold:null,fingerReleaseThreshold:250,longTapThreshold:500,doubleTapThreshold:200,swipe:null,swipeLeft:null,swipeRight:null,swipeUp:null,swipeDown:null,swipeStatus:null,pinchIn:null,pinchOut:null,pinchStatus:null,click:null,tap:null,doubleTap:null,longTap:null,hold:null,triggerOnTouchEnd:!0,triggerOnTouchLeave:!1,allowPageScroll:"auto",fallbackToMouseEvents:!0,excludedElements:"label, button, input, select, textarea, a, .noSwipe",preventDefaultEvents:!0};n.fn.swipe=function(t){var r=n(this),i=r.data(P);if(i&&"string"==typeof t){if(i[t])return i[t].apply(this,Array.prototype.slice.call(arguments,1));n.error("Method "+t+" does not exist on jQuery.swipe")}else if(!(i||"object"!=typeof t&&t))return e.apply(this,arguments);return r},n.fn.swipe.defaults=D,n.fn.swipe.phases={PHASE_START:S,PHASE_MOVE:E,PHASE_END:m,PHASE_CANCEL:y},n.fn.swipe.directions={LEFT:r,RIGHT:i,UP:o,DOWN:u,IN:l,OUT:a},n.fn.swipe.pageScroll={NONE:c,HORIZONTAL:w,VERTICAL:v,AUTO:s},n.fn.swipe.fingers={ONE:1,TWO:2,THREE:3,ALL:T}});