public
Created

Captivate SCORM 2004 Output, replaced SWFObject 1.5 with 2.2

  • Download Gist
captivate.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
// set document.domain property here, if it works for your environment/SCORM implementation
// document.domain="";
var 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)
strURLBase = "",
strURLParams = "",
strURLFull = document.location + "",
intTemp = strURLFull.indexOf("#"),
strTemp = location.protocol.toUpperCase(),
timeCurrent_int = new Date().getTime(),
timeLimit_int = new Date().getTime() + (intIntervalSecs * 1000),
g_bIsInternetExplorer,
flashvars = {},
params = { bgcolor: "#f5f4f1", menu: "false" },
attributes = { id: "Captivate", name: "Captivate" };
 
 
if(g_intAPIType==0){
 
// Detect Internet Explorer
g_bIsInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
 
}
 
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)){
(g_zAPIVersion=="0.2"?g_objAPI.LMSCommit(""):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 = g_bIsInternetExplorer ? Captivate : document.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, eval('g_objAPI.' + strFSCmd + '(\"\");'));
 
} else if(strFSCmd == "LMSSetValue" || strFSCmd=="SetValue"){
 
strErr = eval('g_objAPI.' + strFSCmd + '(\"' + strFSArg1 + '\",\"' + strFSArg2 + '\");');
CaptivateObj.SetVariable(strFSArg3, strErr);
 
} else if(strFSCmd == "LMSFinish" || strFSCmd=="Terminate"){
 
g_bFinishDone = eval('g_objAPI.' + strFSCmd + '(\"\");');
strErr = g_bFinishDone;
CaptivateObj.SetVariable(strFSArg3, g_bFinishDone);
 
} else if(strFSCmd == "LMSCommit" || strFSCmd=="Commit"){
 
strErr = eval('g_objAPI.' + strFSCmd + '(\"\");');
CaptivateObj.SetVariable(strFSArg3, strErr);
 
} else if((strFSArg2) && (strFSArg2.length > 0)){
 
if(strFSCmd=="LMSGetLastError" || strFSCmd=="GetLastError"){
 
strErr = eval('g_objAPI.' + strFSCmd + '();');
CaptivateObj.SetVariable(strFSArg3, strErr);
 
} else {
 
strErr = eval('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 = g_bIsInternetExplorer ? Captivate : document.Captivate,
strFSCmd = new String(command),
strErr = "true",
strFSArg1 = parameter,
strFSArg2 = value,
strFSArg3 = variable,
courseStatus;
 
//alert("command " + command + " ;parameter " +parameter+ " ;value " + value + " ;variable " + variable);
//var strFSArgs = new String(args);
 
/*var intFSDelimiter = strFSArgs.indexOf("|");
if(intFSDelimiter > -1)
{
strFSArg1 = strFSArgs.substr(0, intFSDelimiter); // Name of data element to get from API
var 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, eval('g_objAPI.' + strFSCmd + '(\"\");'));
CaptivateObj.SetScormVariable(strFSArg3,eval('g_objAPI.' + strFSCmd + '(\"\");'));
 
courseStatus = eval('g_objAPI.' + 'GetValue' + '(\"' + "cmi.completion_status" + '\");');
 
if(courseStatus == 'not attempted'){
eval('g_objAPI.' + 'SetValue' + '(\"' + "cmi.completion_status" + '\",\"' + 'incomplete' + '\");');
}
 
} else if(strFSCmd == "LMSSetValue" || strFSCmd == "SetValue"){
 
strErr = eval('g_objAPI.' + strFSCmd + '(\"' + strFSArg1 + '\",\"' + strFSArg2 + '\");');
//CaptivateObj.SetVariable(strFSArg3, strErr);
CaptivateObj.SetScormVariable(strFSArg3, strErr);
 
} else if(strFSCmd == "LMSFinish" || strFSCmd=="Terminate"){
 
g_bFinishDone = eval('g_objAPI.' + strFSCmd + '(\"\");');
strErr = g_bFinishDone;
//CaptivateObj.SetVariable(strFSArg3, g_bFinishDone);
CaptivateObj.SetScormVariable(strFSArg3, g_bFinishDone);
 
} else if(strFSCmd == "LMSCommit" || strFSCmd=="Commit"){
 
strErr = eval('g_objAPI.' + strFSCmd + '(\"\");');
//CaptivateObj.SetVariable(strFSArg3, strErr);
CaptivateObj.SetScormVariable(strFSArg3, strErr);
 
} else if((strFSArg2) && (strFSArg2.length > 0)){
 
if(strFSCmd=="LMSGetLastError" || strFSCmd=="GetLastError"){
 
strErr = eval('g_objAPI.' + strFSCmd + '();');
//CaptivateObj.SetVariable(strFSArg3, strErr);
CaptivateObj.SetScormVariable(strFSArg3, strErr);
 
} else {
 
strErr = eval('g_objAPI.' + strFSCmd + '(\"' + strFSArg1 + '\");');
//CaptivateObj.SetVariable(strFSArg3, strErr);
CaptivateObj.SetScormVariable(strFSArg3, strErr);
 
}
 
} else if(strFSCmd.substring(0,3) == "LMSGet"){
strErr = "-2: No Flash variable specified";
}
 
return strErr;
}
 
// Hook for Internet Explorer
if((navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) || 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;
}
 
if(intTemp == -1){
intTemp = strURLFull.indexOf("?");
}
 
if(intTemp > 0){
strURLParams = strURLFull.substring(intTemp + 1, strURLFull.length);
}
 
if(strTemp.indexOf("FILE") == -1){
intTemp = location.pathname.lastIndexOf("/");
} else {
intTemp = location.pathname.lastIndexOf("\\");
}
 
if(intTemp != -1){
strURLBase = location.protocol + "//" + location.host + location.pathname.substring(0, intTemp + 1);
} else {
strURLBase = location.protocol + "//" + location.host + location.pathname;
}
 
strURLParams = (strURLParams==unescape(strURLParams)?escape(strURLParams):strURLParams);
strURLParams = (strURLParams==""?"":"?") + strURLParams;
 
 
// 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(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;
sample.htm
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
<!-- Copyright [2008] Adobe Systems Incorporated. All rights reserved -->
<!-- saved from url=(0013)about:internet -->
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
<script src="standard.js"></script>
<script src="SCORM_support/scorm_support.js"></script>
<script src="captivate.js"></script>
<style>
body { background: #f5f4f1; text-align: center; }
</style>
</head>
<body>
<div id="CaptivateContent">&nbsp;</div>
<layer id="NS_dynamic" name="NS_dynamic">
<noscript>
This course requires JavaScript to be enabled in your browser. Please enable JavaScript, then relaunch the course.
</noscript>
</layer>
</body>
</html>
standard.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
/**
*
* Copyright 2007
*
* Paulius Uza
* http://www.uza.lt
*
* Dan Florio
* http://www.polygeek.com
*
* Project website:
* http://code.google.com/p/custom-context-menu/
*
* --
* RightClick for Flash Player.
* Version 0.6.2
*
*/
 
var RightClick = {
/**
* Constructor
*/
init: function () {
this.FlashObjectID = "Captivate";
this.FlashContainerID = "CaptivateContent";
this.Cache = this.FlashObjectID;
if(window.addEventListener){
window.addEventListener("mousedown", this.onGeckoMouse(), true);
} else {
document.getElementById(this.FlashContainerID).onmouseup = function() { document.getElementById(RightClick.FlashContainerID).releaseCapture(); }
document.oncontextmenu = function(){ if(window.event.srcElement.id == RightClick.FlashObjectID) { return false; } else { RightClick.Cache = "nan"; }}
document.getElementById(this.FlashContainerID).onmousedown = RightClick.onIEMouse;
}
},
/**
* GECKO / WEBKIT event overkill
* @param {Object} eventObject
*/
killEvents: function(eventObject) {
if(eventObject) {
if (eventObject.stopPropagation) eventObject.stopPropagation();
if (eventObject.preventDefault) eventObject.preventDefault();
if (eventObject.preventCapture) eventObject.preventCapture();
if (eventObject.preventBubble) eventObject.preventBubble();
}
},
/**
* GECKO / WEBKIT call right click
* @param {Object} ev
*/
onGeckoMouse: function(ev) {
return function(ev) {
if (ev.button == 2) {
RightClick.killEvents(ev);
if(ev.target.id == RightClick.FlashObjectID && RightClick.Cache == RightClick.FlashObjectID) {
RightClick.call();
}
RightClick.Cache = ev.target.id;
}
}
},
/**
* IE call right click
* @param {Object} ev
*/
onIEMouse: function() {
if (event.button == 2) {
if(window.event.srcElement.id == RightClick.FlashObjectID && RightClick.Cache == RightClick.FlashObjectID) {
RightClick.call();
}
document.getElementById(RightClick.FlashContainerID).setCapture();
if(window.event.srcElement.id)
RightClick.Cache = window.event.srcElement.id;
}
},
/**
* Main call to Flash External Interface
*/
call: function() {
document.getElementById(this.FlashObjectID).rightClick();
}
}
 
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
//
//This is the base class for implementing an Active Content extension -- a piece of code that knows how to rewrite OBJECT tags so that they comply to the Eolas patent without making the browser display the "Press OK to continue loading the content of this page" message box.
//
// When the user hovers the mouse over an ActiveX control in Internet Explorer 6 updated with (April 2006) Cumulative Security Update (912812) or Internet Explorer 7, the following message is displayed:
// ìPress Spacebar or Enter to activate and use this control.î
// The user can now click the mouse anywhere inside the ActiveX control area, or press the Spacebar or Enter key to activate the control.
// The standard.js file has been introduced to retain the earlier behavior where the control remains interactive from the first click to the last.
 
function writeDocument(s){document.write(s);}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.