vue-app-touch
Version:
1 lines • 2.92 kB
JavaScript
!function(e){var t={};function s(n){if(t[n])return t[n].exports;var r=t[n]={i:n,l:!1,exports:{}};return e[n].call(r.exports,r,r.exports,s),r.l=!0,r.exports}s.m=e,s.c=t,s.d=function(e,t,n){s.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},s.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},s.t=function(e,t){if(1&t&&(e=s(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(s.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)s.d(n,r,function(t){return e[t]}.bind(null,r));return n},s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,"a",t),t},s.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},s.p="",s(s.s=0)}([function(e,t,s){"use strict";s.r(t);var n=function(){function e(e,t){this.tracking=!1,this.lastTapTime=0,e.addEventListener("touchstart",this,!1),e.addEventListener("touchmove",this,!1),e.addEventListener("touchend",this,!1),e.addEventListener("touchcancel",this,!1),this.maxDistance=t&&t.maxDistance||5,this.tapInterval=t&&t.tapInterval||800,this.openPress=t&&t.openPress||!1,this.pressTime=t&&t.pressTime||650}return e.prototype.handleEvent=function(e){var t=e.type,s=e.touches[0],n=e.target;switch(t){case"touchstart":if(e.targetTouches.length>1)return this.tracking=!1,this.openPress&&this.clearPress(),!0;this.tracking=!0,this.spos={x:s.pageX,y:s.pageY},this.epos={x:s.pageX,y:s.pageY},this.openPress&&this.press(n);break;case"touchmove":this.epos={x:s.pageX,y:s.pageY};var r=this.getDistance(this.spos,this.epos);this.openPress&&r>this.maxDistance&&this.clearPress();break;case"touchend":if(this.openPress&&this.clearPress(),!this.tracking)return!0;var i=this.getFingers(e);r=this.getDistance(this.spos,this.epos);0===i&&r<=this.maxDistance&&e.timeStamp-this.lastTapTime>this.tapInterval&&(e.stopPropagation(),this.lastTapTime=e.timeStamp,this.sendTap(n));break;case"touchcancel":this.openPress&&this.clearPress()}},e.prototype.getDistance=function(e,t){var s=t.x-e.x,n=t.y-e.y;return Math.sqrt(s*s+n*n)},e.prototype.getFingers=function(e){return e.touches&&e.touches.length||0},e.prototype.press=function(e){var t=this;this.pressTimeId=setTimeout((function(){t.tracking=!1,t.sendPress(e)}),this.pressTime)},e.prototype.clearPress=function(){this.pressTimeId&&(clearTimeout(this.pressTimeId),this.pressTimeId=0)},e.prototype.sendTap=function(e){var t=e.nodeType===Node.TEXT_NODE?e.parentNode:e,s=document.createEvent("HTMLEvents");s.initEvent("tap",!0,!0),t.dispatchEvent(s)},e.prototype.sendPress=function(e){var t=e.nodeType===Node.TEXT_NODE?e.parentNode:e,s=document.createEvent("HTMLEvents");s.initEvent("press",!0,!0),t.dispatchEvent(s)},e}();t.default=n,new n(document.body,{openPress:!0})}]);