11
11
\E5.,E5F EE1. /; ``*4EEEZhw._ EEEL
12
12
```` `` JEEE. `"45EEEhw.,,,]
13
13
14
- From 2010 till ∞
14
+ From 2010 till infinity
15
15
typecode-js v 0.1
16
16
*/
17
17
18
18
define ( [ 'jquery' , 'NIseed' ] , function ( $ ) {
19
-
19
+
20
20
var window = this ,
21
21
NI = window . NI ;
22
22
23
23
function BrowserDetection ( options ) {
24
24
var o , elements ;
25
-
25
+
26
26
o = $ . extend ( {
27
- addClassToBody :true ,
28
- orientationListen :false ,
29
- detectWebApp :true
27
+ orientation_listen : false ,
28
+ detect_touch : true
30
29
} , options ) ;
31
-
30
+
32
31
elements = {
33
32
body :$ ( 'body' )
34
33
} ;
35
-
34
+
36
35
function init ( ) {
37
36
var userAgent = navigator . userAgent ;
38
37
var appVersion = navigator . appVersion ;
39
- var browser = $ . browser ;
40
-
38
+ var browser = { } ;
39
+
40
+ browser . mozilla = / m o z i l l a / . test ( userAgent . toLowerCase ( ) ) && ! / w e b k i t / . test ( userAgent . toLowerCase ( ) ) ;
41
+ browser . webkit = / w e b k i t / . test ( userAgent . toLowerCase ( ) ) ;
42
+ browser . opera = / o p e r a / . test ( userAgent . toLowerCase ( ) ) ;
43
+ browser . msie = / m s i e / . test ( userAgent . toLowerCase ( ) ) ;
44
+
41
45
// check if browser is webkit...
42
46
if ( browser . webkit ) {
43
- if ( o . addClassToBody ) {
47
+ if ( o . add_class_to_body ) {
44
48
elements . body . addClass ( 'browser-webkit' ) ;
45
49
}
46
-
50
+
47
51
// check if it's chrome, safari, or an iOS browser
48
52
if ( userAgent . match ( / i P a d / i) !== null ) {
49
- if ( o . addClassToBody ) {
50
- elements . body . addClass ( 'browser-ipad os-ios' ) ;
53
+ elements . body . addClass ( 'browser-ipad os-ios' ) ;
54
+ if ( window . navigator . standalone ) {
55
+ elements . body . addClass ( 'ios-webapp' ) ;
51
56
}
52
- if ( o . orientationListen ) {
57
+ if ( o . orientation_listen ) {
53
58
listenToOrientationChange ( ) ;
54
59
}
55
- if ( o . detectWebApp ) {
56
- if ( window . navigator . standalone ) {
57
- elements . body . addClass ( 'ios-webapp' ) ;
58
- }
59
- }
60
60
} else if ( userAgent . match ( / i P h o n e / i) || userAgent . match ( / i P o d / i) ) {
61
- if ( o . addClassToBody ) {
62
- elements . body . addClass ( 'browser-iphone os-ios' ) ;
61
+ elements . body . addClass ( 'browser-iphone os-ios' ) ;
62
+ if ( window . navigator . standalone ) {
63
+ elements . body . addClass ( 'ios-webapp' ) ;
63
64
}
64
- if ( o . orientationListen ) {
65
+ if ( o . orientation_listen ) {
65
66
listenToOrientationChange ( ) ;
66
67
}
67
- if ( o . detectWebApp ) {
68
- if ( window . navigator . standalone ) {
69
- elements . body . addClass ( 'ios-webapp' ) ;
70
- }
71
- }
72
68
} else if ( userAgent . match ( / C h r o m e / i) ) {
73
- if ( o . addClassToBody ) {
74
- elements . body . addClass ( 'browser-chrome' ) ;
75
- }
69
+ elements . body . addClass ( 'browser-chrome' ) ;
76
70
} else if ( userAgent . match ( / S a f a r i / i) ) {
77
- if ( o . addClassToBody ) {
78
- elements . body . addClass ( 'browser-safari' ) ;
79
- }
71
+ elements . body . addClass ( 'browser-safari' ) ;
80
72
}
81
-
73
+
82
74
// ...if browser is NOT webkit, run through the other browsers
83
75
} else {
84
76
if ( browser . msie ) {
85
- if ( o . addClassToBody ) {
86
- elements . body . addClass ( 'browser-ie' ) ;
87
- }
77
+ elements . body . addClass ( 'browser-ie' ) ;
88
78
} else if ( browser . mozilla ) {
89
- if ( o . addClassToBody ) {
90
- elements . body . addClass ( 'browser-firefox' ) ;
91
- }
79
+ elements . body . addClass ( 'browser-firefox' ) ;
92
80
} else if ( browser . opera ) {
93
- if ( o . addClassToBody ) {
94
- elements . body . addClass ( 'browser-opera' ) ;
95
- }
81
+ elements . body . addClass ( 'browser-opera' ) ;
96
82
}
97
83
}
98
84
99
-
100
- // now, detect operating systems
85
+ // detect operating systems
101
86
if ( appVersion . indexOf ( "Mac" ) != - 1 ) {
102
- if ( o . addClassToBody ) {
103
- elements . body . addClass ( 'os-mac' ) ;
104
- }
87
+ elements . body . addClass ( 'os-mac' ) ;
105
88
} else if ( appVersion . indexOf ( "Win" ) != - 1 ) {
106
- if ( o . addClassToBody ) {
107
- elements . body . addClass ( 'os-win' ) ;
108
- }
89
+ elements . body . addClass ( 'os-win' ) ;
109
90
} else if ( appVersion . indexOf ( "X11" ) != - 1 ) {
110
- if ( o . addClassToBody ) {
111
- elements . body . addClass ( 'os-unix' ) ;
112
- }
91
+ elements . body . addClass ( 'os-unix' ) ;
113
92
} else if ( appVersion . indexOf ( "Linux" ) != - 1 ) {
114
- if ( o . addClassToBody ) {
115
- elements . body . addClass ( 'os-linux' ) ;
116
- }
93
+ elements . body . addClass ( 'os-linux' ) ;
117
94
} else {
118
- if ( o . addClassToBody ) {
119
- elements . body . addClass ( 'os-unknown' ) ;
95
+ elements . body . addClass ( 'os-unknown' ) ;
96
+ }
97
+
98
+ // detect touch
99
+ if ( o . detect_touch ) {
100
+ if ( ! ! ( 'ontouchstart' in window ) || ! ! ( 'onmsgesturechange' in window ) ) {
101
+ elements . body . addClass ( 'feature-touch' ) ;
120
102
}
121
103
}
122
-
104
+
105
+
123
106
}
124
-
125
-
126
-
107
+
108
+
127
109
function listenToOrientationChange ( ) {
128
-
110
+
129
111
function changed ( orientation ) {
130
112
if ( orientation === 0 ) {
131
113
elements . body . removeClass ( 'portrait landscape' ) . addClass ( 'portrait' ) ;
@@ -137,20 +119,20 @@ define(['jquery', 'NIseed'], function($) {
137
119
elements . body . removeClass ( 'portrait landscape' ) . addClass ( 'landscape' ) ;
138
120
}
139
121
}
140
-
122
+
141
123
changed ( window . orientation ) ;
142
-
124
+
143
125
window . onorientationchange = function ( ) {
144
126
var orientation = window . orientation ;
145
127
changed ( orientation ) ;
146
128
} ;
147
129
}
148
-
130
+
149
131
init ( ) ;
150
132
}
151
133
152
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
153
-
154
134
NI . BrowserDetection = BrowserDetection ;
155
-
135
+
136
+ return BrowserDetection ;
137
+
156
138
} ) ;
0 commit comments