15
15
* [fastclick](https://github.com/ftlabs/fastclick) and Angular's
16
16
* [ngTouch](https://docs.angularjs.org/api/ngTouch) should not be included, to avoid conflicts.
17
17
*
18
+ * Some browsers already remove the delay with certain settings, such as the CSS property
19
+ * `touch-events: none` or with specific meta tag viewport values. However, each of these
20
+ * browsers still handle clicks differently, such as when to fire off or cancel the event
21
+ * (like scrolling when the target is a button, or holding a button down).
22
+ * For browsers that already remove the 300ms delay, consider Ionic's tap system as a way to
23
+ * normalize how clicks are handled across the various devices so there's an expected response
24
+ * no matter what the device, platform or version. Additionally, Ionic will prevent
25
+ * ghostclicks which even browsers that remove the delay still experience.
26
+ *
18
27
* In some cases, third-party libraries may also be working with touch events which can interfere
19
28
* with the tap system. For example, mapping libraries like Google or Leaflet Maps often implement
20
29
* a touch detection system which conflicts with Ionic's tap system.
@@ -67,6 +76,7 @@ var tapPointerMoved;
67
76
var tapPointerStart ;
68
77
var tapTouchFocusedInput ;
69
78
var tapLastTouchTarget ;
79
+ var tapTouchMoveListener = 'touchmove' ;
70
80
71
81
var TAP_RELEASE_TOLERANCE = 6 ; // how much the coordinates can be off between start/end, but still a click
72
82
@@ -82,6 +92,16 @@ var tapEventListeners = {
82
92
'touchcancel' : tapTouchCancel ,
83
93
'touchmove' : tapTouchMove ,
84
94
95
+ 'pointerdown' : tapTouchStart ,
96
+ 'pointerup' : tapTouchEnd ,
97
+ 'pointercancel' : tapTouchCancel ,
98
+ 'pointermove' : tapTouchMove ,
99
+
100
+ 'MSPointerDown' : tapTouchStart ,
101
+ 'MSPointerUp' : tapTouchEnd ,
102
+ 'MSPointerCancel' : tapTouchCancel ,
103
+ 'MSPointerMove' : tapTouchMove ,
104
+
85
105
'focusin' : tapFocusIn ,
86
106
'focusout' : tapFocusOut
87
107
} ;
@@ -94,9 +114,25 @@ ionic.tap = {
94
114
tapEventListener ( 'click' , true , true ) ;
95
115
tapEventListener ( 'mouseup' ) ;
96
116
tapEventListener ( 'mousedown' ) ;
97
- tapEventListener ( 'touchstart' ) ;
98
- tapEventListener ( 'touchend' ) ;
99
- tapEventListener ( 'touchcancel' ) ;
117
+
118
+ if ( window . navigator . pointerEnabled ) {
119
+ tapEventListener ( 'pointerdown' ) ;
120
+ tapEventListener ( 'pointerup' ) ;
121
+ tapEventListener ( 'pointcancel' ) ;
122
+ tapTouchMoveListener = 'pointermove' ;
123
+
124
+ } else if ( window . navigator . msPointerEnabled ) {
125
+ tapEventListener ( 'MSPointerDown' ) ;
126
+ tapEventListener ( 'MSPointerUp' ) ;
127
+ tapEventListener ( 'MSPointerCancel' ) ;
128
+ tapTouchMoveListener = 'MSPointerMove' ;
129
+
130
+ } else {
131
+ tapEventListener ( 'touchstart' ) ;
132
+ tapEventListener ( 'touchend' ) ;
133
+ tapEventListener ( 'touchcancel' ) ;
134
+ }
135
+
100
136
tapEventListener ( 'focusin' ) ;
101
137
tapEventListener ( 'focusout' ) ;
102
138
@@ -314,7 +350,7 @@ function tapTouchStart(e) {
314
350
tapEnableTouchEvents ( ) ;
315
351
tapPointerStart = getPointerCoordinates ( e ) ;
316
352
317
- tapEventListener ( 'touchmove' ) ;
353
+ tapEventListener ( tapTouchMoveListener ) ;
318
354
ionic . activator . start ( e ) ;
319
355
320
356
if ( ionic . Platform . isIOS ( ) && ionic . tap . isLabelWithTextInput ( e . target ) ) {
@@ -350,14 +386,14 @@ function tapTouchEnd(e) {
350
386
function tapTouchMove ( e ) {
351
387
if ( tapHasPointerMoved ( e ) ) {
352
388
tapPointerMoved = true ;
353
- tapEventListener ( 'touchmove' , false ) ;
389
+ tapEventListener ( tapTouchMoveListener , false ) ;
354
390
ionic . activator . end ( ) ;
355
391
return false ;
356
392
}
357
393
}
358
394
359
395
function tapTouchCancel ( e ) {
360
- tapEventListener ( 'touchmove' , false ) ;
396
+ tapEventListener ( tapTouchMoveListener , false ) ;
361
397
ionic . activator . end ( ) ;
362
398
tapPointerMoved = false ;
363
399
}
0 commit comments