Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit b80bc8e

Browse files
committed
docs(gesture): add missing service and method docs (#11197)
1 parent c60982b commit b80bc8e

File tree

1 file changed

+57
-38
lines changed

1 file changed

+57
-38
lines changed

src/core/services/gesture/gesture.js

Lines changed: 57 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,82 @@
11
var HANDLERS = {};
22

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.
55
* It contains normalized x and y coordinates from DOM events,
66
* as well as other information abstracted from the DOM.
77
*/
8-
98
var pointer, lastPointer, forceSkipClickHijack = false, maxClickDistance = 6;
109

1110
/**
1211
* 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}
1413
*/
1514
var lastLabelClickPos = null;
1615

1716
// Used to attach event listeners once when multiple ng-apps are running.
1817
var isInitialized = false;
1918

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+
*/
2025
angular
2126
.module('material.core.gestures', [ ])
2227
.provider('$mdGesture', MdGestureProvider)
2328
.factory('$$MdGestureHandler', MdGestureHandler)
24-
.run(attachToDocument );
29+
.run(attachToDocument);
2530

2631
/**
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+
*/
5156
function MdGestureProvider() { }
5257

5358
MdGestureProvider.prototype = {
5459

55-
// Publish access to setter to configure a variable BEFORE the
60+
// Publish access to setter to configure a variable BEFORE the
5661
// $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+
*/
5769
skipClickHijack: function() {
5870
return forceSkipClickHijack = true;
5971
},
6072

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+
*/
6180
setMaxClickDistance: function(clickDistance) {
6281
maxClickDistance = parseInt(clickDistance);
6382
},
@@ -135,14 +154,14 @@ function MdGesture($$MdGestureHandler, $$rAF, $timeout) {
135154
};
136155
}
137156

138-
/*
157+
/**
139158
* Register an element to listen for a handler.
140159
* This allows an element to override the default options for a handler.
141160
* Additionally, some handlers like drag and hold only dispatch events if
142161
* the domEvent happens inside an element that's registered to listen for these events.
143162
*
144163
* @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 })
146165
*/
147166
function register(element, handlerName, options) {
148167
var handler = HANDLERS[handlerName.replace(/^\$md./, '')];
@@ -164,7 +183,7 @@ function MdGesture($$MdGestureHandler, $$rAF, $timeout) {
164183
return self;
165184
}
166185

167-
/*
186+
/**
168187
* Register handlers. These listen to touch/start/move events, interpret them,
169188
* and dispatch gesture events depending on options & conditions. These are all
170189
* instances of GestureHandler.
@@ -476,7 +495,7 @@ function MdGestureHandler() {
476495
angular.element(eventPointer.target).trigger(eventObj);
477496
}
478497

479-
/*
498+
/**
480499
* NOTE: nativeDispatchEvent is very performance sensitive.
481500
* @param srcEvent the original DOM touch event that started this.
482501
* @param eventType the name of the custom event to send (eg 'click' or '$md.drag')
@@ -486,7 +505,7 @@ function MdGestureHandler() {
486505
eventPointer = eventPointer || pointer;
487506
var eventObj;
488507

489-
if (eventType === 'click' || eventType == 'mouseup' || eventType == 'mousedown' ) {
508+
if (eventType === 'click' || eventType === 'mouseup' || eventType === 'mousedown' ) {
490509
eventObj = document.createEvent('MouseEvents');
491510
eventObj.initMouseEvent(
492511
eventType, true, true, window, srcEvent.detail,
@@ -732,7 +751,7 @@ function updatePointerState(ev, pointer) {
732751
pointer.velocityY = pointer.distanceY / pointer.duration;
733752
}
734753

735-
/*
754+
/**
736755
* Normalize the point where the DOM event happened whether it's touch or mouse.
737756
* @returns point event obj with pageX and pageY on it.
738757
*/
@@ -747,13 +766,13 @@ function getEventPoint(ev) {
747766
function canFocus(element) {
748767
return (
749768
!!element &&
750-
element.getAttribute('tabindex') != '-1' &&
769+
element.getAttribute('tabindex') !== '-1' &&
751770
!element.hasAttribute('disabled') &&
752771
(
753772
element.hasAttribute('tabindex') ||
754773
element.hasAttribute('href') ||
755774
element.isContentEditable ||
756-
['INPUT', 'SELECT', 'BUTTON', 'TEXTAREA', 'VIDEO', 'AUDIO'].indexOf(element.nodeName) != -1
775+
['INPUT', 'SELECT', 'BUTTON', 'TEXTAREA', 'VIDEO', 'AUDIO'].indexOf(element.nodeName) !== -1
757776
)
758777
);
759778
}

0 commit comments

Comments
 (0)