forked from requirejs/requirejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathafterload.html
More file actions
96 lines (87 loc) · 2.98 KB
/
afterload.html
File metadata and controls
96 lines (87 loc) · 2.98 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!DOCTYPE html>
<html>
<head>
<title>require.js: After Load</title>
<script type="text/javascript" src="doh/runner.js"></script>
<script type="text/javascript" src="doh/_browserRunner.js"></script>
<script type="text/javascript">
var d, s, head;
function goRequire() {
//Need a hack to trigger require.pageLoaded() for pre Firefox 3.6 browsers.
var ff = parseFloat(navigator.userAgent.split("Firefox/")[1]) || null;
if (ff && ff < 3.6) {
require.pageLoaded();
}
require({
paths: {
domReady: "../domReady"
}
},
["require", "simple", "domReady"],
function (require, simple, domReady) {
domReady(function() {
doh.is("blue", simple.color);
//Now test another script getting loaded will see
//document.readyState === "complete".
var s = document.createElement("script");
s.src = "afterloadreadystate.js";
s.charset = "utf-8";
head.appendChild(s);
});
}
);
}
function loadRequire() {
var readyRegExp = /complete|loaded/;
function onScriptLoad(evt) {
var node = evt.target || evt.srcElement;
if (evt.type === "load" || readyRegExp.test(node.readyState)) {
//Clean up script binding, otherwise, Opera in particular
//may trigger it again.
if (node.removeEventListener) {
node.removeEventListener("load", onScriptLoad, false);
} else {
//Probably IE.
node.detachEvent("onreadystatechange", onScriptLoad);
}
goRequire();
}
};
//Create script tag for require.js
s = document.createElement("script");
s.src = "../require.js";
s.charset = "utf-8";
//Set up load listener.
if (s.addEventListener) {
s.addEventListener("load", onScriptLoad, false);
} else {
//Probably IE.
s.attachEvent("onreadystatechange", onScriptLoad);
}
head = (document.getElementsByTagName("head")[0] ||
document.getElementsByTagName("html")[0]);
head.appendChild(s);
}
doh.register(
"afterload",
[
{
name: "afterload",
timeout: 5000,
runTest: function() {
d = new doh.Deferred();
return d;
}
}
]
);
doh.run();
</script>
</head>
<body onload="loadRequire()">
<h1>require.js: After Load Test</h1>
<p>Tests adding require after the page loads, and tests that require.js patches
up document.readyState for Firefox less than 3.6.</p>
<p>Check console for messages</p>
</body>
</html>