-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswipe-events.min.js
34 lines (32 loc) · 3.58 KB
/
swipe-events.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var SwipeEvents=SwipeEvents||(()=>{let t=false;let f;let I;let P;let j;let C;let k;window.addEventListener("DOMContentLoaded",()=>{console.log(`
%cswipe-events.js%c v1.0 loaded
toggle logging to debug: %cSwipeEvents.toggleTelemetryLogging()%c
more info: https://github.com/eric-eldard/swipe-events.js
`.replace(/\n[ ]{12}/g,"\n"),"color: green","color: unset","color: blue","color: unset")});document.addEventListener("touchstart",e=>{f=e.changedTouches[0].clientX;I=e.changedTouches[0].clientY;C=Date.now();P=f;j=I;k=C;o(f,I,C,e)});document.addEventListener("touchmove",e=>{const t=e.changedTouches[0].clientX;const n=e.changedTouches[0].clientY;const a=Date.now();o(t,n,a,e);P=t;j=n;k=a});document.addEventListener("touchend",e=>{o(P,j,Date.now(),e)});document.addEventListener("touchcancel",e=>{o(P,j,Date.now(),e)});function o(e,t,n,a){const o=a.type==="touchstart";const l=o||a.type==="touchmove";const c=e-f;const i=t-I;const s=Math.abs(c);const d=Math.abs(i);const r=Math.hypot(s,d);const g=Math.abs(e-P);const u=Math.abs(t-j);const p=Math.hypot(g,u);const h=n-C;const v=s/h||0;const $=d/h||0;const X=r/h||0;const Y=n-k;const m=g/Y||0;const D=u/Y||0;const w=p/Y||0;let S=null;let E=null;let M=null;if(s>0||d>0){const b=f>e?"W":"E";const y=I>t?"N":"S";const L=Math.atan2(d,s)*(180/Math.PI);S=s>d?b:y;E=L>22.5&&L<67.5?y+b:S;const T=Math.atan2(i,c);M=(T<0?T+2*Math.PI:T)*(180/Math.PI)}document.dispatchEvent(new CustomEvent("swipe",{detail:{event:a,eventTime:n,duration:h,initial:o,ongoing:l,cardinal4:S,cardinal8:E,theta:M,originX:f,originY:I,currentX:e,currentY:t,totalDistanceX:s,totalDistanceY:d,totalDistance:r,latestDistanceX:g,latestDistanceY:u,latestDistance:p,overallSpeedX:v,overallSpeedY:$,overallSpeed:X,latestSpeedX:m,latestSpeedY:D,latestSpeed:w}}))}document.addEventListener("swipe",e=>{if(t){console.debug(`
-- swipe event --
%cevent: ${e.detail.event.type}
event time: ${e.detail.eventTime}
duration: ${e.detail.duration}
initial: ${e.detail.initial}
ongoing: ${e.detail.ongoing}
%ccardinal 4: ${e.detail.cardinal4}
cardinal 8: ${e.detail.cardinal8}
theta: ${e.detail.theta}
%corigin X: ${e.detail.originX}
origin Y: ${e.detail.originY}
%ccurrent X: ${e.detail.currentX}
current Y: ${e.detail.currentY}
%ctotal distance X: ${e.detail.totalDistanceX}
total distance Y: ${e.detail.totalDistanceY}
total distance: ${e.detail.totalDistance}
%clatest distance X: ${e.detail.latestDistanceX}
latest distance Y: ${e.detail.latestDistanceY}
latest distance: ${e.detail.latestDistance}
%coverall speed X: ${e.detail.overallSpeedX}
overall speed Y: ${e.detail.overallSpeedY}
overall speed: ${e.detail.overallSpeed}
%clatest speed X: ${e.detail.latestSpeedX}
latest speed Y: ${e.detail.latestSpeedY}
latest speed: ${e.detail.latestSpeed}
`.replace(/\n[ ]+/g,"\n"),"color: dimgray","color: brown","color: green","color: red","color: blue","color: orange","color: purple","color: darkcyan")}});return{telemetryLoggingEnabled:function(){return t},toggleTelemetryLogging:function(){t=!t;return t}}})();
//# sourceMappingURL=swipe-events.min.js.map