forked from Rich-Harris/Points
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPoints.min.js
1 lines (1 loc) · 4.65 KB
/
Points.min.js
1
(function(){"use strict";function t(){this.originalEvent.preventDefault()}var e,n,i,r,o,a,c,d,s,v,u,l;if(void 0===window.onpointerdown){l="screenX screenY clientX clientY ctrlKey shiftKey altKey metaKey relatedTarget detail button buttons pointerId pointerType width height pressure tiltX tiltY isPrimary".split(" ");try{r=new UIEvent("test"),a=function(t,e){return new UIEvent(t,{view:window,bubbles:e})}}catch(p){document.createEvent&&(a=function(t,e){var n=document.createEvent("UIEvents");return n.initUIEvent(t,e,!0,window),n})}if(!a)throw Error("Cannot create events. You may be using an unsupported browser.");if(c=function(e,n,i,r){var o,c;for(o=a(e,!r),c=l.length;c--;)Object.defineProperty(o,l[c],{value:i[l[c]],writable:!1});return Object.defineProperty(o,"originalEvent",{value:n,writable:!1}),Object.defineProperty(o,"preventDefault",{value:t,writable:!1}),o},navigator.pointerEnabled=!0,void 0!==window.onmspointerdown)return["MSPointerDown","MSPointerUp","MSPointerCancel","MSPointerMove","MSPointerOver","MSPointerOut"].forEach(function(t){var e;e=t.toLowerCase().substring(2),"pointerover"===e||"pointerout"===e?window.addEventListener(t,function(t){var n=c(e,t,t,!1);t.target.dispatchEvent(n),t.target.contains(t.relatedTarget)||(n=c("pointerover"===e?"pointerenter":"pointerleave",t,t,!0),t.target.dispatchEvent(n))},!0):window.addEventListener(t,function(t){var n=c(e,t,t,!1);t.target.dispatchEvent(n)},!0)}),navigator.maxTouchPoints=navigator.msMaxTouchPoints,void 0;u={0:1,1:4,2:2},d=function(e,n,i){var r,o,a,d;return void 0!==n.buttons?(o=n.buttons,r=n.buttons?n.button:-1):0===event.button&&0===event.which?(r=-1,o=0):(r=n.button,o=u[r]),a=n.pressure||n.mozPressure||(o?.5:0),d={screenX:n.screenX,screenY:n.screenY,clientX:n.clientX,clientY:n.clientY,ctrlKey:n.ctrlKey,shiftKey:n.shiftKey,altKey:n.altKey,metaKey:n.metaKey,relatedTarget:n.relatedTarget,detail:n.detail,button:r,buttons:o,pointerId:1,pointerType:"mouse",width:0,height:0,pressure:a,tiltX:0,tiltY:0,isPrimary:!0,preventDefault:t},c(e,n,d,i)},s=void 0!==window.ontouchstart?function(t){for(var e,n=i.length,r=10;n--;)if(e=i[n],r>Math.abs(t.clientX-e.clientX)&&r>Math.abs(t.clientY-e.clientY))return!0}:function(){return!1},o=function(t){"over"===t||"out"===t?window.addEventListener("mouse"+t,function(e){var n;s(e)||(n=d("pointer"+t,e),e.target.dispatchEvent(n),e.target.contains(e.relatedTarget)||(n=d("over"===t?"pointerenter":"pointerleave",e,!0),e.target.dispatchEvent(n)))}):window.addEventListener("mouse"+t,function(e){var n;s(e)||(n=d("pointer"+t,e),e.target.dispatchEvent(n))})},["down","up","over","out","move"].forEach(function(t){o(t)}),void 0!==window.ontouchstart&&(e={},n=0,i=[],v=function(n,i,r,o,a){var d;return d={screenX:i.screenX,screenY:i.screenY,clientX:r.clientX,clientY:r.clientY,ctrlKey:i.ctrlKey,shiftKey:i.shiftKey,altKey:i.altKey,metaKey:i.metaKey,relatedTarget:a||i.relatedTarget,detail:i.detail,button:0,buttons:1,pointerId:r.identifier+2,pointerType:"touch",width:20,height:20,pressure:.5,tiltX:0,tiltY:0,isPrimary:e[r.identifier].isPrimary,preventDefault:t},c(n,i,d,o)},window.addEventListener("touchstart",function(t){var o,a;for(o=t.changedTouches,a=function(r){var o,a,c,d;d={target:r.target,isPrimary:n?!1:!0},e[r.identifier]=d,n+=1,o=v("pointerdown",t,r),a=v("pointerover",t,r),c=v("pointerenter",t,r,!0),r.target.dispatchEvent(a),r.target.dispatchEvent(c),r.target.dispatchEvent(o),i.push(r),setTimeout(function(){var t=i.indexOf(r);-1!==t&&i.splice(t,1)},1500)},r=0;o.length>r;r+=1)a(o[r])}),window.addEventListener("touchmove",function(t){var n,i;for(n=t.changedTouches,i=function(n){var i,r,o,a,c,d,s,u;return d=e[n.identifier],u=document.elementFromPoint(n.clientX,n.clientY),d.target===u?(i=v("pointermove",t,n),u.dispatchEvent(i),void 0):(s=d.target,d.target=u,s.contains(u)||(c=v("pointerleave",t,n,!0,u),s.dispatchEvent(c)),o=v("pointerout",t,n,!1),s.dispatchEvent(o),i=v("pointermove",t,n,!1),u.dispatchEvent(i),r=v("pointerover",t,n,!1),u.dispatchEvent(r),u.contains(s)||(a=v("pointerenter",t,n,!0,s),u.dispatchEvent(a)),void 0)},r=0;n.length>r;r+=1)i(n[r])}),window.addEventListener("touchend",function(t){var i,o;for(i=t.changedTouches,o=function(i){var r,o,a,c;c=document.elementFromPoint(i.clientX,i.clientY),r=v("pointerup",t,i,!1),o=v("pointerout",t,i,!1),a=v("pointerleave",t,i,!0),delete e[i.identifier],n-=1,c.dispatchEvent(r),c.dispatchEvent(o),c.dispatchEvent(a)},r=0;i.length>r;r+=1)o(i[r])}),window.addEventListener("touchcancel",function(t){var i,o;for(i=t.changedTouches,o=function(i){var r,o,a;r=v("pointercancel",t,i),o=v("pointerout",t,i),a=v("pointerleave",t,i),i.target.dispatchEvent(r),i.target.dispatchEvent(o),i.target.dispatchEvent(a),delete e[i.identifier],n-=1},r=0;i.length>r;r+=1)o(i[r])}))}})();