-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscorm.js
67 lines (64 loc) · 1.9 KB
/
scorm.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
62
63
64
65
66
67
(function ()
{
function findAPI(win)
{
var depth = 0,
depthLimit = 500;
while ((!win.API) && (!win.API_1484_11) && win.parent && (win.parent != win) && (depth <= depthLimit))
{
depth++;
win = win.parent;
}
return win.API_1484_11 || win.API || null;
}
function getAPI(win)
{
var API = findAPI(win);
if(!API && win.parent && (win.parent != win))
API = findAPI(win.parent);
if (!API && win.top && win.top.opener)
API = findAPI(win.top.opener);
if (!API && win.top && win.top.opener && win.top.opener.document)
API = findAPI(win.top.opener.document);
return API;
}
function getCall(lms, name)
{
if (lms && lms[name])
return lms[name].bind(lms);
return function() {};
}
function initAPI()
{
var SCORM = {
initialize: getCall(api, 'LMSInitialize'),
getValue: getCall(api, 'LMSGetValue'),
setValue: getCall(api, 'LMSSetValue'),
commit: getCall(api, 'LMSCommit'),
terminate: getCall(api, 'LMSFinish'),
setLessonComplete: function(score)
{
this.setValue('cmi.core.score.raw', score === undefined? 100 : score);
this.setValue('cmi.core.lesson_status', 'completed');
this.commit('');
}
};
SCORM.initialize('');
window.addEventListener('unload', function()
{
SCORM.terminate('');
});
window.SCORM = SCORM;
}
function tryGetAPI()
{
api = getAPI(window);
if(api)
initAPI();
else if(--maxTries > 0)
setTimeout(tryGetAPI, 1000);
}
var api = null;
var maxTries = 10;
tryGetAPI();
})();