-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscorm_api.js
61 lines (54 loc) · 1.74 KB
/
scorm_api.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
var findAPITries = 0;
function findAPI(win)
{
// Check to see if the window (win) contains the API
// if the window (win) does not contain the API and
// the window (win) has a parent window and the parent window
// is not the same as the window (win)
while ( (win.API == null) && (win.parent != null) && (win.parent != win) )
{
// increment the number of findAPITries
findAPITries++;
// Note: 7 is an arbitrary number, but should be more than sufficient
if (findAPITries > 7)
{
alert("Error finding API -- too deeply nested.");
return null;
}
// set the variable that represents the window being
// being searched to be the parent of the current window
// then search for the API again
win = win.parent;
}
return win.API;
}
function getAPI()
{
// start by looking for the API in the current window
var theAPI = findAPI(window);
// if the API is null (could not be found in the current window)
// and the current window has an opener window
if ( (theAPI == null) && (window.opener != null) && (typeof(window.opener) != "undefined") )
{
// try to find the API in the current window's opener
theAPI = findAPI(window.opener);
}
// if the API has not been found
if (theAPI == null)
{
// Alert the user that the API Adapter could not be found
alert("Unable to find an API adapter");
}
return theAPI;
}
function loadAPI(){
API = getAPI();
API.LMSInitialize("");
}
function instantFail(API){
API.LMSSetValue("cmi.core.lesson_status","failed");
// API.LMSSetValue("cmi.core.lesson_status","completed");
API.LMSSetValue("cmi.core.score.raw","69");
alert("You failed!!!! Congrats!!!");
API.LMSFinish("");
}