4
<title>Script Load Interactive Test</title>
5
<script src="../common.js"></script>
7
/*jslint plusplus: false, strict: false */
8
/*global log: false, dumpLogs: false */
10
var noCache = location.href.indexOf("nocache") !== -1;
12
log("noCache: " + noCache);
14
var readyRegExp = /complete|loaded/,
15
useInteractive = false,
18
currentlyAddingScript,
19
waitingFunc, loadUrls,
34
for (i = 0; i < loadedScripts.length; i++) {
35
module = loadedScripts[i];
36
log("module " + module.name + " === " + module.obj.name);
40
if (callCount === 1) {
41
log("-------Trying cache hits now--------");
43
setTimeout(loadUrls, 500);
47
function finishScript(script, func) {
53
name: script.getAttribute('data-name').replace(/\.js$/, ''),
57
if (loadedScripts.length === 9) {
62
function onTestScriptLoad(evt) {
63
var node = evt.target || evt.srcElement;
64
if (evt.type === "load" || readyRegExp.test(node.readyState)) {
65
if (!useInteractive) {
66
finishScript(node, waitingFunc);
70
if (node.removeEventListener) {
71
node.removeEventListener("load", onTestScriptLoad, false);
74
node.detachEvent("onreadystatechange", onTestScriptLoad);
78
function attachScript(url, name, useDocWrite) {
80
url += "?stamp=" + (new Date()).getTime();
82
var node = document.createElement("script");
84
node.type = "text/javascript";
85
node.charset = "utf-8";
86
node.setAttribute("data-name", name);
88
//Set up load listener.
89
if (node.addEventListener) {
90
node.addEventListener("load", onTestScriptLoad, false);
93
useInteractive = true;
94
node.attachEvent("onreadystatechange", onTestScriptLoad);
96
currentlyAddingScript = node;
98
document.getElementsByTagName("head")[0].appendChild(node);
99
currentlyAddingScript = null;
102
loadUrls = function () {
103
for (var i = 0, url; (url = urls[i]); i++) {
104
attachScript(url, url);
109
var scripts, i, script = currentlyAddingScript;
110
if (useInteractive) {
111
scripts = document.getElementsByTagName('script');
113
for (i = scripts.length - 1; i > -1; i--) {
114
states.push(i + scripts[i].readyState + scripts[i].src);
115
//log('script with name ' + scripts[i].getAttribute('data-name') + ' has readyState = ' + scripts[i].readyState + ' for func: ' + func);
116
if (scripts[i].readyState === 'interactive') {
122
log("ERROR: No matching script interactive for " + func);
123
log("script readyStates are: " + states);
125
//log('calling finishScript for interactive dat-name: ' + script.getAttribute('data-name'));
126
finishScript(script, func);
138
<h1>Script Load Interactive Test</h1>
140
<p>This test checks to see if a function call can be associated with a specific script tag.</p>
141
<p>For non-IE 6-8 browsers, the script onload event may not fire right after the the script
142
is evaluated. Kris Zyp found for IE though that in a function call that is called while the
143
script is executed, it could query the script nodes and the one that is in "interactive" mode
144
indicates the current script.</p>
145
<p>So this test tries to see to use interactive state if possible, and if that does not work,
146
falls back to using script onload to associate the scripts.</p>
147
<p>Check the console for output. Expected result, all scripts are matched up with their calls.</p>