This repository was archived by the owner on Sep 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathcalibrate.ts
More file actions
73 lines (61 loc) · 2.21 KB
/
Copy pathcalibrate.ts
File metadata and controls
73 lines (61 loc) · 2.21 KB
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
(function(window) {
'use strict';
// HACK: ie8 does not need to reset the body border,
// while any other browser does.
// This hack is obsolete in standards mode, but
// calibration script is executed on about:blank
// which is in quirks mode.
// Needs to find a proper way to open calibration
// page in standards mode.
function needsResetBorder() {
return !/MSIE 8\.0/.test(navigator.userAgent);
}
function resetZoom() {
var meta = document.createElement('meta');
meta.name = 'viewport';
meta.content = 'width=device-width,initial-scale=1.0,user-scalable=no';
document.getElementsByTagName('head')[0].appendChild(meta);
}
function createPattern() {
var bodyStyle = document.body.style;
bodyStyle.margin = 0;
bodyStyle.padding = 0;
if (needsResetBorder()) {
bodyStyle.border = 0;
}
bodyStyle.backgroundColor = '#96fa00';
}
function hasCSS3Selectors() {
try {
document.querySelector('body:nth-child(1)');
} catch (e) {
return false;
}
return true;
}
function needsCompatLib() {
return !hasCSS3Selectors() ||
!window.getComputedStyle ||
!window.matchMedia ||
!String.prototype.trim;
}
// In safari `window.innerWidth` always returns default 980px and and even viewport meta tag setting does not change it.
// https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/UsingtheViewport/UsingtheViewport.html
function getInnerWidth() {
var isSafari = /Safari/.test(navigator.userAgent);
return isSafari
? document.documentElement.clientWidth || document.body.clientWidth
: window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
}
function getBrowserFeatures() {
var features = {
needsCompatLib: needsCompatLib(),
pixelRatio: window.devicePixelRatio,
innerWidth: getInnerWidth()
};
return features;
}
resetZoom();
createPattern();
return getBrowserFeatures();
}(window));