forked from GianlucaGuarini/Tocca.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTocca.min.js
More file actions
2 lines (2 loc) · 1.84 KB
/
Copy pathTocca.min.js
File metadata and controls
2 lines (2 loc) · 1.84 KB
1
2
/*! tocca v1.0.0 || Gianluca Guarini */
!function(a,b){"use strict";if("function"!=typeof a.createEvent)return!1;var c,d,e,f,g,h,i,j,k="undefined"!=typeof jQuery,l=function(a){var b=a.toLowerCase(),c="MS"+a;return navigator.msPointerEnabled?c:b},m=!1,n={touchstart:l("PointerDown")+" touchstart",touchend:l("PointerUp")+" touchend",touchmove:l("PointerMove")+" touchmove"},o=function(a,b,c){for(var d=b.split(" "),e=d.length;e--;)a.addEventListener(d[e],c,!1)},p=function(a){return a.targetTouches?a.targetTouches[0]:a},q=function(){return(new Date).getTime()},r=function(b,e,f,g){var h=a.createEvent("Event");if(h.originalEvent=f,g=g||{},g.x=c,g.y=d,g.distance=g.distance,k&&(h=jQuery.Event(e,{originalEvent:f}),jQuery(b).trigger(h,g)),h.initEvent){for(var i in g)h[i]=g[i];h.initEvent(e,!0,!0),b.dispatchEvent(h)}for(;b;)b["on"+e]&&b["on"+e](h),b=b.parentNode},s=function(a){if("mousedown"!==a.type&&(m=!0),"mousedown"!==a.type||!m){var b=p(a);e=c=b.pageX,f=d=b.pageY,j=setTimeout(function(){r(a.target,"longtap",a),h=a.target},y),g=q(),B++}},t=function(a){if("mouseup"===a.type&&m)return void(m=!1);var b=[],k=q(),l=f-d,n=e-c;if(clearTimeout(i),clearTimeout(j),-v>=n&&b.push("swiperight"),n>=v&&b.push("swipeleft"),-v>=l&&b.push("swipedown"),l>=v&&b.push("swipeup"),b.length){for(var o=0;o<b.length;o++){var p=b[o];r(a.target,p,a,{distance:{x:Math.abs(n),y:Math.abs(l)}})}B=0}else e>=c-z&&c+z>=e&&f>=d-z&&d+z>=f&&g+w-k>=0&&(r(a.target,B>=2&&h===a.target?"dbltap":"tap",a),h=a.target),i=setTimeout(function(){B=0},x)},u=function(a){if("mousemove"!==a.type||!m){var b=p(a);c=b.pageX,d=b.pageY}},v=b.SWIPE_THRESHOLD||100,w=b.TAP_THRESHOLD||150,x=b.DBL_TAP_THRESHOLD||200,y=b.LONG_TAP_THRESHOLD||1e3,z=b.TAP_PRECISION/2||30,A=b.JUST_ON_TOUCH_DEVICES,B=0;o(a,n.touchstart+(A?"":" mousedown"),s),o(a,n.touchend+(A?"":" mouseup"),t),o(a,n.touchmove+(A?"":" mousemove"),u)}(document,window);