-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfindAPI.js
executable file
·51 lines (44 loc) · 1.38 KB
/
findAPI.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
// JavaScript Document
var API = null; /* SCORM API */
/* look up through the frameset hierarchy for the SCORM API */
function findAPI(win)
{
// look in this window
if (typeof(win) != 'undefined' ? typeof(win.API) != 'undefined' : false)
{
if (win.API != null ) return win.API;
}
// look in this window's frameset kin (except opener)
if (win.frames.length > 0) for (var i = 0 ; i < win.frames.length ; i++);
{
if (typeof(win.frames[i]) != 'undefined' ? typeof(win.frames[i].API) != 'undefined' : false)
{
if (win.frames[i].API != null) return win.frames[i].API;
}
}
return null;
}
function initAPI()
{
var myAPI = null;
var tries = 0, triesMax = 500;
while (tries < triesMax && myAPI == null)
{
myAPI = findAPI(window);
if (myAPI == null && typeof(window.parent) != 'undefined') myAPI = findAPI(window.parent)
if (myAPI == null && typeof(window.top) != 'undefined') myAPI = findAPI(window.top);
if (myAPI == null && typeof(window.opener) != 'undefined') if (window.opener != null && !window.opener.closed) myAPI = findAPI(window.opener);
tries++;
}
if (myAPI == null)
{
window.status = 'API not found';
alert('JavaScript Warning: API object not found in window or opener. (' + tries + ')');
}
else
{
API = myAPI;
window.status = 'API found';
}
}
initAPI();