-
Notifications
You must be signed in to change notification settings - Fork 3
/
common.js
47 lines (42 loc) · 1.28 KB
/
common.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
//Common functions for the test files. *MUST* be included after require.js.
(function() {
var messages = [];
var bodyReady = false;
window.log = function(message) {
if (typeof console != "undefined" && console.log) {
console.log(message);
} else {
messages.push(message);
if (bodyReady) {
dumpLogs();
}
}
}
function dumpLogs() {
bodyReady = true;
if (messages.length) {
var body = document.getElementsByTagName("body")[0];
if (body) {
for (var i = 0; i < messages.length; i++) {
var div = document.createElement("div");
div.innerHTML = messages[i];
body.appendChild(div);
}
}
messages =[];
}
}
//Wait for document ready before dumping results.
//Will not work with Firefox 3.5 or earlier, but just
//be sure to use Firebug or something that defines console.log
var tries = 0;
function checkDom() {
if (document.readyState === "complete") {
dumpLogs();
} else if (tries < 5) {
tries += 1;
setTimeout(checkDom, 1000);
}
}
checkDom();
})();