-
Notifications
You must be signed in to change notification settings - Fork 913
/
site.js
98 lines (95 loc) · 3.64 KB
/
site.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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
(function () {
'use strict';
window.site = {
getPlatform: function (ua, pf) {
// Firefox OS navigator.platform is an empty string, which equates to a falsey value in JS
// Ths means we must use an ugly ternary statement here to make testing easier.
pf = (pf === '') ? '' : pf || navigator.platform;
ua = ua || navigator.userAgent;
if (/Win(16|9[x58]|NT( [1234]| 5\.0| [^0-9]|[^ -]|$))/.test(ua) ||
/Windows ([MC]E|9[x58]|3\.1|4\.10|NT( [1234]| 5\.0| [^0-9]|[^ ]|$))/.test(ua) ||
/Windows_95/.test(ua)) {
/**
* Officially unsupported platforms are Windows 95, 98, ME, NT 4.x, 2000
* These regular expressions match:
* - Win16
* - Win9x
* - Win95
* - Win98
* - WinNT (not followed by version or followed by version <= 5)
* - Windows ME
* - Windows CE
* - Windows 9x
* - Windows 95
* - Windows 98
* - Windows 3.1
* - Windows 4.10
* - Windows NT (not followed by version or followed by version <= 5)
* - Windows_95
*/
return 'oldwin';
}
if (ua.indexOf("MSIE 6.0") !== -1 &&
ua.indexOf("Windows NT 5.1") !== -1 &&
ua.indexOf("SV1") === -1) {
// Windows XP SP1
return 'oldwin';
}
if (pf.indexOf("Win32") !== -1 ||
pf.indexOf("Win64") !== -1) {
return 'windows';
}
if (/android/i.test(ua)) {
return 'android';
}
if (/armv[6-7]l/.test(pf)) {
return 'android';
}
if (pf.indexOf("Linux") !== -1) {
return 'linux';
}
if (pf.indexOf("MacPPC") !== -1) {
return 'oldmac';
}
if (/Mac OS X 10.[0-5]/.test(ua)) {
return 'oldmac';
}
if (pf.indexOf('iPhone') !== -1 ||
pf.indexOf('iPad') !== -1 ||
pf.indexOf('iPod') !== -1 ) {
return 'ios';
}
if (ua.indexOf("Mac OS X") !== -1) {
return 'osx';
}
if (ua.indexOf("MSIE 5.2") !== -1) {
return 'oldmac';
}
if (pf.indexOf("Mac") !== -1) {
return 'oldmac';
}
if (pf === '' &&
/Firefox/.test(ua) &&
/Mobile|Tablet/.test(ua) &&
!(/Android/.test(ua))) {
return 'fxos';
}
return 'other';
},
platform: 'other'
};
(function () {
// if other than 'windows', immediately replace the platform classname on the html-element
// to avoid lots of flickering
var h = document.documentElement;
window.site.platform = window.site.getPlatform();
if (window.site.platform !== 'windows') {
h.className = h.className.replace("windows", window.site.platform);
}
// Add class to reflect javascript availability for CSS
h.className = h.className.replace(/\bno-js\b/, 'js');
})();
})();