@@ -73,6 +73,7 @@ function MdGesture($$MdGestureHandler, $$rAF, $timeout) {
73
73
var userAgent = navigator . userAgent || navigator . vendor || window . opera ;
74
74
var isIos = userAgent . match ( / i p a d | i p h o n e | i p o d / i) ;
75
75
var isAndroid = userAgent . match ( / a n d r o i d / i) ;
76
+ var touchActionProperty = getTouchAction ( ) ;
76
77
var hasJQuery = ( typeof window . jQuery !== 'undefined' ) && ( angular . element === window . jQuery ) ;
77
78
78
79
var self = {
@@ -215,7 +216,7 @@ function MdGesture($$MdGestureHandler, $$rAF, $timeout) {
215
216
// If we don't preventDefault touchmove events here, Android will assume we don't
216
217
// want to listen to anymore touch events. It will start scrolling and stop sending
217
218
// touchmove events.
218
- ev . preventDefault ( ) ;
219
+ if ( ! touchActionProperty && ev . type === 'touchmove' ) ev . preventDefault ( ) ;
219
220
220
221
// If the user moves greater than <maxDistance> pixels, stop the hold timer
221
222
// set in onStart
@@ -234,7 +235,7 @@ function MdGesture($$MdGestureHandler, $$rAF, $timeout) {
234
235
* The drag handler dispatches a drag event if the user holds and moves his finger greater than
235
236
* <minDistance> px in the x or y direction, depending on options.horizontal.
236
237
* The drag will be cancelled if the user moves his finger greater than <minDistance>*<cancelMultiplier> in
237
- * the perpindicular direction. Eg if the drag is horizontal and the user moves his finger <minDistance>*<cancelMultiplier>
238
+ * the perpendicular direction. Eg if the drag is horizontal and the user moves his finger <minDistance>*<cancelMultiplier>
238
239
* pixels vertically, this handler won't consider the move part of a drag.
239
240
*/
240
241
. handler ( 'drag' , {
@@ -243,6 +244,18 @@ function MdGesture($$MdGestureHandler, $$rAF, $timeout) {
243
244
horizontal : true ,
244
245
cancelMultiplier : 1.5
245
246
} ,
247
+ onSetup : function ( element , options ) {
248
+ if ( touchActionProperty ) {
249
+ // We check for horizontal to be false, because otherwise we would overwrite the default opts.
250
+ this . oldTouchAction = element [ 0 ] . style [ touchActionProperty ] ;
251
+ element [ 0 ] . style [ touchActionProperty ] = options . horizontal === false ? 'pan-y' : 'pan-x' ;
252
+ }
253
+ } ,
254
+ onCleanup : function ( element ) {
255
+ if ( this . oldTouchAction ) {
256
+ element [ 0 ] . style [ touchActionProperty ] = this . oldTouchAction ;
257
+ }
258
+ } ,
246
259
onStart : function ( ev ) {
247
260
// For drag, require a parent to be registered with $mdGesture.register()
248
261
if ( ! this . state . registeredParent ) this . cancel ( ) ;
@@ -253,7 +266,7 @@ function MdGesture($$MdGestureHandler, $$rAF, $timeout) {
253
266
// If we don't preventDefault touchmove events here, Android will assume we don't
254
267
// want to listen to anymore touch events. It will start scrolling and stop sending
255
268
// touchmove events.
256
- ev . preventDefault ( ) ;
269
+ if ( ! touchActionProperty && ev . type === 'touchmove' ) ev . preventDefault ( ) ;
257
270
258
271
if ( ! this . state . dragPointer ) {
259
272
if ( this . state . options . horizontal ) {
@@ -277,7 +290,7 @@ function MdGesture($$MdGestureHandler, $$rAF, $timeout) {
277
290
this . dispatchDragMove ( ev ) ;
278
291
}
279
292
} ,
280
- // Only dispatch dragmove events every frame; any more is unnecessray
293
+ // Only dispatch dragmove events every frame; any more is unnecessary
281
294
dispatchDragMove : $$rAF . throttle ( function ( ev ) {
282
295
// Make sure the drag didn't stop while waiting for the next frame
283
296
if ( this . state . isRunning ) {
@@ -318,6 +331,19 @@ function MdGesture($$MdGestureHandler, $$rAF, $timeout) {
318
331
}
319
332
} ) ;
320
333
334
+ function getTouchAction ( ) {
335
+ var testEl = document . createElement ( 'div' ) ;
336
+ var vendorPrefixes = [ '' , 'webkit' , 'Moz' , 'MS' , 'ms' , 'o' ] ;
337
+
338
+ for ( var i = 0 ; i < vendorPrefixes . length ; i ++ ) {
339
+ var prefix = vendorPrefixes [ i ] ;
340
+ var property = prefix ? prefix + 'TouchAction' : 'touchAction' ;
341
+ if ( angular . isDefined ( testEl . style [ property ] ) ) {
342
+ return property ;
343
+ }
344
+ }
345
+ }
346
+
321
347
}
322
348
323
349
/**
@@ -346,6 +372,8 @@ function MdGestureHandler() {
346
372
dispatchEvent : hasJQuery ? jQueryDispatchEvent : nativeDispatchEvent ,
347
373
348
374
// These are overridden by the registered handler
375
+ onSetup : angular . noop ,
376
+ onCleanup : angular . noop ,
349
377
onStart : angular . noop ,
350
378
onMove : angular . noop ,
351
379
onEnd : angular . noop ,
@@ -395,7 +423,7 @@ function MdGestureHandler() {
395
423
return null ;
396
424
} ,
397
425
398
- // Called from $mdGesture.register when an element reigsters itself with a handler.
426
+ // Called from $mdGesture.register when an element registers itself with a handler.
399
427
// Store the options the user gave on the DOMElement itself. These options will
400
428
// be retrieved with getNearestParent when the handler starts.
401
429
registerElement : function ( element , options ) {
@@ -404,11 +432,15 @@ function MdGestureHandler() {
404
432
element [ 0 ] . $mdGesture [ this . name ] = options || { } ;
405
433
element . on ( '$destroy' , onDestroy ) ;
406
434
435
+ self . onSetup ( element , options || { } ) ;
436
+
407
437
return onDestroy ;
408
438
409
439
function onDestroy ( ) {
410
440
delete element [ 0 ] . $mdGesture [ self . name ] ;
411
441
element . off ( '$destroy' , onDestroy ) ;
442
+
443
+ self . onCleanup ( element , options || { } ) ;
412
444
}
413
445
}
414
446
} ;
0 commit comments