1
1
var HANDLERS = { } ;
2
2
3
- /* The state of the current 'pointer'
4
- * The pointer represents the state of the current touch.
3
+ /**
4
+ * The state of the current 'pointer'. The pointer represents the state of the current touch.
5
5
* It contains normalized x and y coordinates from DOM events,
6
6
* as well as other information abstracted from the DOM.
7
7
*/
8
-
9
8
var pointer , lastPointer , forceSkipClickHijack = false , maxClickDistance = 6 ;
10
9
11
10
/**
12
11
* The position of the most recent click if that click was on a label element.
13
- * @type {{x: number, y: number}? }
12
+ * @type {{x: number, y: number}|null }
14
13
*/
15
14
var lastLabelClickPos = null ;
16
15
17
16
// Used to attach event listeners once when multiple ng-apps are running.
18
17
var isInitialized = false ;
19
18
19
+ /**
20
+ * @ngdoc module
21
+ * @name material.core.gestures
22
+ * @description
23
+ * AngularJS Material Gesture handling for touch devices. This module replaced the usage of the hammerjs library.
24
+ */
20
25
angular
21
26
. module ( 'material.core.gestures' , [ ] )
22
27
. provider ( '$mdGesture' , MdGestureProvider )
23
28
. factory ( '$$MdGestureHandler' , MdGestureHandler )
24
- . run ( attachToDocument ) ;
29
+ . run ( attachToDocument ) ;
25
30
26
31
/**
27
- * @ngdoc service
28
- * @name $mdGestureProvider
29
- * @module material.core.gestures
30
- *
31
- * @description
32
- * In some scenarios on Mobile devices (without jQuery), the click events should NOT be hijacked.
33
- * `$mdGestureProvider` is used to configure the Gesture module to ignore or skip click hijacking on mobile
34
- * devices.
35
- * You can also change max click distance (6px by default) if you have issues on some touch screens.
36
- *
37
- * <hljs lang="js">
38
- * app.config(function($mdGestureProvider) {
39
- *
40
- * // For mobile devices without jQuery loaded, do not
41
- * // intercept click events during the capture phase.
42
- * $mdGestureProvider.skipClickHijack();
43
- *
44
- * // If hijcacking clicks, change default 6px click distance
45
- * $mdGestureProvider.setMaxClickDistance(12);
46
- *
47
- * });
48
- * </hljs>
49
- *
50
- */
32
+ * @ngdoc service
33
+ * @name $mdGestureProvider
34
+ * @module material.core.gestures
35
+ *
36
+ * @description
37
+ * In some scenarios on mobile devices (without jQuery), the click events should NOT be hijacked.
38
+ * `$mdGestureProvider` is used to configure the Gesture module to ignore or skip click hijacking on mobile
39
+ * devices.
40
+ *
41
+ * You can also change the max click distance, `6px` by default, if you have issues on some touch screens.
42
+ *
43
+ * <hljs lang="js">
44
+ * app.config(function($mdGestureProvider) {
45
+ *
46
+ * // For mobile devices without jQuery loaded, do not
47
+ * // intercept click events during the capture phase.
48
+ * $mdGestureProvider.skipClickHijack();
49
+ *
50
+ * // If hijacking clicks, you may want to change the default click distance
51
+ * $mdGestureProvider.setMaxClickDistance(12);
52
+ * });
53
+ * </hljs>
54
+ *
55
+ */
51
56
function MdGestureProvider ( ) { }
52
57
53
58
MdGestureProvider . prototype = {
54
59
55
- // Publish access to setter to configure a variable BEFORE the
60
+ // Publish access to setter to configure a variable BEFORE the
56
61
// $mdGesture service is instantiated...
62
+ /**
63
+ * @ngdoc method
64
+ * @name $mdGestureProvider#skipClickHijack
65
+ *
66
+ * @description
67
+ * Tell the AngularJS Material Gesture module to skip (or ignore) click hijacking on mobile devices.
68
+ */
57
69
skipClickHijack : function ( ) {
58
70
return forceSkipClickHijack = true ;
59
71
} ,
60
72
73
+ /**
74
+ * @ngdoc method
75
+ * @name $mdGestureProvider#setMaxClickDistance
76
+ * @param clickDistance {string} Distance in pixels. I.e. `12px`.
77
+ * @description
78
+ * Set the max distance from the origin of the touch event to trigger touch handlers.
79
+ */
61
80
setMaxClickDistance : function ( clickDistance ) {
62
81
maxClickDistance = parseInt ( clickDistance ) ;
63
82
} ,
@@ -135,14 +154,14 @@ function MdGesture($$MdGestureHandler, $$rAF, $timeout) {
135
154
} ;
136
155
}
137
156
138
- /*
157
+ /**
139
158
* Register an element to listen for a handler.
140
159
* This allows an element to override the default options for a handler.
141
160
* Additionally, some handlers like drag and hold only dispatch events if
142
161
* the domEvent happens inside an element that's registered to listen for these events.
143
162
*
144
163
* @see GestureHandler for how overriding of default options works.
145
- * @example $mdGesture.register(myElement, 'drag', { minDistance: 20, horziontal : false })
164
+ * @example $mdGesture.register(myElement, 'drag', { minDistance: 20, horizontal : false })
146
165
*/
147
166
function register ( element , handlerName , options ) {
148
167
var handler = HANDLERS [ handlerName . replace ( / ^ \$ m d ./ , '' ) ] ;
@@ -164,7 +183,7 @@ function MdGesture($$MdGestureHandler, $$rAF, $timeout) {
164
183
return self ;
165
184
}
166
185
167
- /*
186
+ /**
168
187
* Register handlers. These listen to touch/start/move events, interpret them,
169
188
* and dispatch gesture events depending on options & conditions. These are all
170
189
* instances of GestureHandler.
@@ -476,7 +495,7 @@ function MdGestureHandler() {
476
495
angular . element ( eventPointer . target ) . trigger ( eventObj ) ;
477
496
}
478
497
479
- /*
498
+ /**
480
499
* NOTE: nativeDispatchEvent is very performance sensitive.
481
500
* @param srcEvent the original DOM touch event that started this.
482
501
* @param eventType the name of the custom event to send (eg 'click' or '$md.drag')
@@ -486,7 +505,7 @@ function MdGestureHandler() {
486
505
eventPointer = eventPointer || pointer ;
487
506
var eventObj ;
488
507
489
- if ( eventType === 'click' || eventType == 'mouseup' || eventType == 'mousedown' ) {
508
+ if ( eventType === 'click' || eventType === 'mouseup' || eventType = == 'mousedown' ) {
490
509
eventObj = document . createEvent ( 'MouseEvents' ) ;
491
510
eventObj . initMouseEvent (
492
511
eventType , true , true , window , srcEvent . detail ,
@@ -732,7 +751,7 @@ function updatePointerState(ev, pointer) {
732
751
pointer . velocityY = pointer . distanceY / pointer . duration ;
733
752
}
734
753
735
- /*
754
+ /**
736
755
* Normalize the point where the DOM event happened whether it's touch or mouse.
737
756
* @returns point event obj with pageX and pageY on it.
738
757
*/
@@ -747,13 +766,13 @@ function getEventPoint(ev) {
747
766
function canFocus ( element ) {
748
767
return (
749
768
! ! element &&
750
- element . getAttribute ( 'tabindex' ) != '-1' &&
769
+ element . getAttribute ( 'tabindex' ) !== '-1' &&
751
770
! element . hasAttribute ( 'disabled' ) &&
752
771
(
753
772
element . hasAttribute ( 'tabindex' ) ||
754
773
element . hasAttribute ( 'href' ) ||
755
774
element . isContentEditable ||
756
- [ 'INPUT' , 'SELECT' , 'BUTTON' , 'TEXTAREA' , 'VIDEO' , 'AUDIO' ] . indexOf ( element . nodeName ) != - 1
775
+ [ 'INPUT' , 'SELECT' , 'BUTTON' , 'TEXTAREA' , 'VIDEO' , 'AUDIO' ] . indexOf ( element . nodeName ) !== - 1
757
776
)
758
777
) ;
759
778
}
0 commit comments