1
+ /**
2
+ * Hilo
3
+ * Copyright 2015 alibaba.com
4
+ * Licensed under the MIT License
5
+ */
6
+
7
+ /**
8
+ * @language =en
9
+ * @class Browser feature set
10
+ * @static
11
+ * @module hilo/util/browser
12
+ */
13
+ /**
14
+ * @language =zh
15
+ * @class 浏览器特性集合
16
+ * @static
17
+ * @module hilo/util/browser
18
+ */
19
+ var browser = ( function ( ) {
20
+ var ua = navigator . userAgent ;
21
+ var doc = document ;
22
+ var win = window ;
23
+ var docElem = doc . documentElement ;
24
+
25
+ var data = /** @lends browser */ {
26
+ /**
27
+ * 是否是iphone
28
+ * @type {Boolean }
29
+ */
30
+ iphone : / i p h o n e / i. test ( ua ) ,
31
+
32
+ /**
33
+ * 是否是ipad
34
+ * @type {Boolean }
35
+ */
36
+ ipad : / i p a d / i. test ( ua ) ,
37
+
38
+ /**
39
+ * 是否是ipod
40
+ * @type {Boolean }
41
+ */
42
+ ipod : / i p o d / i. test ( ua ) ,
43
+
44
+ /**
45
+ * 是否是ios
46
+ * @type {Boolean }
47
+ */
48
+ ios : / i p h o n e | i p a d | i p o d / i. test ( ua ) ,
49
+
50
+ /**
51
+ * 是否是android
52
+ * @type {Boolean }
53
+ */
54
+ android : / a n d r o i d / i. test ( ua ) ,
55
+
56
+ /**
57
+ * 是否是webkit
58
+ * @type {Boolean }
59
+ */
60
+ webkit : / w e b k i t / i. test ( ua ) ,
61
+
62
+ /**
63
+ * 是否是chrome
64
+ * @type {Boolean }
65
+ */
66
+ chrome : / c h r o m e / i. test ( ua ) ,
67
+
68
+ /**
69
+ * 是否是safari
70
+ * @type {Boolean }
71
+ */
72
+ safari : / s a f a r i / i. test ( ua ) ,
73
+
74
+ /**
75
+ * 是否是firefox
76
+ * @type {Boolean }
77
+ */
78
+ firefox : / f i r e f o x / i. test ( ua ) ,
79
+
80
+ /**
81
+ * 是否是ie
82
+ * @type {Boolean }
83
+ */
84
+ ie : / m s i e / i. test ( ua ) ,
85
+
86
+ /**
87
+ * 是否是opera
88
+ * @type {Boolean }
89
+ */
90
+ opera : / o p e r a / i. test ( ua ) ,
91
+ /**
92
+ * 是否支持触碰事件。
93
+ * @type {String }
94
+ */
95
+ supportTouch : 'ontouchstart' in win ,
96
+
97
+ /**
98
+ * 是否支持canvas元素。
99
+ * @type {Boolean }
100
+ */
101
+ supportCanvas : doc . createElement ( 'canvas' ) . getContext != null ,
102
+ /**
103
+ * 是否支持本地存储localStorage。
104
+ * @type {Boolean }
105
+ */
106
+ supportStorage : false ,
107
+
108
+ /**
109
+ * 是否支持检测设备方向orientation。
110
+ * @type {Boolean }
111
+ */
112
+ supportOrientation : 'orientation' in win ,
113
+
114
+ /**
115
+ * 是否支持检测加速度devicemotion。
116
+ * @type {Boolean }
117
+ */
118
+ supportDeviceMotion : 'ondevicemotion' in win
119
+ } ;
120
+
121
+ //`localStorage` is null or `localStorage.setItem` throws error in some cases (e.g. localStorage is disabled)
122
+ try {
123
+ var value = 'hilo' ;
124
+ localStorage . setItem ( value , value ) ;
125
+ localStorage . removeItem ( value ) ;
126
+ data . supportStorage = true ;
127
+ } catch ( e ) { }
128
+
129
+ /**
130
+ * 浏览器厂商CSS前缀的js值。比如:webkit。
131
+ * @type {String }
132
+ */
133
+ var jsVendor = data . jsVendor = data . webkit ? 'webkit' : data . firefox ? 'webkit' : data . opera ? 'o' : data . ie ? 'ms' : '' ;
134
+ /**
135
+ * 浏览器厂商CSS前缀的css值。比如:-webkit-。
136
+ * @type {String }
137
+ */
138
+ var cssVendor = data . cssVendor = '-' + jsVendor + '-' ;
139
+
140
+ //css transform/3d feature dectection
141
+ var testElem = doc . createElement ( 'div' ) , style = testElem . style ;
142
+ /**
143
+ * 是否支持CSS Transform变换。
144
+ * @type {Boolean }
145
+ */
146
+ var supportTransform = style [ jsVendor + 'Transform' ] != undefined ;
147
+
148
+ /**
149
+ * 是否支持CSS Transform 3D变换。
150
+ * @type {Boolean }
151
+ */
152
+ var supportTransform3D = style [ jsVendor + 'Perspective' ] != undefined ;
153
+ if ( supportTransform3D ) {
154
+ testElem . id = 'test3d' ;
155
+ style = doc . createElement ( 'style' ) ;
156
+ style . textContent = '@media (' + cssVendor + 'transform-3d){#test3d{height:3px}}' ;
157
+ doc . head . appendChild ( style ) ;
158
+
159
+ docElem . appendChild ( testElem ) ;
160
+ supportTransform3D = testElem . offsetHeight == 3 ;
161
+ doc . head . removeChild ( style ) ;
162
+ docElem . removeChild ( testElem ) ;
163
+ }
164
+ data . supportTransform = supportTransform ;
165
+ data . supportTransform3D = supportTransform3D ;
166
+
167
+ return data ;
168
+ } ) ( ) ;
0 commit comments