-
Notifications
You must be signed in to change notification settings - Fork 0
/
gwdgesture_min.js
12 lines (12 loc) · 5.87 KB
/
gwdgesture_min.js
1
2
3
4
5
6
7
8
9
10
11
12
(function(){'use strict';var h;var k=function(a,b,c){if(c){var d=document.createEvent("CustomEvent");d.initCustomEvent(a,!0,!0,c)}else d=document.createEvent("Event"),d.initEvent(a,!0,!0);b.dispatchEvent(d);return d},l=function(a){a=a.timeStamp;return 5E12>a?a:a/1E3};var n=["auto","none","pan-x","pan-y"],p=2,q=null,r=!1,t=null,u=null,v=[],y=function(a,b){var c=b.changedTouches[0];null==q&&(q=c.identifier,t=c.clientX,u=c.clientY,r=!1);w(b);x(a,"pointerover",b);x(a,"pointerdown",b)},z=function(a,b,c){if(!r){var d;if(d=1!=a&&null!=t){var e=c.touches[0];d=Math.abs(e.clientX-t);e=Math.abs(e.clientY-u);d=2==a?d>e:e>d}d?(x(b,"pointercancel",c),r=!0,q=null):(x(b,"pointermove",c),c.preventDefault());u=t=null}},B=function(a,b){r||(w(b),A(b),x(a,"pointerup",b),x(a,"pointerout",
b))},A=function(a){null!=q&&C(a,function(a){q==a.identifier&&(u=t=q=null)})},w=function(a){a=a.changedTouches[0];q==a.identifier&&(a={l:a.clientX,m:a.clientY,A:a.screenX,B:a.screenY},v.push(a),setTimeout(function(a){a=v.indexOf(a);-1<a&&v.splice(a,1)}.bind(null,a),2500))},D=function(a,b,c,d){b=Math.abs(b-d);return 25>=Math.abs(a-c)&&25>=b},E=function(a,b,c,d){var e=document.createEvent("Event");e.initEvent(a,!0,!0);e.clientX=c.clientX;e.clientY=c.clientY;e.pointerId=b;e.isPrimary=d;return e},F={},
G=function(a){a=""+a.identifier;F[a]||(F[a]=p++);return F[a]},H=function(a,b,c){c.preventDefault();var d;a:{for(d=0;d<v.length;d++)if(D(c.clientX,c.clientY,v[d].l,v[d].m)||D(c.screenX,c.screenY,v[d].A,v[d].B)){d=!0;break a}d=!1}d||a.dispatchEvent(E(b,1,c,!0))},I=function(a,b,c){a.dispatchEvent(E(b,c.pointerId,c,c.isPrimary))},x=function(a,b,c){C(c,function(c){a.dispatchEvent(E(b,G(c),c,q==c.identifier))})},C=function(a,b){a=a.changedTouches;for(var c=0,d=a.length;c<d;++c)b(a[c])};var J=function(a){var b=document.createEvent("Event");b.initEvent("tap",!0,!0);b.clientX=a.clientX;b.clientY=a.clientY;return b},L=function(a,b,c){return K(a,c.clientX,c.clientY,c.clientX-b.downX,c.clientY-b.downY,c.clientX-b.lastX,c.clientY-b.lastY)},K=function(a,b,c,d,e,m,g){var f=document.createEvent("Event");f.initEvent(a,!0,!0);f.clientX=b;f.clientY=c;f.dx=d;f.dy=e;f.ddx=m;f.ddy=g;return f};var M=function(a,b){return Math.abs(a)>=Math.abs(b)?0<a?"swiperight":"swipeleft":0<b?"swipedown":"swipeup"};var N=function(){};goog.inherits(N,HTMLElement);h=N.prototype;
h.createdCallback=function(){this.a={};this.b=!1;this.i=k.bind(null,"hover",this);this.f=this.u.bind(this);this.g=this.v.bind(this);this.j=this.C.bind(this);this.h=this.w.bind(this);this.c=this.o.bind(this);this.D=this.hasAttribute("swipe-velocity")?parseFloat(this.getAttribute("swipe-velocity")):.5;this.s=this.hasAttribute("swipe-distance")?parseFloat(this.getAttribute("swipe-distance")):.1;var a=1;switch(this.getAttribute("touch-action")){case "auto":a=0;break;case "pan-x":a=2;break;case "pan-y":a=
3}a=a||0;var b=n[a];this.setAttribute("touch-action",b);this.style.touchAction=b;this.style.msTouchAction=b;void 0===window.PointerEvent&&(navigator.msPointerEnabled?(this.addEventListener("MSPointerOver",I.bind(null,this,"pointerover"),!1),this.addEventListener("MSPointerDown",I.bind(null,this,"pointerdown"),!1),this.addEventListener("MSPointerMove",I.bind(null,this,"pointermove"),!1),this.addEventListener("MSPointerUp",I.bind(null,this,"pointerup"),!1),this.addEventListener("MSPointerOut",I.bind(null,
this,"pointerout"),!1),this.addEventListener("MSPointerCancel",I.bind(null,this,"pointercancel"),!1)):(this.addEventListener("mouseover",H.bind(null,this,"pointerover"),!1),this.addEventListener("mousedown",H.bind(null,this,"pointerdown"),!1),this.addEventListener("mousemove",H.bind(null,this,"pointermove"),!1),this.addEventListener("mouseup",H.bind(null,this,"pointerup"),!1),this.addEventListener("mouseout",H.bind(null,this,"pointerout"),!1),void 0!==window.ontouchstart&&(this.addEventListener("touchstart",
y.bind(null,this),!1),0!=a&&this.addEventListener("touchmove",z.bind(null,a,this),!1),this.addEventListener("touchend",B.bind(null,this),!1))))};h.attachedCallback=function(){this.addEventListener("pointerover",this.i,!1);this.addEventListener("pointerdown",this.f,!1);this.addEventListener("pointermove",this.g,!1);this.addEventListener("pointerup",this.j,!1);this.addEventListener("pointerout",this.h,!1);this.addEventListener("pointercancel",this.c,!1)};
h.detachedCallback=function(){this.removeEventListener("pointerover",this.i,!1);this.removeEventListener("pointerdown",this.f,!1);this.removeEventListener("pointermove",this.g,!1);this.removeEventListener("pointerup",this.j,!1);this.removeEventListener("pointerout",this.h,!1);this.removeEventListener("pointercancel",this.c,!1)};
h.u=function(a){if(a.isPrimary){var b=""+a.pointerId;this.a[b]||(this.a[b]={downX:a.clientX,downY:a.clientY,downTime:l(a),lastX:a.clientX,lastY:a.clientY,tracking:!1});this.b=!1}};h.v=function(a){a.preventDefault();var b=this.a[""+a.pointerId];if(b){if(10<Math.abs(b.downX-a.clientX)||10<Math.abs(b.downY-a.clientY))this.b=!0;b.tracking||(this.dispatchEvent(K("trackstart",b.downX,b.downY,0,0,0,0)),b.tracking=!0);this.dispatchEvent(L("track",b,a));b.lastX=a.clientX;b.lastY=a.clientY}};
h.C=function(a){O(this,a)&&(this.b||this.dispatchEvent(J(a)))};h.w=function(a){O(this,a);k("hoverend",this)};
var O=function(a,b){var c=a.a[""+b.pointerId];if(c){if(c.tracking){a.dispatchEvent(L("trackend",c,b));var d=b.clientX-c.downX,e=b.clientY-c.downY;a:{var m=l(b)-c.downTime;var g=a.s;var f=d/m;m=e/m;if(Math.abs(Math.sqrt(f*f+m*m))<a.D)g=!1;else switch(M(d,e)){case "swipeup":case "swipedown":g=.92<Math.abs(e/Math.sqrt(e*e+d*d))&&Math.abs(e)>=a.clientHeight*g;break a;case "swipeleft":case "swiperight":g=.92<Math.abs(d/Math.sqrt(d*d+e*e))&&Math.abs(d)>=a.clientWidth*g;break a;default:g=!1}}g&&k(M(d,e),
a)}P(a,b)}return c};N.prototype.o=function(a){P(this,a);this.b=!0};var P=function(a,b){b=""+b.pointerId;a.a[b]&&delete a.a[b]};N.prototype.attributeChangedCallback=function(){};document.registerElement("gwd-gesture",{prototype:N.prototype});}).call(this);