public
Created

Captivate SCORM 2004 Output, begin cleanup of scorm_support.js

  • Download Gist
scorm_support.js
JavaScript
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
var g_objAPI = null,
g_nAPI = 0, // type of API to start searching for; allowable values: 0 - SCORM 2004; 1 - SCORM 1.2 (or 1.1)
g_aAPI = ["1.0", "0.2"], // Array that stores the API versions
g_zAPIVersion = -1,
g_bFinishDone = false,
g_intAPIType = 0, // Specifies SCORM 2004
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 findAPI(win) {
 
// Search the window hierarchy for an object named "API_1484_11" for SCORM 2004 or "API" for SCORM 1.2 or below
// Look in the current window (win) and recursively look in any child frames
 
if(g_nAPI == 0){
 
if(win.API_1484_11 != null){
return win.API_1484_11;
}
 
} else if(g_nAPI == 1 || g_nAPI == "") {
 
if (win.API != null){
g_zAPIVersion = g_aAPI[g_nAPI];
return win.API;
}
 
}
 
if (win.length > 0){ // check frames
 
for (var i=0;i<win.length;i++){
var objAPI = findAPI(win.frames[i]);
if (objAPI != null){
return objAPI;
}
}
}
 
return null;
 
}
 
 
function getAPI(intAPISearchOrder) {
 
// intAPISearchOrder is 0 - start at current window and work way up; 1 - start at top window and work way down.
 
var objAPI = null;
 
intAPISearchOrder = (typeof intAPISearchOrder === "undefined") ? 0 : intAPISearchOrder;
 
if(intAPISearchOrder == 0) {
 
// start and the current window and recurse up through parent windows/frames
 
var objCurrentWindow = window,
xCount = 0;
 
objAPI = findAPI(objCurrentWindow);
 
while(objCurrentWindow && !objAPI && xCount < 100){
 
xCount++;
 
if(objCurrentWindow.opener != null && typeof objCurrentWindow.opener !== "undefined"){
objCurrentWindow = objCurrentWindow.opener;
} else {
objCurrentWindow = objCurrentWindow.parent;
}
 
objAPI = findAPI(objCurrentWindow);
 
}
 
if(objAPI == null && g_nAPI < (g_aAPI.length-1)){
g_nAPI++;
objAPI = getAPI(intAPISearchOrder);
}
 
} else {
 
// start at the top window and recurse down through child frames
 
objAPI = findAPI(this.top);
 
if (objAPI == null){
 
// the API wasn't found in the current window's hierarchy. If the
// current window has an opener (was launched by another window),
// check the opener's window hierarchy.
 
objTopWindow=window.top;
objTopWindow = objTopWindow.opener;
 
while (objTopWindow && !objAPI){
 
//checking window opener
objAPI = findAPI(objTopWindow.top);
if (objAPI==null){
objTopWindow = objTopWindow.opener;
}
 
}
 
if(objAPI == null && g_nAPI < (g_aAPI.length-1)){
g_nAPI++;
objAPI = getAPI(intAPISearchOrder);
}
 
}
 
}
 
if(objAPI == null) {
 
//can't find API
 
} else if(objAPI != null && g_zAPIVersion == -1) {
 
g_zAPIVersion = objAPI.version;
 
}
 
return objAPI;
 
}
 
function setAPI() {
 
while(g_objAPI == undefined){
g_objAPI = getAPI(0);
}
 
}
 
function isAPI() {
return typeof g_objAPI !== "undefined" && g_objAPI != null;
}
 
// called in the outer HTML file
// g_objAPI = getAPI();
 
function dataToFlash(layer, msg) {
 
// set the comm HTML
 
fcomValue = "<OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" WIDTH=\"2\" HEIGHT=\"2\" id=\"scorm_support\" ALIGN=\"\"> <PARAM NAME=movie VALUE=\"scorm_support.swf?invokeMethod=methodToExecute&lc_name=lc_name&param=" + msg + "\"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#FFFFFF> <EMBED src=\"scorm_support.swf?invokeMethod=methodToExecute&lc_name=lc_name&param=" + msg + "\" quality=high bgcolor=#FFFFFF WIDTH=\"2\" HEIGHT=\"2\" NAME=\"scorm_support\" ALIGN=\"\" TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=\"http://www.macromedia.com/go/getflashplayer\"></EMBED> </OBJECT>";
 
// get the browser info
 
var IE = swfobject.ua.ie,
NS4 = (navigator.appName.indexOf("Netscape")!=-1 && parseInt(navigator.appVersion)<5),
NS6 = (navigator.appName.indexOf("Netscape")!=-1 && parseInt(navigator.appVersion)>4.9);
 
if (IE){
IE_dynamic.document.body.innerHTML=fcomValue;
}
 
if (NS4){
 
// change the comm HTML
 
fcomValue = "<OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" WIDTH=\"2\" HEIGHT=\"2\" id=\"scorm_support\" ALIGN=\"\"> <PARAM NAME=movie VALUE=\"SCORM_support/scorm_support.swf?invokeMethod=methodToExecute&lc_name=lc_name&param=" + msg + "\"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#FFFFFF> <EMBED src=\"SCORM_support/scorm_support.swf?invokeMethod=methodToExecute&lc_name=lc_name&param=" + msg + "\" quality=high bgcolor=#FFFFFF WIDTH=\"2\" HEIGHT=\"2\" NAME=\"scorm_support\" ALIGN=\"\" TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=\"http://www.macromedia.com/go/getflashplayer\"></EMBED> </OBJECT>";
 
eval("var echoecho = document.layers.NS_"+layer+".document;");
echoecho.open();
echoecho.write(fcomValue);
echoecho.close();
 
}
 
if (NS6){
 
// change the comm HTML
 
fcomValue = "<OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" WIDTH=\"2\" HEIGHT=\"2\" id=\"scorm_support\" ALIGN=\"\"> <PARAM NAME=movie VALUE=\"SCORM_support/scorm_support.swf?invokeMethod=methodToExecute&lc_name=lc_name&param=" + msg + "\"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#FFFFFF> <EMBED src=\"SCORM_support/scorm_support.swf?invokeMethod=methodToExecute&lc_name=lc_name&param=" + msg + "\" quality=high bgcolor=#FFFFFF WIDTH=\"2\" HEIGHT=\"2\" NAME=\"scorm_support\" ALIGN=\"\" TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=\"http://www.macromedia.com/go/getflashplayer\"></EMBED> </OBJECT>";
 
document.getElementById("NS_"+layer).innerHTML = fcomValue;
 
}
 
}
 
 
function dataFromFlash(strSCOfunction, strSCOproperty, varSCOvalue, strFLvariableName) {
 
var varResult = false;
 
if(isAPI()){
 
if (varSCOvalue != ""){
 
varResult = g_objAPI[strSCOfunction](strSCOproperty, varSCOvalue);
 
} else {
 
if(strSCOfunction == "LMSGetLastError"){
 
varResult = g_objAPI[strSCOfunction]();
 
} else {
 
varResult = g_objAPI[strSCOfunction](strSCOproperty);
 
}
 
}
 
} else {
 
if (SCOvalue != ""){
 
varResult = strSCOfunction(strSCOproperty, varSCOvalue);
 
} else {
 
varResult = strSCOfunction(strSCOproperty);
 
}
 
}
 
if(strSCOfunction == "Terminate"){
 
// set global variable to result of Finish function
g_bFinishDone = varResult;
 
}
 
dataToFlash("dynamic", strFLvariableName + "|" + varResult);
 
}
 
 
function Finish(){
 
if(isAPI() && g_bFinishDone == false){
g_objAPI.Commit("");
g_bFinishDone = (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 == "Initialize"){
 
CaptivateObj.SetVariable(strFSArg3, g_objAPI.Initialize(""));
 
} else if(strFSCmd == "SetValue"){
 
strErr = g_objAPI.SetValue(strFSArg1, strFSArg2);
CaptivateObj.SetVariable(strFSArg3, strErr);
 
} else if(strFSCmd == "Terminate"){
 
g_bFinishDone = g_objAPI.Terminate("");
strErr = g_bFinishDone;
CaptivateObj.SetVariable(strFSArg3, g_bFinishDone);
 
} else if(strFSCmd == "Commit"){
 
strErr = g_objAPI.Commit("");
CaptivateObj.SetVariable(strFSArg3, strErr);
 
} else if(strFSArg2 && (strFSArg2.length > 0)){
 
if(strFSCmd == "GetLastError"){
 
strErr = g_objAPI.GetLastError();
CaptivateObj.SetVariable(strFSArg3, strErr);
 
} else {
 
strErr = g_objAPI[strFSCmd](strFSArg1);
CaptivateObj.SetVariable(strFSArg3, strErr);
 
}
 
}
 
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 == "Initialize"){
 
CaptivateObj.SetScormVariable(strFSArg3, g_objAPI.Initialize(""));
 
courseStatus = g_objAPI.GetValue("cmi.completion_status");
 
if(courseStatus == "not attempted"){
g_objAPI.SetValue("cmi.completion_status", "incomplete");
}
 
} else if(strFSCmd == "SetValue"){
 
strErr = g_objAPI.SetValue(strFSArg1, strFSArg2);
CaptivateObj.SetScormVariable(strFSArg3, strErr);
 
} else if(strFSCmd == "Terminate"){
 
g_bFinishDone = g_objAPI.Terminate("");
strErr = g_bFinishDone;
CaptivateObj.SetScormVariable(strFSArg3, g_bFinishDone);
 
} else if(strFSCmd == "Commit"){
 
strErr = g_objAPI.Commit("");
CaptivateObj.SetScormVariable(strFSArg3, strErr);
 
} else if((strFSArg2) && (strFSArg2.length > 0)){
 
if(strFSCmd == "GetLastError"){
 
strErr = g_objAPI.GetLastError();
CaptivateObj.SetScormVariable(strFSArg3, strErr);
 
} else {
 
strErr = g_objAPI[strFSCmd](strFSArg1);
CaptivateObj.SetScormVariable(strFSArg3, strErr);
 
}
 
}
 
return strErr;
 
}
 
// Hook for Internet Explorer
if(swfobject.ua.ie){
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");
}
 
// 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=0";
}
 
 
window.onunload = Finish;

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.