@@ -46,14 +46,16 @@ var vueTouchEvents = {
46
46
47
47
48
48
function touchStartEvent ( event ) {
49
- var $this = this . $$touchObj
50
- if ( event . type . indexOf ( "mouse" ) === - 1 ) {
51
- $this . supportTouch = true ;
49
+ var $this = this . $$touchObj ,
50
+ isTouchEvent = event . type . indexOf ( "touch" ) >= 0 ,
51
+ isMouseEvent = event . type . indexOf ( "mouse" ) >= 0
52
+
53
+ if ( isTouchEvent ) {
54
+ $this . lastTouchStartTime = event . timeStamp
52
55
}
53
56
54
- if ( $this . supportTouch && event . type . indexOf ( "mouse" ) !== - 1 ) {
55
- // don't click when we're touch instead of clicking
56
- return ;
57
+ if ( isMouseEvent && $this . lastTouchStartTime && event . timeStamp - $this . lastTouchStartTime < 350 ) {
58
+ return
57
59
}
58
60
59
61
if ( $this . touchStarted ) {
@@ -81,11 +83,6 @@ var vueTouchEvents = {
81
83
function touchMoveEvent ( event ) {
82
84
var $this = this . $$touchObj
83
85
84
- if ( $this . supportTouch && event . type . indexOf ( "mouse" ) !== - 1 ) {
85
- // don't move when we're touch instead of clicking
86
- return ;
87
- }
88
-
89
86
$this . currentX = touchX ( event )
90
87
$this . currentY = touchY ( event )
91
88
@@ -121,11 +118,16 @@ var vueTouchEvents = {
121
118
}
122
119
123
120
function touchEndEvent ( event ) {
124
- var $this = this . $$touchObj
121
+ var $this = this . $$touchObj ,
122
+ isTouchEvent = event . type . indexOf ( "touch" ) >= 0 ,
123
+ isMouseEvent = event . type . indexOf ( "mouse" ) >= 0
125
124
126
- if ( $this . supportTouch && event . type . indexOf ( "mouse" ) !== - 1 ) {
127
- // don't touchend when we're touch instead of clicking
128
- return ;
125
+ if ( isTouchEvent ) {
126
+ $this . lastTouchEndTime = event . timeStamp
127
+ }
128
+
129
+ if ( isMouseEvent && $this . lastTouchEndTime && event . timeStamp - $this . lastTouchEndTime < 350 ) {
130
+ return
129
131
}
130
132
131
133
$this . touchStarted = false
@@ -224,8 +226,6 @@ var vueTouchEvents = {
224
226
bind : function ( $el , binding ) {
225
227
226
228
$el . $$touchObj = $el . $$touchObj || {
227
- // will change to true when `touchstart` event first trigger
228
- supportTouch : false ,
229
229
// an object contains all callbacks registered,
230
230
// key is event name, value is an array
231
231
callbacks : { } ,
@@ -269,14 +269,11 @@ var vueTouchEvents = {
269
269
$el . addEventListener ( 'touchcancel' , touchCancelEvent )
270
270
$el . addEventListener ( 'touchend' , touchEndEvent )
271
271
272
- if ( ! options . disableClick ) {
273
- //$el.addEventListener('click', clickEvent)
274
- $el . addEventListener ( 'mousedown' , touchStartEvent )
275
- $el . addEventListener ( 'mousemove' , touchMoveEvent )
276
- $el . addEventListener ( 'mouseup' , touchEndEvent )
277
- $el . addEventListener ( 'mouseenter' , mouseEnterEvent )
278
- $el . addEventListener ( 'mouseleave' , mouseLeaveEvent )
279
- }
272
+ $el . addEventListener ( 'mousedown' , touchStartEvent )
273
+ $el . addEventListener ( 'mousemove' , touchMoveEvent )
274
+ $el . addEventListener ( 'mouseup' , touchEndEvent )
275
+ $el . addEventListener ( 'mouseenter' , mouseEnterEvent )
276
+ $el . addEventListener ( 'mouseleave' , mouseLeaveEvent )
280
277
281
278
// set bind mark to true
282
279
$el . $$touchObj . hasBindTouchEvents = true
@@ -288,14 +285,11 @@ var vueTouchEvents = {
288
285
$el . removeEventListener ( 'touchcancel' , touchCancelEvent )
289
286
$el . removeEventListener ( 'touchend' , touchEndEvent )
290
287
291
- if ( ! options . disableClick ) {
292
- //$el.removeEventListener('click', clickEvent)
293
- $el . removeEventListener ( 'mousedown' , touchStartEvent )
294
- $el . removeEventListener ( 'mousemove' , touchMoveEvent )
295
- $el . removeEventListener ( 'mouseup' , touchEndEvent )
296
- $el . removeEventListener ( 'mouseenter' , mouseEnterEvent )
297
- $el . removeEventListener ( 'mouseleave' , mouseLeaveEvent )
298
- }
288
+ $el . removeEventListener ( 'mousedown' , touchStartEvent )
289
+ $el . removeEventListener ( 'mousemove' , touchMoveEvent )
290
+ $el . removeEventListener ( 'mouseup' , touchEndEvent )
291
+ $el . removeEventListener ( 'mouseenter' , mouseEnterEvent )
292
+ $el . removeEventListener ( 'mouseleave' , mouseLeaveEvent )
299
293
300
294
// remove vars
301
295
delete $el . $$touchObj
0 commit comments