-
Notifications
You must be signed in to change notification settings - Fork 5
/
jquery.ua.js
170 lines (161 loc) · 7.4 KB
/
jquery.ua.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*!
* jQuery UA plugin v0.13.0
* https://github.com/terkel/jquery-ua
*
* Copyright (c) Takeru Suzuki - http://terkel.jp/
* Licensed under the MIT license - http://www.opensource.org/licenses/MIT
*/
(function ($) {
var p, b, e;
$.ua = $.ua || {
init: function () {
p = this.platform = this.detect(this.data.platforms);
b = this.browser = this.detect(this.data.browsers);
e = this.engine = this.detect(this.data.engines);
},
detect: function (data) {
var ua = navigator.userAgent.toLowerCase(),
item = {},
name,
versionSearch,
flags,
versionNames,
i,
is,
ic,
j,
js,
jc;
for (i = 0, is = data.length; i < is; i++) {
ic = data[i];
name = ic.name;
versionSearch = ic.versionSearch;
flags = ic.flags;
versionNames = ic.versionNames;
if (ua.indexOf(name) !== -1) {
item.name = name.replace(/\s/g, '');
item[item.name] = true;
item.version = ('' + (new RegExp(versionSearch + '(\\d+((\\.|_)\\d+)*)').exec(ua) || [, 0])[1]).replace(/_/g, '.');
item.versionMajor = parseInt(item.version, 10);
if (flags) {
for (j = 0, js = flags.length; j < js; j++) {
item[flags[j]] = true;
}
}
if (versionNames) {
for (j = 0, js = versionNames.length; j < js; j++) {
jc = versionNames[j];
if (item.version.indexOf(jc.number) === 0) {
item.versionName = jc.name;
item[item.versionName] = true;
break;
}
}
}
if (data === $.ua.data.platforms) {
item.mobile = /mobile|phone/.test(ua) || item.blackberry;
item.tablet = /tablet/.test(ua) || item.ipad || (item.android && !/mobile/.test(ua));
if (item.ios) {
item.versionName = 'ios' + item.versionMajor;
}
}
break;
}
}
if (!item.name) {
item['unknown'] = true;
item.name = '';
item.version = '';
item.versionMajor = '';
}
return item;
},
data: {
platforms: [
{ name: 'windows phone', versionSearch: 'windows phone os ', versionNames: [ // windows phone must be tested before win
{ number: '8.1', name: 'blue' },
{ number: '8', name: 'apollo' },
{ number: '7.8', name: 'mango' },
{ number: '7.5', name: 'mango' },
{ number: '7', name: 'photon' }
]},
{ name: 'win', versionSearch: 'windows(?: nt)? ', versionNames: [
{ number: '10.0', name: 'win10' }, // Windows 10 Final Release
{ number: '6.4', name: 'win10 TechnicalPreview' }, // Windows 10 Preview Release
{ number: '6.3', name: 'win81' },
{ number: '6.2', name: 'win8' },
{ number: '6.1', name: 'win7' },
{ number: '6.0', name: 'winvista' },
{ number: '5.2', name: 'winxp' },
{ number: '5.1', name: 'winxp' },
{ number: '5.0', name: 'win2000' }
]},
{ name: 'ipad', versionSearch: 'cpu os ', flags: ['ios'] }, // ipad and ipod must be tested before iphone
{ name: 'ipod', versionSearch: 'iphone os ', flags: ['ios'] },
{ name: 'iphone', versionSearch: 'iphone os ', flags: ['ios'] }, // iphone must be tested before mac
{ name: 'mac', versionSearch: 'os x ', versionNames: [
{ number: '10.15', name: 'catalina' },
{ number: '10.14', name: 'mojave' },
{ number: '10.13', name: 'highsierra' },
{ number: '10.12', name: 'sierra' },
{ number: '10.11', name: 'elcapitan' },
{ number: '10.10', name: 'yosemite' },
{ number: '10.9', name: 'mavericks' },
{ number: '10.8', name: 'mountainlion' },
{ number: '10.7', name: 'lion' },
{ number: '10.6', name: 'snowleopard' },
{ number: '10.5', name: 'leopard' },
{ number: '10.4', name: 'tiger' },
{ number: '10.3', name: 'panther' },
{ number: '10.2', name: 'jaguar' },
{ number: '10.1', name: 'puma' },
{ number: '10.0', name: 'cheetah' }
]},
{ name: 'android', versionSearch: 'android ', versionNames: [ // android must be tested before linux
{ number: '10.', name: '10' },
{ number: '9.', name: 'pie' },
{ number: '8.', name: 'oreo' },
{ number: '7.', name: 'nougat' },
{ number: '6.', name: 'marshmallow' },
{ number: '5.', name: 'lollipop' },
{ number: '4.4', name: 'kitkat' },
{ number: '4.3', name: 'jellybean' },
{ number: '4.2', name: 'jellybean' },
{ number: '4.1', name: 'jellybean' },
{ number: '4.0', name: 'icecreamsandwich' },
{ number: '3.', name: 'honeycomb' },
{ number: '2.3', name: 'gingerbread' },
{ number: '2.2', name: 'froyo' },
{ number: '2.', name: 'eclair' },
{ number: '1.6', name: 'donut' },
{ number: '1.5', name: 'cupcake' }
]},
{ name: 'blackberry', versionSearch: '(?:blackberry\\d{4}[a-z]?|version)/' },
{ name: 'linux' }
],
browsers: [
{ name: 'iemobile', versionSearch: 'iemobile/' }, // iemobile must be tested before msie
{ name: 'msie', versionSearch: 'msie ' },
{ name: 'firefox', versionSearch: 'firefox/' },
{ name: 'chrome', versionSearch: 'chrome/' }, // chrome must be tested before safari
{ name: 'safari', versionSearch: 'version/' },
{ name: 'opera', versionSearch: 'version/' }
],
engines: [
{ name: 'trident', versionSearch: 'trident/' },
{ name: 'webkit', versionSearch: 'webkit/' }, // webkit must be tested before gecko
{ name: 'gecko', versionSearch: 'rv:' },
{ name: 'presto', versionSearch: 'presto/' }
]
}
};
$.ua.init();
$('html').addClass([
p.name,
p.versionName,
b.name,
b.name + b.versionMajor,
e.name,
e.name + e.versionMajor
].join(' '));
})(jQuery);