2
2
* Pointer Events shim
3
3
*/
4
4
define ( [
5
+ "./handlers/features" ,
5
6
"./handlers/utils" ,
6
7
"./handlers/touch" ,
7
8
"./handlers/mouse" ,
8
9
"./handlers/mspointer"
9
- ] , function ( utils , touch , mouse , mspointer ) {
10
+ ] , function ( has , utils , touch , mouse , mspointer ) {
10
11
"use strict" ;
11
12
12
- var pointerEvents = { _targetElement : null } ,
13
- feature = {
14
- //todo: should use has() module instead and
15
- //consider loading touch and mspointer modules conditionally.
16
- touch : ( "ontouchstart" in document ) ,
17
- pointer : ( "onpointerdown" in document ) ,
18
- mspointer : ( "onmspointerdown" in document ) ,
19
- chrome : / c h r o m e / i. test ( navigator . userAgent ) ,
20
- mobile : / ( m o b i l e ) | ( a n d r o i d ) / i. test ( navigator . userAgent )
21
- } ;
13
+ var pointerEvents = { _targetElement : null } ;
22
14
23
15
/**
24
16
* Enable Pointer events. Register native event handlers. Importing this module automatically register native
@@ -32,14 +24,14 @@ define([
32
24
if ( this . _targetElement ) {
33
25
return ; // already initialized
34
26
}
35
- if ( ! feature . pointer ) {
36
- if ( feature . mspointer ) {
27
+ if ( ! has ( " pointer" ) ) {
28
+ if ( has ( " mspointer" ) ) {
37
29
mspointer . registerHandlers ( targetElement ) ;
38
30
} else {
39
- if ( feature . touch ) {
40
- if ( ! feature . mobile ) {
31
+ if ( has ( " touch" ) ) {
32
+ if ( ! has ( " mobile" ) ) {
41
33
mouse . registerHandlers ( targetElement ) ;
42
- if ( feature . chrome ) {
34
+ if ( has ( " chrome" ) ) {
43
35
touch . registerHandlers ( targetElement ) ;
44
36
}
45
37
} else {
@@ -91,10 +83,10 @@ define([
91
83
if ( ! this . _targetElement ) {
92
84
return false ; // not initialized
93
85
}
94
- if ( feature . pointer ) {
86
+ if ( has ( " pointer" ) ) {
95
87
return targetElement . setPointerCapture ( pointerId ) ; // use native Pointer Events method
96
88
} else {
97
- if ( feature . mspointer ) {
89
+ if ( has ( " mspointer" ) ) {
98
90
return targetElement . msSetPointerCapture ( pointerId ) ; // use native Pointer Events method
99
91
} else {
100
92
if ( pointerId === 1 ) { // mouse always gets ID = 1
@@ -116,10 +108,10 @@ define([
116
108
if ( ! this . _targetElement ) {
117
109
return false ;
118
110
}
119
- if ( feature . pointer ) {
111
+ if ( has ( " pointer" ) ) {
120
112
return targetElement . releasePointerCapture ( pointerId ) ;
121
113
} else {
122
- if ( feature . mspointer ) {
114
+ if ( has ( " mspointer" ) ) {
123
115
return targetElement . msReleasePointerCapture ( pointerId ) ;
124
116
} else {
125
117
if ( pointerId === 1 ) {
@@ -149,12 +141,12 @@ define([
149
141
}
150
142
151
143
// CSS rule when user agent implements W3C Pointer Events or when a polyfill is in place.
152
- if ( feature . pointer ) {
144
+ if ( has ( " pointer" ) ) {
153
145
insertTouchActionCSSRule ( "touch-action" ) ;
154
146
}
155
147
156
148
// CSS rule for IE10 and IE11 preview
157
- if ( feature . mspointer ) {
149
+ if ( has ( " mspointer" ) ) {
158
150
insertTouchActionCSSRule ( "-ms-touch-action" ) ;
159
151
}
160
152
@@ -178,7 +170,7 @@ define([
178
170
* @param e click event
179
171
*/
180
172
function clickHandler ( e ) {
181
- if ( feature . touch ) {
173
+ if ( has ( " touch" ) ) {
182
174
// (7) Android 4.1.1 generates a click after touchend even when touchstart is prevented.
183
175
// if we receive a native click at an element with touch action disabled we just have to absorb it.
184
176
// (fixed in Android 4.1.2+)
0 commit comments