-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
87 lines (66 loc) · 2.27 KB
/
index.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
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function () {
if (typeof window === 'undefined') {
return;
}
var ua = navigator.userAgent.toLowerCase().replace(/trident.* rv/, 'msie');
var mobileDevice = (/ip(?:hone|ad|od)|android|blackberry|windows phone/.exec(ua) + '').replace(/ /g, '-') || 'other';
var browser = {
browser: /msie|firefox|opera|chrome|safari/.exec(ua) || 'other',
version: (/(version|chrome|firefox|msie)[\/ :]([\d.]+)/.exec(ua) || [])[2] || '0',
mobile: /mobile/.test(ua)
};
browser[browser.browser] = true;
if (/webkit/.test(ua)) {
browser.webkit = true;
}
// determine mobile in 'desktop' mode
if (!browser.mobile && 'matchMedia' in window && ('DeviceOrientationEvent' in window || 'orientation' in window) && window.matchMedia('only screen and (min-device-width : 320px) and (max-device-width : 667px)').matches) {
browser.mobile = true;
}
if (browser.mobile) {
browser.device = mobileDevice;
if (browser.device === 'other' && /linux/.test(ua)) {
browser.device = 'android';
}
if (browser.device === 'other' && /macintosh|mac os/.test(ua)) {
browser.device = 'iphone';
}
if (browser.device === 'ipad' || browser.device === 'android' && Math.min(screen.width, screen.height) > 600) {
browser.tablet = true;
}
browser[browser.device] = true;
if (!browser.tablet && (browser.iphone || browser.ipod || browser.android || browser['windows-phone'])) {
browser.phone = true;
}
}
// is weak browser, flag for turn off some ftrs
if (browser.msie && browser.version < 10 || browser.mobile || !(window.history && history.pushState)) {
browser.isWeak = true;
}
var classList = [browser.browser, browser.browser + '_' + browser.version];
browser.version.split('.').reduce(function (res, num) {
classList.push(browser.browser + '_' + res);
return res + '.' + num;
});
if (browser.webkit) {
classList.push('webkit');
}
if (browser.mobile) {
classList.push('mobile');
classList.push('mobile-' + browser.device);
if (browser.tablet) {
classList.push('tablet');
}
} else {
classList.push('desktop');
}
var html = document.getElementsByTagName('html')[0];
classList.forEach(function (className) {
return html.classList.add(className);
});
return browser;
}();