@@ -33,6 +33,7 @@ var dataPropertyName = "virtualMouseBindings",
33
33
didScroll = false ,
34
34
clickBlockList = [ ] ,
35
35
blockMouseTriggers = false ,
36
+ blockTouchTriggers = false ,
36
37
eventCaptureSupported = $ . support . eventCapture ,
37
38
$document = $ ( document ) ,
38
39
nextTouchID = 1 ,
@@ -118,34 +119,12 @@ function getClosestElementWithVirtualBinding(element, eventType)
118
119
119
120
function enableTouchBindings ( )
120
121
{
121
- if ( ! activeDocHandlers [ "touchbindings" ] ) {
122
- $document . bind ( "touchend" , handleTouchEnd )
123
-
124
- // On touch platforms, touching the screen and then dragging your finger
125
- // causes the window content to scroll after some distance threshold is
126
- // exceeded. On these platforms, a scroll prevents a click event from being
127
- // dispatched, and on some platforms, even the touchend is suppressed. To
128
- // mimic the suppression of the click event, we need to watch for a scroll
129
- // event. Unfortunately, some platforms like iOS don't dispatch scroll
130
- // events until *AFTER* the user lifts their finger (touchend). This means
131
- // we need to watch both scroll and touchmove events to figure out whether
132
- // or not a scroll happenens before the touchend event is fired.
133
-
134
- . bind ( "touchmove" , handleTouchMove )
135
- . bind ( "scroll" , handleScroll ) ;
136
-
137
- activeDocHandlers [ "touchbindings" ] = 1 ;
138
- }
122
+ blockTouchTriggers = false ;
139
123
}
140
124
141
125
function disableTouchBindings ( )
142
126
{
143
- if ( activeDocHandlers [ "touchbindings" ] ) {
144
- $document . unbind ( "touchmove" , handleTouchMove )
145
- . unbind ( "touchend" , handleTouchEnd )
146
- . unbind ( "scroll" , handleScroll ) ;
147
- activeDocHandlers [ "touchbindings" ] = 0 ;
148
- }
127
+ blockTouchTriggers = true ;
149
128
}
150
129
151
130
function enableMouseBindings ( )
@@ -232,6 +211,10 @@ function handleTouchStart(event)
232
211
233
212
function handleScroll ( event )
234
213
{
214
+ if ( blockTouchTriggers ) {
215
+ return ;
216
+ }
217
+
235
218
if ( ! didScroll ) {
236
219
triggerVirtualEvent ( "vmousecancel" , event , getVirtualBindingFlags ( event . target ) ) ;
237
220
}
@@ -242,6 +225,10 @@ function handleScroll(event)
242
225
243
226
function handleTouchMove ( event )
244
227
{
228
+ if ( blockTouchTriggers ) {
229
+ return ;
230
+ }
231
+
245
232
var t = getNativeEvent ( event ) . touches [ 0 ] ;
246
233
247
234
var didCancel = didScroll ,
@@ -259,6 +246,10 @@ function handleTouchMove(event)
259
246
260
247
function handleTouchEnd ( event )
261
248
{
249
+ if ( blockTouchTriggers ) {
250
+ return ;
251
+ }
252
+
262
253
disableTouchBindings ( ) ;
263
254
264
255
var flags = getVirtualBindingFlags ( event . target ) ;
@@ -339,7 +330,22 @@ function getSpecialEventObject(eventType)
339
330
340
331
activeDocHandlers [ "touchstart" ] = ( activeDocHandlers [ "touchstart" ] || 0 ) + 1 ;
341
332
if ( activeDocHandlers [ "touchstart" ] === 1 ) {
342
- $document . bind ( "touchstart" , handleTouchStart ) ;
333
+ $document . bind ( "touchstart" , handleTouchStart )
334
+
335
+ . bind ( "touchend" , handleTouchEnd )
336
+
337
+ // On touch platforms, touching the screen and then dragging your finger
338
+ // causes the window content to scroll after some distance threshold is
339
+ // exceeded. On these platforms, a scroll prevents a click event from being
340
+ // dispatched, and on some platforms, even the touchend is suppressed. To
341
+ // mimic the suppression of the click event, we need to watch for a scroll
342
+ // event. Unfortunately, some platforms like iOS don't dispatch scroll
343
+ // events until *AFTER* the user lifts their finger (touchend). This means
344
+ // we need to watch both scroll and touchmove events to figure out whether
345
+ // or not a scroll happenens before the touchend event is fired.
346
+
347
+ . bind ( "touchmove" , handleTouchMove )
348
+ . bind ( "scroll" , handleScroll ) ;
343
349
}
344
350
}
345
351
} ,
@@ -359,7 +365,10 @@ function getSpecialEventObject(eventType)
359
365
360
366
-- activeDocHandlers [ "touchstart" ] ;
361
367
if ( ! activeDocHandlers [ "touchstart" ] ) {
362
- $document . unbind ( "touchstart" , handleTouchStart ) ;
368
+ $document . unbind ( "touchstart" , handleTouchStart )
369
+ . unbind ( "touchmove" , handleTouchMove )
370
+ . unbind ( "touchend" , handleTouchEnd )
371
+ . unbind ( "scroll" , handleScroll ) ;
363
372
}
364
373
}
365
374
0 commit comments