Skip to content

@pipwerks /captivate.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Captivate SCORM 2004 Output, removed eval
// set document.domain property here, if it works for your environment/SCORM implementation
// document.domain="";
var flashvars = {},
params = { bgcolor: "#f5f4f1", menu: "false" },
attributes = { id: "Captivate", name: "Captivate" },
g_intAPIType = 0,
strURLFile = "sample.swf", // Name of the flash file
intIntervalSecs = 1, // Number of seconds to wait for SCORM API to load
g_intAPIOrder = 0, // Way to search for API object (0 - starts with bottom up; 1 - starts top down)
strURLParams = "";
timeCurrent_int = new Date().getTime(),
timeLimit_int = new Date().getTime() + (intIntervalSecs * 1000),
function callbackFn(e){
//e.ref is the <object> aka SWF file. No need for getElementById
if(e.success && e.ref){
e.ref.tabIndex = -1; //Set tabIndex to enable focus on non-form elements
e.ref.focus();
}
}
function Finish(){
if(isAPI() && g_bFinishDone == false){
if(g_zAPIVersion == "0.2"){
g_objAPI.LMSCommit("");
} else {
g_objAPI.Commit(""));
}
g_bFinishDone = (g_zAPIVersion == "0.2") ? g_objAPI.LMSFinish("") == "true" : g_objAPI.Terminate("") == "true";
}
return g_bFinishDone + ""; // Force type to string
}
// Handle fscommand messages from a Flash movie
function Captivate_DoFSCommand(command, args){
var CaptivateObj = document.getElementById("Captivate"),
strFSArgs = new String(args),
strFSCmd = new String(command),
strErr = "true",
strFSArg1,
strFSArg2,
strFSArg3,
intFSDelimiter = strFSArgs.indexOf("|"),
strFSTemp;
if(intFSDelimiter > -1){
strFSArg1 = strFSArgs.substr(0, intFSDelimiter); // Name of data element to get from API
strFSTemp = strFSArgs.substr(intFSDelimiter + 1);
intFSDelimiter = strFSTemp.indexOf("|");
if(intFSDelimiter > -1){
strFSArg2 = strFSTemp.substr(0, intFSDelimiter); // Value
strFSArg3 = strFSTemp.substr(intFSDelimiter + 1); // Variable
} else {
strFSArg2 = strFSTemp;
}
} else {
strFSArg1 = strFSArgs;
}
// do nothing, if SCORM API is not available
if(!isAPI()){ return; }
if(strFSCmd == "LMSInitialize" || strFSCmd == "Initialize"){
CaptivateObj.SetVariable(strFSArg3, g_objAPI[strFSCmd](""));
} else if(strFSCmd == "LMSSetValue" || strFSCmd == "SetValue"){
strErr = g_objAPI[strFSCmd](strFSArg1, strFSArg2);
CaptivateObj.SetVariable(strFSArg3, strErr);
} else if(strFSCmd == "LMSFinish" || strFSCmd == "Terminate"){
g_bFinishDone = g_objAPI[strFSCmd]("");
strErr = g_bFinishDone;
CaptivateObj.SetVariable(strFSArg3, g_bFinishDone);
} else if(strFSCmd == "LMSCommit" || strFSCmd == "Commit"){
strErr = g_objAPI[strFSCmd]("");
CaptivateObj.SetVariable(strFSArg3, strErr);
} else if((strFSArg2) && (strFSArg2.length > 0)){
if(strFSCmd == "LMSGetLastError" || strFSCmd == "GetLastError"){
strErr = g_objAPI[strFSCmd]();
CaptivateObj.SetVariable(strFSArg3, strErr);
} else {
strErr = g_objAPI[strFSCmd](strFSArg1);
CaptivateObj.SetVariable(strFSArg3, strErr);
}
} else if(strFSCmd.substring(0,3) == "LMSGet"){
strErr = "-2: No Flash variable specified";
}
return strErr;
}
function Captivate_DoExternalInterface(command, parameter, value, variable){
var CaptivateObj = document.getElementById("Captivate"),
strFSCmd = new String(command),
strErr = "true",
strFSArg1 = parameter,
strFSArg2 = value,
strFSArg3 = variable,
courseStatus;
// do nothing, if SCORM API is not available
if(!isAPI()){ return; }
if(strFSCmd == "LMSInitialize" || strFSCmd == "Initialize"){
CaptivateObj.SetScormVariable(strFSArg3, g_objAPI[strFSCmd](""));
courseStatus = g_objAPI.GetValue("cmi.completion_status");
if(courseStatus == "not attempted"){
g_objAPI.SetValue("cmi.completion_status", "incomplete");
}
} else if(strFSCmd == "LMSSetValue" || strFSCmd == "SetValue"){
strErr = g_objAPI[strFSCmd](strFSArg1, strFSArg2);
CaptivateObj.SetScormVariable(strFSArg3, strErr);
} else if(strFSCmd == "LMSFinish" || strFSCmd == "Terminate"){
g_bFinishDone = g_objAPI[strFSCmd]("");
strErr = g_bFinishDone;
CaptivateObj.SetScormVariable(strFSArg3, g_bFinishDone);
} else if(strFSCmd == "LMSCommit" || strFSCmd == "Commit"){
strErr = g_objAPI[strFSCmd]("");
CaptivateObj.SetScormVariable(strFSArg3, strErr);
} else if((strFSArg2) && (strFSArg2.length > 0)){
if(strFSCmd == "LMSGetLastError" || strFSCmd == "GetLastError"){
strErr = g_objAPI[strFSCmd]();
CaptivateObj.SetScormVariable(strFSArg3, strErr);
} else {
strErr = g_objAPI[strFSCmd](strFSArg1);
CaptivateObj.SetScormVariable(strFSArg3, strErr);
}
} else if(strFSCmd.substring(0,3) == "LMSGet"){
strErr = "-2: No Flash variable specified";
}
return strErr;
}
// Hook for Internet Explorer
if(swfobject.ua.ie || g_intAPIType == -1){
g_intAPIType = 0;
document.write("<script language=\"VBScript\"\>\n");
document.write("On Error Resume Next\n");
document.write("Sub Captivate_FSCommand(ByVal command, ByVal args)\n");
document.write("Call Captivate_DoFSCommand(command, args)\n");
document.write("End Sub\n");
document.write("</script\>\n");
document.write("<script language=\"VBScript\"\>\n");
document.write("On Error Resume Next\n");
document.write("Sub Captivate_DoExternalInterface(ByVal command, ByVal parameter, ByVal value, ByVal variable)\n");
document.write("Call Captivate_DoExternalInterface(command, parameter, value, variable)\n");
document.write("End Sub\n");
document.write("</script\>\n");
} else {
g_intAPIType = 0;
}
// This simply loops for a set period of time, waiting for the API to
// load and/or be found. A better solution would be to use setInterval
// and on the timeout, redirect or load the resulting Captivate file.
while(g_objAPI == null && timeCurrent_int < timeLimit_int){
g_objAPI = getAPI(g_intAPIOrder);
timeCurrent_int = new Date().getTime();
}
//If SCORM connection is active, append the following querystring to the URL
if(g_objAPI != null){
strURLParams = "?SCORM_API=" + g_zAPIVersion + "&SCORM_TYPE=" + g_intAPIType;
}
//swfobject.embedSWF has a built-in domready call,
//so it doesn't need to be wrapped in a window.onload event.
swfobject.embedSWF(strURLFile + strURLParams, "CaptivateContent", "641", "512", "10", false, flashvars, params, attributes, callbackFn);
window.onunload = Finish;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.