|
var SCORM_API = null, |
|
foundAPI = false, |
|
g_bFinishDone = false; |
|
|
|
/* ------------------------------------------------------------------------- |
|
findAPI(window) |
|
Adapted from pipwerks SCORM wrapper |
|
https://github.com/pipwerks/scorm-api-wrapper |
|
|
|
Looks for an object named API in parent and opener windows |
|
|
|
Parameters: window (the browser window object). |
|
Returns: Object if API is found, null if no API found |
|
---------------------------------------------------------------------------- */ |
|
|
|
var findAPI = function(win){ |
|
|
|
var API, |
|
findAttempts = 0, |
|
findAttemptLimit = 500; |
|
|
|
while (!win.API_1484_11 && win.parent && win.parent != win && findAttempts <= findAttemptLimit){ |
|
findAttempts++; |
|
win = win.parent; |
|
} |
|
|
|
API = win.API_1484_11 || null; |
|
|
|
/* |
|
if(!API){ |
|
alert("Error finding API. \nFind attempts: " +findAttempts +". \nFind attempt limit: " +findAttemptLimit); |
|
} |
|
*/ |
|
|
|
return API; |
|
|
|
}; |
|
|
|
|
|
/* ------------------------------------------------------------------------- |
|
getAPI() |
|
Adapted from pipwerks SCORM wrapper |
|
https://github.com/pipwerks/scorm-api-wrapper |
|
|
|
Looks for an object named API_1484_11, first in the current window's frame |
|
hierarchy and then, if necessary, in the current window's opener window |
|
hierarchy (if there is an opener window). |
|
|
|
Parameters: None. |
|
Returns: Object if API found, null if no API found |
|
---------------------------------------------------------------------------- */ |
|
|
|
var getAPI = function(){ |
|
|
|
var API = null, |
|
win = window; |
|
|
|
//Look in parent windows first |
|
if(win.parent && win.parent != win){ |
|
API = findAPI(win.parent); |
|
} |
|
|
|
//Look in opener windows next |
|
if(!API && win.top.opener){ |
|
API = findAPI(win.top.opener); |
|
} |
|
|
|
//Plateau LMS needs special hand-holding |
|
if(!API && win.top.opener && win.top.opener.document) { |
|
API = findAPI(win.top.opener.document); |
|
} |
|
|
|
//if(!API){ alert("getAPI failed: Can't find the API!"); } |
|
|
|
return API; |
|
|
|
}; |
|
|
|
|
|
//Quick way to check if SCORM API is available and communicative |
|
function SCORM_API_Available() { |
|
return (SCORM_API && SCORM_API.GetLastError && typeof SCORM_API.GetLastError() !== "undefined"); |
|
} |
|
|
|
|
|
function Finish(){ |
|
|
|
if(SCORM_API_Available() && g_bFinishDone == false){ |
|
SCORM_API.Commit(""); |
|
g_bFinishDone = (SCORM_API.Terminate("") === "true"); |
|
} |
|
return g_bFinishDone + ""; // Force type to string |
|
|
|
} |
|
|
|
|
|
function Captivate_DoExternalInterface(command, parameter, value, variable){ |
|
|
|
var strErr = "true"; |
|
|
|
//Ensure SCORM API is still available |
|
if(!SCORM_API_Available()){ return; } |
|
|
|
if(command === "Initialize"){ |
|
|
|
CaptivateSWF.SetScormVariable(variable, SCORM_API.Initialize("")); |
|
|
|
if(SCORM_API.GetValue("cmi.completion_status") == "not attempted"){ |
|
SCORM_API.SetValue("cmi.completion_status", "incomplete"); |
|
} |
|
|
|
} else if(command === "SetValue"){ |
|
|
|
strErr = SCORM_API.SetValue(parameter, value); |
|
CaptivateSWF.SetScormVariable(variable, strErr); |
|
|
|
} else if(command === "Terminate"){ |
|
|
|
g_bFinishDone = SCORM_API.Terminate(""); |
|
strErr = g_bFinishDone; |
|
CaptivateSWF.SetScormVariable(variable, g_bFinishDone); |
|
|
|
} else if(command === "Commit"){ |
|
|
|
strErr = SCORM_API.Commit(""); |
|
CaptivateSWF.SetScormVariable(variable, strErr); |
|
|
|
} else if((value) && (value.length > 0)){ |
|
|
|
if(command === "GetLastError"){ |
|
|
|
strErr = SCORM_API.GetLastError(); |
|
CaptivateSWF.SetScormVariable(variable, strErr); |
|
|
|
} else { |
|
|
|
strErr = SCORM_API[command](parameter); |
|
CaptivateSWF.SetScormVariable(variable, strErr); |
|
|
|
} |
|
|
|
} |
|
|
|
return strErr; |
|
|
|
} |
|
|
|
window.onunload = Finish; |