@@ -9,14 +9,16 @@ const USER_AGENT = window.navigator && window.navigator.userAgent || '';
9
9
const webkitVersionMap = ( / A p p l e W e b K i t \/ ( [ \d . ] + ) / i) . exec ( USER_AGENT ) ;
10
10
const appleWebkitVersion = webkitVersionMap ? parseFloat ( webkitVersionMap . pop ( ) ) : null ;
11
11
12
+ const browser = { } ;
13
+
12
14
/**
13
15
* Whether or not this device is an iPad.
14
16
*
15
17
* @static
16
18
* @const
17
19
* @type {Boolean }
18
20
*/
19
- export const IS_IPAD = ( / i P a d / i) . test ( USER_AGENT ) ;
21
+ export const IS_IPAD = browser . IS_IPAD = ( / i P a d / i) . test ( USER_AGENT ) ;
20
22
21
23
/**
22
24
* Whether or not this device is an iPhone.
@@ -28,7 +30,7 @@ export const IS_IPAD = (/iPad/i).test(USER_AGENT);
28
30
// The Facebook app's UIWebView identifies as both an iPhone and iPad, so
29
31
// to identify iPhones, we need to exclude iPads.
30
32
// http://artsy.github.io/blog/2012/10/18/the-perils-of-ios-user-agent-sniffing/
31
- export const IS_IPHONE = ( / i P h o n e / i) . test ( USER_AGENT ) && ! IS_IPAD ;
33
+ export const IS_IPHONE = browser . IS_IPHONE = ( / i P h o n e / i) . test ( USER_AGENT ) && ! IS_IPAD ;
32
34
33
35
/**
34
36
* Whether or not this device is an iPod.
@@ -37,7 +39,7 @@ export const IS_IPHONE = (/iPhone/i).test(USER_AGENT) && !IS_IPAD;
37
39
* @const
38
40
* @type {Boolean }
39
41
*/
40
- export const IS_IPOD = ( / i P o d / i) . test ( USER_AGENT ) ;
42
+ export const IS_IPOD = browser . IS_IPOD = ( / i P o d / i) . test ( USER_AGENT ) ;
41
43
42
44
/**
43
45
* Whether or not this is an iOS device.
@@ -46,7 +48,7 @@ export const IS_IPOD = (/iPod/i).test(USER_AGENT);
46
48
* @const
47
49
* @type {Boolean }
48
50
*/
49
- export const IS_IOS = IS_IPHONE || IS_IPAD || IS_IPOD ;
51
+ export const IS_IOS = browser . IS_IOS = IS_IPHONE || IS_IPAD || IS_IPOD ;
50
52
51
53
/**
52
54
* The detected iOS version - or `null`.
@@ -55,7 +57,7 @@ export const IS_IOS = IS_IPHONE || IS_IPAD || IS_IPOD;
55
57
* @const
56
58
* @type {string|null }
57
59
*/
58
- export const IOS_VERSION = ( function ( ) {
60
+ export const IOS_VERSION = browser . IOS_VERSION = ( function ( ) {
59
61
const match = USER_AGENT . match ( / O S ( \d + ) _ / i) ;
60
62
61
63
if ( match && match [ 1 ] ) {
@@ -71,7 +73,7 @@ export const IOS_VERSION = (function() {
71
73
* @const
72
74
* @type {Boolean }
73
75
*/
74
- export const IS_ANDROID = ( / A n d r o i d / i) . test ( USER_AGENT ) ;
76
+ export const IS_ANDROID = browser . IS_ANDROID = ( / A n d r o i d / i) . test ( USER_AGENT ) ;
75
77
76
78
/**
77
79
* The detected Android version - or `null`.
@@ -80,7 +82,7 @@ export const IS_ANDROID = (/Android/i).test(USER_AGENT);
80
82
* @const
81
83
* @type {number|string|null }
82
84
*/
83
- export const ANDROID_VERSION = ( function ( ) {
85
+ export const ANDROID_VERSION = browser . ANDROID_VERSION = ( function ( ) {
84
86
// This matches Android Major.Minor.Patch versions
85
87
// ANDROID_VERSION is Major.Minor as a Number, if Minor isn't available, then only Major is returned
86
88
const match = USER_AGENT . match ( / A n d r o i d ( \d + ) (?: \. ( \d + ) ) ? (?: \. ( \d + ) ) * / i) ;
@@ -107,7 +109,7 @@ export const ANDROID_VERSION = (function() {
107
109
* @const
108
110
* @type {Boolean }
109
111
*/
110
- export const IS_NATIVE_ANDROID = IS_ANDROID && ANDROID_VERSION < 5 && appleWebkitVersion < 537 ;
112
+ export const IS_NATIVE_ANDROID = browser . IS_NATIVE_ANDROID = IS_ANDROID && ANDROID_VERSION < 5 && appleWebkitVersion < 537 ;
111
113
112
114
/**
113
115
* Whether or not this is Mozilla Firefox.
@@ -116,7 +118,7 @@ export const IS_NATIVE_ANDROID = IS_ANDROID && ANDROID_VERSION < 5 && appleWebki
116
118
* @const
117
119
* @type {Boolean }
118
120
*/
119
- export const IS_FIREFOX = ( / F i r e f o x / i) . test ( USER_AGENT ) ;
121
+ export const IS_FIREFOX = browser . IS_FIREFOX = ( / F i r e f o x / i) . test ( USER_AGENT ) ;
120
122
121
123
/**
122
124
* Whether or not this is Microsoft Edge.
@@ -125,7 +127,7 @@ export const IS_FIREFOX = (/Firefox/i).test(USER_AGENT);
125
127
* @const
126
128
* @type {Boolean }
127
129
*/
128
- export const IS_EDGE = ( / E d g e / i) . test ( USER_AGENT ) ;
130
+ export const IS_EDGE = browser . IS_EDGE = ( / E d g e / i) . test ( USER_AGENT ) ;
129
131
130
132
/**
131
133
* Whether or not this is Google Chrome.
@@ -137,7 +139,7 @@ export const IS_EDGE = (/Edge/i).test(USER_AGENT);
137
139
* @const
138
140
* @type {Boolean }
139
141
*/
140
- export const IS_CHROME = ! IS_EDGE && ( ( / C h r o m e / i) . test ( USER_AGENT ) || ( / C r i O S / i) . test ( USER_AGENT ) ) ;
142
+ export const IS_CHROME = browser . IS_CHROME = ! IS_EDGE && ( ( / C h r o m e / i) . test ( USER_AGENT ) || ( / C r i O S / i) . test ( USER_AGENT ) ) ;
141
143
142
144
/**
143
145
* The detected Google Chrome version - or `null`.
@@ -146,7 +148,7 @@ export const IS_CHROME = !IS_EDGE && ((/Chrome/i).test(USER_AGENT) || (/CriOS/i)
146
148
* @const
147
149
* @type {number|null }
148
150
*/
149
- export const CHROME_VERSION = ( function ( ) {
151
+ export const CHROME_VERSION = browser . CHROME_VERSION = ( function ( ) {
150
152
const match = USER_AGENT . match ( / ( C h r o m e | C r i O S ) \/ ( \d + ) / ) ;
151
153
152
154
if ( match && match [ 2 ] ) {
@@ -162,7 +164,7 @@ export const CHROME_VERSION = (function() {
162
164
* @const
163
165
* @type {number|null }
164
166
*/
165
- export const IE_VERSION = ( function ( ) {
167
+ export const IE_VERSION = browser . IE_VERSION = ( function ( ) {
166
168
const result = ( / M S I E \s ( \d + ) \. \d / ) . exec ( USER_AGENT ) ;
167
169
let version = result && parseFloat ( result [ 1 ] ) ;
168
170
@@ -181,7 +183,7 @@ export const IE_VERSION = (function() {
181
183
* @const
182
184
* @type {Boolean }
183
185
*/
184
- export const IS_SAFARI = ( / S a f a r i / i) . test ( USER_AGENT ) && ! IS_CHROME && ! IS_ANDROID && ! IS_EDGE ;
186
+ export const IS_SAFARI = browser . IS_SAFARI = ( / S a f a r i / i) . test ( USER_AGENT ) && ! IS_CHROME && ! IS_ANDROID && ! IS_EDGE ;
185
187
186
188
/**
187
189
* Whether or not this is any flavor of Safari - including iOS.
@@ -190,7 +192,7 @@ export const IS_SAFARI = (/Safari/i).test(USER_AGENT) && !IS_CHROME && !IS_ANDRO
190
192
* @const
191
193
* @type {Boolean }
192
194
*/
193
- export const IS_ANY_SAFARI = ( IS_SAFARI || IS_IOS ) && ! IS_CHROME ;
195
+ export const IS_ANY_SAFARI = browser . IS_ANY_SAFARI = ( IS_SAFARI || IS_IOS ) && ! IS_CHROME ;
194
196
195
197
/**
196
198
* Whether or not this device is touch-enabled.
@@ -199,7 +201,18 @@ export const IS_ANY_SAFARI = (IS_SAFARI || IS_IOS) && !IS_CHROME;
199
201
* @const
200
202
* @type {Boolean }
201
203
*/
202
- export const TOUCH_ENABLED = Dom . isReal ( ) && (
204
+ export const TOUCH_ENABLED = browser . TOUCH_ENABLE = Dom . isReal ( ) && (
203
205
'ontouchstart' in window ||
204
206
window . navigator . maxTouchPoints ||
205
207
window . DocumentTouch && window . document instanceof window . DocumentTouch ) ;
208
+
209
+ /**
210
+ * A function that can be used to override values in this module
211
+ *
212
+ * @param {Object } obj
213
+ * The object that contains keys/values that should override
214
+ * keys/values in this module
215
+ */
216
+ export const override = function ( obj ) {
217
+ Object . assign ( browser , obj ) ;
218
+ } ;
0 commit comments