forked from joseph/Monocle
/
test.js
75 lines (62 loc) · 1.84 KB
/
test.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
Monocle.DEBUG = true;
(function () {
function readUA() {
testResult("userAgent", navigator.userAgent);
}
function readBrowser() {
var res = [];
for (var prop in Monocle.Browser.is) {
var val = Monocle.Browser.is[prop];
if (val) { res.push("is."+prop); }
}
for (var prop in Monocle.Browser.on) {
var val = Monocle.Browser.on[prop];
if (val) { res.push("on."+prop); }
}
testResult(
"Browser",
"engine: "+Monocle.Browser.engine+". "+res.join(", ")+"."
);
}
function testResult(name, val) {
var tbl = document.getElementById('results');
var row = document.createElement('tr');
var nCell = document.createElement('td');
var vCell = document.createElement('td');
var nCellText = document.createTextNode(name);
var vCellText = document.createTextNode(val);
nCell.appendChild(nCellText);
vCell.appendChild(vCellText);
vCell.style.color = colorForTestResult(name, val);
row.appendChild(nCell);
row.appendChild(vCell);
tbl.appendChild(row);
}
function colorForTestResult(name, val) {
var neutralNames = ["userAgent", "Browser", "touch", "embedded"];
try {
if (neutralNames.indexOf(name) >= 0) {
return "black";
}
} catch (e) {}
if (name.match(/^supports/)) {
return val ? "green" : "red";
}
return val ? "orange": "green";
}
function assertCompatibility(env) {
var div = document.getElementById('compatibility');
div.style.display = 'block';
var x = env.isCompatible() ? "compatible" : "incompatible";
div.innerHTML = "This browser is "+x+" with Monocle.";
div.className = x;
}
function init() {
readUA();
readBrowser();
env = new Monocle.Env();
env.properties.resultCallback = testResult;
env.survey(assertCompatibility);
}
window.onload = init;
})();