1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,117 +0,0 @@ |
1 |
-import { window } from 'ssr-window'; |
|
2 |
-import Support from './support'; |
|
3 |
- |
|
4 |
-const Device = (function Device() { |
|
5 |
- const platform = window.navigator.platform; |
|
6 |
- const ua = window.navigator.userAgent; |
|
7 |
- |
|
8 |
- const device = { |
|
9 |
- ios: false, |
|
10 |
- android: false, |
|
11 |
- androidChrome: false, |
|
12 |
- desktop: false, |
|
13 |
- iphone: false, |
|
14 |
- ipod: false, |
|
15 |
- ipad: false, |
|
16 |
- edge: false, |
|
17 |
- ie: false, |
|
18 |
- firefox: false, |
|
19 |
- macos: false, |
|
20 |
- windows: false, |
|
21 |
- cordova: !!(window.cordova || window.phonegap), |
|
22 |
- phonegap: !!(window.cordova || window.phonegap), |
|
23 |
- electron: false, |
|
24 |
- }; |
|
25 |
- |
|
26 |
- const screenWidth = window.screen.width; |
|
27 |
- const screenHeight = window.screen.height; |
|
28 |
- |
|
29 |
- const android = ua.match(/(Android);?[\s\/]+([\d.]+)?/); // eslint-disable-line |
|
30 |
- let ipad = ua.match(/(iPad).*OS\s([\d_]+)/); |
|
31 |
- const ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/); |
|
32 |
- const iphone = !ipad && ua.match(/(iPhone\sOS|iOS)\s([\d_]+)/); |
|
33 |
- const ie = ua.indexOf('MSIE ') >= 0 || ua.indexOf('Trident/') >= 0; |
|
34 |
- const edge = ua.indexOf('Edge/') >= 0; |
|
35 |
- const firefox = ua.indexOf('Gecko/') >= 0 && ua.indexOf('Firefox/') >= 0; |
|
36 |
- const windows = platform === 'Win32'; |
|
37 |
- const electron = ua.toLowerCase().indexOf('electron') >= 0; |
|
38 |
- let macos = platform === 'MacIntel'; |
|
39 |
- |
|
40 |
- // iPadOs 13 fix |
|
41 |
- if (!ipad |
|
42 |
- && macos |
|
43 |
- && Support.touch |
|
44 |
- && ( |
|
45 |
- (screenWidth === 1024 && screenHeight === 1366) // Pro 12.9 |
|
46 |
- || (screenWidth === 834 && screenHeight === 1194) // Pro 11 |
|
47 |
- || (screenWidth === 834 && screenHeight === 1112) // Pro 10.5 |
|
48 |
- || (screenWidth === 768 && screenHeight === 1024) // other |
|
49 |
- ) |
|
50 |
- ) { |
|
51 |
- ipad = ua.match(/(Version)\/([\d.]+)/); |
|
52 |
- macos = false; |
|
53 |
- } |
|
54 |
- |
|
55 |
- device.ie = ie; |
|
56 |
- device.edge = edge; |
|
57 |
- device.firefox = firefox; |
|
58 |
- |
|
59 |
- // Android |
|
60 |
- if (android && !windows) { |
|
61 |
- device.os = 'android'; |
|
62 |
- device.osVersion = android[2]; |
|
63 |
- device.android = true; |
|
64 |
- device.androidChrome = ua.toLowerCase().indexOf('chrome') >= 0; |
|
65 |
- } |
|
66 |
- if (ipad || iphone || ipod) { |
|
67 |
- device.os = 'ios'; |
|
68 |
- device.ios = true; |
|
69 |
- } |
|
70 |
- // iOS |
|
71 |
- if (iphone && !ipod) { |
|
72 |
- device.osVersion = iphone[2].replace(/_/g, '.'); |
|
73 |
- device.iphone = true; |
|
74 |
- } |
|
75 |
- if (ipad) { |
|
76 |
- device.osVersion = ipad[2].replace(/_/g, '.'); |
|
77 |
- device.ipad = true; |
|
78 |
- } |
|
79 |
- if (ipod) { |
|
80 |
- device.osVersion = ipod[3] ? ipod[3].replace(/_/g, '.') : null; |
|
81 |
- device.ipod = true; |
|
82 |
- } |
|
83 |
- // iOS 8+ changed UA |
|
84 |
- if (device.ios && device.osVersion && ua.indexOf('Version/') >= 0) { |
|
85 |
- if (device.osVersion.split('.')[0] === '10') { |
|
86 |
- device.osVersion = ua.toLowerCase().split('version/')[1].split(' ')[0]; |
|
87 |
- } |
|
88 |
- } |
|
89 |
- |
|
90 |
- // Webview |
|
91 |
- device.webView = !!((iphone || ipad || ipod) && (ua.match(/.*AppleWebKit(?!.*Safari)/i) || window.navigator.standalone)) |
|
92 |
- || (window.matchMedia && window.matchMedia('(display-mode: standalone)').matches); |
|
93 |
- device.webview = device.webView; |
|
94 |
- device.standalone = device.webView; |
|
95 |
- |
|
96 |
- // Desktop |
|
97 |
- device.desktop = !(device.ios || device.android) || electron; |
|
98 |
- if (device.desktop) { |
|
99 |
- device.electron = electron; |
|
100 |
- device.macos = macos; |
|
101 |
- device.windows = windows; |
|
102 |
- if (device.macos) { |
|
103 |
- device.os = 'macos'; |
|
104 |
- } |
|
105 |
- if (device.windows) { |
|
106 |
- device.os = 'windows'; |
|
107 |
- } |
|
108 |
- } |
|
109 |
- |
|
110 |
- // Pixel Ratio |
|
111 |
- device.pixelRatio = window.devicePixelRatio || 1; |
|
112 |
- |
|
113 |
- // Export object |
|
114 |
- return device; |
|
115 |
-}()); |
|
116 |
- |
|
117 |
-export default Device; |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,117 @@ |
1 |
+import { window } from 'ssr-window'; |
|
2 |
+import Support from './support'; |
|
3 |
+ |
|
4 |
+const Device = (function Device() { |
|
5 |
+ const platform = window.navigator.platform; |
|
6 |
+ const ua = window.navigator.userAgent; |
|
7 |
+ |
|
8 |
+ const device = { |
|
9 |
+ ios: false, |
|
10 |
+ android: false, |
|
11 |
+ androidChrome: false, |
|
12 |
+ desktop: false, |
|
13 |
+ iphone: false, |
|
14 |
+ ipod: false, |
|
15 |
+ ipad: false, |
|
16 |
+ edge: false, |
|
17 |
+ ie: false, |
|
18 |
+ firefox: false, |
|
19 |
+ macos: false, |
|
20 |
+ windows: false, |
|
21 |
+ cordova: !!(window.cordova || window.phonegap), |
|
22 |
+ phonegap: !!(window.cordova || window.phonegap), |
|
23 |
+ electron: false, |
|
24 |
+ }; |
|
25 |
+ |
|
26 |
+ const screenWidth = window.screen.width; |
|
27 |
+ const screenHeight = window.screen.height; |
|
28 |
+ |
|
29 |
+ const android = ua.match(/(Android);?[\s\/]+([\d.]+)?/); // eslint-disable-line |
|
30 |
+ let ipad = ua.match(/(iPad).*OS\s([\d_]+)/); |
|
31 |
+ const ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/); |
|
32 |
+ const iphone = !ipad && ua.match(/(iPhone\sOS|iOS)\s([\d_]+)/); |
|
33 |
+ const ie = ua.indexOf('MSIE ') >= 0 || ua.indexOf('Trident/') >= 0; |
|
34 |
+ const edge = ua.indexOf('Edge/') >= 0; |
|
35 |
+ const firefox = ua.indexOf('Gecko/') >= 0 && ua.indexOf('Firefox/') >= 0; |
|
36 |
+ const windows = platform === 'Win32'; |
|
37 |
+ const electron = ua.toLowerCase().indexOf('electron') >= 0; |
|
38 |
+ let macos = platform === 'MacIntel'; |
|
39 |
+ |
|
40 |
+ // iPadOs 13 fix |
|
41 |
+ if (!ipad |
|
42 |
+ && macos |
|
43 |
+ && Support.touch |
|
44 |
+ && ( |
|
45 |
+ (screenWidth === 1024 && screenHeight === 1366) // Pro 12.9 |
|
46 |
+ || (screenWidth === 834 && screenHeight === 1194) // Pro 11 |
|
47 |
+ || (screenWidth === 834 && screenHeight === 1112) // Pro 10.5 |
|
48 |
+ || (screenWidth === 768 && screenHeight === 1024) // other |
|
49 |
+ ) |
|
50 |
+ ) { |
|
51 |
+ ipad = ua.match(/(Version)\/([\d.]+)/); |
|
52 |
+ macos = false; |
|
53 |
+ } |
|
54 |
+ |
|
55 |
+ device.ie = ie; |
|
56 |
+ device.edge = edge; |
|
57 |
+ device.firefox = firefox; |
|
58 |
+ |
|
59 |
+ // Android |
|
60 |
+ if (android && !windows) { |
|
61 |
+ device.os = 'android'; |
|
62 |
+ device.osVersion = android[2]; |
|
63 |
+ device.android = true; |
|
64 |
+ device.androidChrome = ua.toLowerCase().indexOf('chrome') >= 0; |
|
65 |
+ } |
|
66 |
+ if (ipad || iphone || ipod) { |
|
67 |
+ device.os = 'ios'; |
|
68 |
+ device.ios = true; |
|
69 |
+ } |
|
70 |
+ // iOS |
|
71 |
+ if (iphone && !ipod) { |
|
72 |
+ device.osVersion = iphone[2].replace(/_/g, '.'); |
|
73 |
+ device.iphone = true; |
|
74 |
+ } |
|
75 |
+ if (ipad) { |
|
76 |
+ device.osVersion = ipad[2].replace(/_/g, '.'); |
|
77 |
+ device.ipad = true; |
|
78 |
+ } |
|
79 |
+ if (ipod) { |
|
80 |
+ device.osVersion = ipod[3] ? ipod[3].replace(/_/g, '.') : null; |
|
81 |
+ device.ipod = true; |
|
82 |
+ } |
|
83 |
+ // iOS 8+ changed UA |
|
84 |
+ if (device.ios && device.osVersion && ua.indexOf('Version/') >= 0) { |
|
85 |
+ if (device.osVersion.split('.')[0] === '10') { |
|
86 |
+ device.osVersion = ua.toLowerCase().split('version/')[1].split(' ')[0]; |
|
87 |
+ } |
|
88 |
+ } |
|
89 |
+ |
|
90 |
+ // Webview |
|
91 |
+ device.webView = !!((iphone || ipad || ipod) && (ua.match(/.*AppleWebKit(?!.*Safari)/i) || window.navigator.standalone)) |
|
92 |
+ || (window.matchMedia && window.matchMedia('(display-mode: standalone)').matches); |
|
93 |
+ device.webview = device.webView; |
|
94 |
+ device.standalone = device.webView; |
|
95 |
+ |
|
96 |
+ // Desktop |
|
97 |
+ device.desktop = !(device.ios || device.android) || electron; |
|
98 |
+ if (device.desktop) { |
|
99 |
+ device.electron = electron; |
|
100 |
+ device.macos = macos; |
|
101 |
+ device.windows = windows; |
|
102 |
+ if (device.macos) { |
|
103 |
+ device.os = 'macos'; |
|
104 |
+ } |
|
105 |
+ if (device.windows) { |
|
106 |
+ device.os = 'windows'; |
|
107 |
+ } |
|
108 |
+ } |
|
109 |
+ |
|
110 |
+ // Pixel Ratio |
|
111 |
+ device.pixelRatio = window.devicePixelRatio || 1; |
|
112 |
+ |
|
113 |
+ // Export object |
|
114 |
+ return device; |
|
115 |
+}()); |
|
116 |
+ |
|
117 |
+export default Device; |