From efbc0b1a744b7432078512e6c20537b9519e866e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9C=97=E6=9C=97?= <102187902@qq.com> Date: Thu, 30 Aug 2018 15:28:31 +0800 Subject: [PATCH] issue #55 --- dist/tap.js | 17 ++++++++++++++++- dist/tap.min.js | 2 +- src/tap.js | 4 +++- src/utils.js | 13 +++++++++++++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/dist/tap.js b/dist/tap.js index 3360a6b..6e09bb7 100644 --- a/dist/tap.js +++ b/dist/tap.js @@ -36,6 +36,19 @@ return e; }; + utils.isPc = function () { + var uaInfo = navigator.userAgent; + var agents = ["Android", "iPhone", "Windows Phone", "iPad", "iPod"]; + var flag = true; + for (var i = 0; i < agents.length; i++) { + if (uaInfo.indexOf(agents[i]) > 0) { + flag = false; + break; + } + } + return flag; + }; + var eventMatrix = [{ // Touchable devices test: ('propertyIsEnumerable' in window || 'hasOwnProperty' in document) && (window.propertyIsEnumerable('ontouchstart') || document.hasOwnProperty('ontouchstart') || window.hasOwnProperty('ontouchstart')), @@ -127,6 +140,9 @@ init = function() { var i = 0; + if(utils.isPc()) { + return utils.attachEvent(document.documentElement, 'click', handlers.click); + } for (; i < eventMatrix.length; i++) { if (eventMatrix[i].test) { deviceEvents = eventMatrix[i].events; @@ -139,7 +155,6 @@ } } - return utils.attachEvent(document.documentElement, 'click', handlers.click); }; utils.attachEvent(window, 'load', init); diff --git a/dist/tap.min.js b/dist/tap.min.js index ae469c7..cf89383 100644 --- a/dist/tap.min.js +++ b/dist/tap.min.js @@ -1 +1 @@ -!function(a){var b={},c={};c.attachEvent=function(b,c,d){if("addEventListener"in a)return b.addEventListener(c,d,!1)},c.fireFakeEvent=function(a,b){if(document.createEvent)return a.target.dispatchEvent(c.createEvent(b))},c.createEvent=function(b){if(document.createEvent){var c=a.document.createEvent("HTMLEvents");return c.initEvent(b,!0,!0),c.eventName=b,c}},c.getRealEvent=function(a){return a.originalEvent&&a.originalEvent.touches&&a.originalEvent.touches.length?a.originalEvent.touches[0]:a.touches&&a.touches.length?a.touches[0]:a};var d=[{test:("propertyIsEnumerable"in a||"hasOwnProperty"in document)&&(a.propertyIsEnumerable("ontouchstart")||document.hasOwnProperty("ontouchstart")||a.hasOwnProperty("ontouchstart")),events:{start:"touchstart",move:"touchmove",end:"touchend"}},{test:a.navigator.msPointerEnabled,events:{start:"MSPointerDown",move:"MSPointerMove",end:"MSPointerUp"}},{test:a.navigator.pointerEnabled,events:{start:"pointerdown",move:"pointermove",end:"pointerup"}}];b.options={eventName:"tap",fingerMaxOffset:11};var e,f,g,h,i={};e=function(a){return c.attachEvent(document.documentElement,h[a],g[a])},g={start:function(a){a=c.getRealEvent(a),i.start=[a.pageX,a.pageY],i.offset=[0,0]},move:function(a){if(!i.start&&!i.move)return!1;a=c.getRealEvent(a),i.move=[a.pageX,a.pageY],i.offset=[Math.abs(i.move[0]-i.start[0]),Math.abs(i.move[1]-i.start[1])]},end:function(d){if(d=c.getRealEvent(d),i.offset&&d.preventDefault&&i.offset[0]0){c=!1;break}return c};var d=[{test:("propertyIsEnumerable"in a||"hasOwnProperty"in document)&&(a.propertyIsEnumerable("ontouchstart")||document.hasOwnProperty("ontouchstart")||a.hasOwnProperty("ontouchstart")),events:{start:"touchstart",move:"touchmove",end:"touchend"}},{test:a.navigator.msPointerEnabled,events:{start:"MSPointerDown",move:"MSPointerMove",end:"MSPointerUp"}},{test:a.navigator.pointerEnabled,events:{start:"pointerdown",move:"pointermove",end:"pointerup"}}];b.options={eventName:"tap",fingerMaxOffset:11};var e,f,g,h,i={};e=function(a){return c.attachEvent(document.documentElement,h[a],g[a])},g={start:function(a){a=c.getRealEvent(a),i.start=[a.pageX,a.pageY],i.offset=[0,0]},move:function(a){if(!i.start&&!i.move)return!1;a=c.getRealEvent(a),i.move=[a.pageX,a.pageY],i.offset=[Math.abs(i.move[0]-i.start[0]),Math.abs(i.move[1]-i.start[1])]},end:function(d){if(d=c.getRealEvent(d),i.offset&&d.preventDefault&&i.offset[0] 0) { + flag = false; + break; + } + } + return flag; + };