From: Vincent Vanwaelscappel Date: Tue, 4 Sep 2018 13:26:59 +0000 (+0200) Subject: wip #2207 @4 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=42f9a5e5d6bb9750029f00d5b4f3c93eb8fdb8e1;p=fluidbook-html5.git wip #2207 @4 --- diff --git a/js/libs/scorm/apiwrapper.js b/js/libs/scorm/apiwrapper.js index 7ad6a797..a0cbd76b 100644 --- a/js/libs/scorm/apiwrapper.js +++ b/js/libs/scorm/apiwrapper.js @@ -24,7 +24,6 @@ further modified by Philip Hutchison =============================================================== */ - var pipwerks = {}; //pipwerks 'namespace' helps ensure no conflicts with possible other "SCORM" variables pipwerks.UTILS = {}; //For holding UTILS functions pipwerks.debug = {isActive: true}; //Enable (true) or disable (false) for debug mode @@ -74,7 +73,6 @@ pipwerks.SCORM.isAvailable = function () { ---------------------------------------------------------------------------- */ pipwerks.SCORM.API.find = function (win) { - var API = null, findAttempts = 0, findAttemptLimit = 500, @@ -82,80 +80,52 @@ pipwerks.SCORM.API.find = function (win) { trace = pipwerks.UTILS.trace, scorm = pipwerks.SCORM; - while ((!win.API && !win.API_1484_11) && - (win.parent) && - (win.parent != win) && - (findAttempts <= findAttemptLimit)) { - + while ( + (!win.API && !win.API_1484_11) && + (win.parent) && + (win.parent != win) && + (findAttempts <= findAttemptLimit) + ) { findAttempts++; win = win.parent; - } //If SCORM version is specified by user, look for specific API if (scorm.version) { - switch (scorm.version) { - case "2004" : - if (win.API_1484_11) { - API = win.API_1484_11; - } else { - trace(traceMsgPrefix + ": SCORM version 2004 was specified by user, but API_1484_11 cannot be found."); - } - break; - case "1.2" : - if (win.API) { - API = win.API; - } else { - trace(traceMsgPrefix + ": SCORM version 1.2 was specified by user, but API cannot be found."); - } - break; - } - } else { //If SCORM version not specified by user, look for APIs - if (win.API_1484_11) { //SCORM 2004-specific API. - scorm.version = "2004"; //Set version API = win.API_1484_11; - } else if (win.API) { //SCORM 1.2-specific API - scorm.version = "1.2"; //Set version API = win.API; - } - } if (API) { - trace(traceMsgPrefix + ": API found. Version: " + scorm.version); trace("API: " + API); - } else { - trace(traceMsgPrefix + ": Error finding API. \nFind attempts: " + findAttempts + ". \nFind attempt limit: " + findAttemptLimit); - } return API; - }; @@ -170,7 +140,6 @@ pipwerks.SCORM.API.find = function (win) { ---------------------------------------------------------------------------- */ pipwerks.SCORM.API.get = function () { - var API = null, win = window, scorm = pipwerks.SCORM, @@ -200,7 +169,6 @@ pipwerks.SCORM.API.get = function () { } return API; - }; @@ -213,17 +181,12 @@ pipwerks.SCORM.API.get = function () { ---------------------------------------------------------------------------- */ pipwerks.SCORM.API.getHandle = function () { - var API = pipwerks.SCORM.API; if (!API.handle && !API.isFound) { - API.handle = API.get(); - } - return API.handle; - }; @@ -241,7 +204,6 @@ pipwerks.SCORM.API.getHandle = function () { ---------------------------------------------------------------------------- */ pipwerks.SCORM.connection.initialize = function () { - var success = false, scorm = pipwerks.SCORM, completionStatus = scorm.data.completionStatus, @@ -253,12 +215,10 @@ pipwerks.SCORM.connection.initialize = function () { trace("connection.initialize called."); if (!scorm.connection.isActive) { - var API = scorm.API.getHandle(), errorCode = 0; if (API) { - switch (scorm.version) { case "1.2" : success = makeBoolean(API.LMSInitialize("")); @@ -269,85 +229,56 @@ pipwerks.SCORM.connection.initialize = function () { } if (success) { - //Double-check that connection is active and working before returning 'true' boolean errorCode = debug.getCode(); - if (errorCode !== null && errorCode === 0) { - scorm.connection.isActive = true; - if (scorm.handleCompletionStatus) { - //Automatically set new launches to incomplete completionStatus = scorm.status("get"); - if (completionStatus) { - switch (completionStatus) { - //Both SCORM 1.2 and 2004 case "not attempted": scorm.status("set", "incomplete"); scorm.set('cmi.success_status', 'unknown'); break; - //SCORM 2004 only case "unknown" : scorm.status("set", "incomplete"); scorm.set('cmi.success_status', 'unknown'); break; - //Additional options, presented here in case you'd like to use them //case "completed" : break; //case "incomplete" : break; //case "passed" : break; //SCORM 1.2 only //case "failed" : break; //SCORM 1.2 only //case "browsed" : break; //SCORM 1.2 only - } - //Commit changes scorm.save(); - } - } - } else { - success = false; trace(traceMsgPrefix + "failed. \nError code: " + errorCode + " \nError info: " + debug.getInfo(errorCode)); - } - } else { - errorCode = debug.getCode(); if (errorCode !== null && errorCode !== 0) { - trace(traceMsgPrefix + "failed. \nError code: " + errorCode + " \nError info: " + debug.getInfo(errorCode)); - } else { - trace(traceMsgPrefix + "failed: No response from server."); - } } - } else { - trace(traceMsgPrefix + "failed: API is null."); - } - } else { - trace(traceMsgPrefix + "aborted: Connection already active."); } - return success; }; @@ -374,14 +305,11 @@ pipwerks.SCORM.connection.terminate = function () { if (scorm.connection.isActive) { - var API = scorm.API.getHandle(), errorCode = 0; if (API) { - if (scorm.handleExitMode && !exitStatus) { - if (completionStatus !== "completed" && completionStatus !== "passed") { switch (scorm.version) { case "1.2" : @@ -391,26 +319,22 @@ pipwerks.SCORM.connection.terminate = function () { success = scorm.set("cmi.exit", "suspend"); break; } - } else { switch (scorm.version) { case "1.2" : - success = scorm.set("cmi.core.exit", "logout"); + success = scorm.set("cmi.core.exit", "suspend"); break; case "2004": - success = scorm.set("cmi.exit", "normal"); + success = scorm.set("cmi.exit", "suspend"); break; } - } - } //Ensure we persist the data success = scorm.save(); if (success) { - switch (scorm.version) { case "1.2" : success = makeBoolean(API.LMSFinish("")); @@ -421,32 +345,19 @@ pipwerks.SCORM.connection.terminate = function () { } if (success) { - scorm.connection.isActive = false; - } else { - errorCode = debug.getCode(); trace(traceMsgPrefix + "failed. \nError code: " + errorCode + " \nError info: " + debug.getInfo(errorCode)); - } - } - } else { - trace(traceMsgPrefix + "failed: API is null."); - } - } else { - trace(traceMsgPrefix + "aborted: Connection already terminated."); - } - return success; - }; @@ -464,7 +375,6 @@ pipwerks.SCORM.connection.terminate = function () { ---------------------------------------------------------------------------- */ pipwerks.SCORM.data.get = function (parameter) { - var value = null, scorm = pipwerks.SCORM, trace = pipwerks.UTILS.trace, @@ -472,12 +382,10 @@ pipwerks.SCORM.data.get = function (parameter) { traceMsgPrefix = "SCORM.data.get('" + parameter + "') "; if (scorm.connection.isActive) { - var API = scorm.API.getHandle(), errorCode = 0; if (API) { - switch (scorm.version) { case "1.2" : value = API.LMSGetValue(parameter); @@ -486,52 +394,35 @@ pipwerks.SCORM.data.get = function (parameter) { value = API.GetValue(parameter); break; } - errorCode = debug.getCode(); //GetValue returns an empty string on errors //If value is an empty string, check errorCode to make sure there are no errors if (value !== "" || errorCode === 0) { - //GetValue is successful. //If parameter is lesson_status/completion_status or exit status, let's //grab the value and cache it so we can check it during connection.terminate() switch (parameter) { - case "cmi.core.lesson_status": case "cmi.completion_status" : scorm.data.completionStatus = value; break; - case "cmi.core.exit": case "cmi.exit" : scorm.data.exitStatus = value; break; - } - } else { - trace(traceMsgPrefix + "failed. \nError code: " + errorCode + "\nError info: " + debug.getInfo(errorCode)); - } - } else { - trace(traceMsgPrefix + "failed: API is null."); - } - } else { - trace(traceMsgPrefix + "failed: API connection is inactive."); - } - trace(traceMsgPrefix + " value: " + value); - return String(value); - }; @@ -548,7 +439,6 @@ pipwerks.SCORM.data.get = function (parameter) { ---------------------------------------------------------------------------- */ pipwerks.SCORM.data.set = function (parameter, value) { - var success = false, scorm = pipwerks.SCORM, trace = pipwerks.UTILS.trace, @@ -558,12 +448,10 @@ pipwerks.SCORM.data.set = function (parameter, value) { if (scorm.connection.isActive) { - var API = scorm.API.getHandle(), errorCode = 0; if (API) { - switch (scorm.version) { case "1.2" : success = makeBoolean(API.LMSSetValue(parameter, value)); @@ -574,37 +462,23 @@ pipwerks.SCORM.data.set = function (parameter, value) { } if (success) { - if (parameter === "cmi.core.lesson_status" || parameter === "cmi.completion_status") { - scorm.data.completionStatus = value; - + }else if(parameter=='cmi.core.exit' || parameter=='cmi.exit'){ + scorm.data.exitStatus = value; } - } else { - errorCode = debug.getCode(); - trace(traceMsgPrefix + "failed. \nError code: " + errorCode + ". \nError info: " + debug.getInfo(errorCode)); - } - } else { - trace(traceMsgPrefix + "failed: API is null."); - } - } else { - trace(traceMsgPrefix + "failed: API connection is inactive."); - } - trace(traceMsgPrefix + " value: " + value); - return success; - }; @@ -626,11 +500,8 @@ pipwerks.SCORM.data.save = function () { if (scorm.connection.isActive) { - var API = scorm.API.getHandle(); - if (API) { - switch (scorm.version) { case "1.2" : success = makeBoolean(API.LMSCommit("")); @@ -639,17 +510,11 @@ pipwerks.SCORM.data.save = function () { success = makeBoolean(API.Commit("")); break; } - } else { - trace(traceMsgPrefix + ": API is null."); - } - } else { - trace(traceMsgPrefix + ": API connection is inactive."); - } return success; @@ -658,7 +523,6 @@ pipwerks.SCORM.data.save = function () { pipwerks.SCORM.status = function (action, status) { - var success = false, scorm = pipwerks.SCORM, trace = pipwerks.UTILS.trace, @@ -666,7 +530,6 @@ pipwerks.SCORM.status = function (action, status) { cmi = ""; if (action !== null) { - switch (scorm.version) { case "1.2" : cmi = "cmi.core.lesson_status"; @@ -677,35 +540,23 @@ pipwerks.SCORM.status = function (action, status) { } switch (action) { - case "get": success = scorm.data.get(cmi); break; - case "set": if (status !== null) { - success = scorm.data.set(cmi, status); - } else { - success = false; trace(traceMsgPrefix + ": status was not specified."); - } - break; - default : success = false; trace(traceMsgPrefix + ": no valid action was specified."); - } - } else { - trace(traceMsgPrefix + ": action was not specified."); - } return success; @@ -734,7 +585,6 @@ pipwerks.SCORM.debug.getCode = function () { code = 0; if (API) { - switch (scorm.version) { case "1.2" : code = parseInt(API.LMSGetLastError(), 10); @@ -743,15 +593,11 @@ pipwerks.SCORM.debug.getCode = function () { code = parseInt(API.GetLastError(), 10); break; } - } else { - trace("SCORM.debug.getCode failed: API is null."); - } return code; - }; @@ -765,15 +611,12 @@ pipwerks.SCORM.debug.getCode = function () { ----------------------------------------------------------------------------- */ pipwerks.SCORM.debug.getInfo = function (errorCode) { - var scorm = pipwerks.SCORM, API = scorm.API.getHandle(), trace = pipwerks.UTILS.trace, result = ""; - if (API) { - switch (scorm.version) { case "1.2" : result = API.LMSGetErrorString(errorCode.toString()); @@ -782,15 +625,10 @@ pipwerks.SCORM.debug.getInfo = function (errorCode) { result = API.GetErrorString(errorCode.toString()); break; } - } else { - trace("SCORM.debug.getInfo failed: API is null."); - } - return String(result); - }; @@ -804,14 +642,12 @@ pipwerks.SCORM.debug.getInfo = function (errorCode) { ---------------------------------------------------------------------------- */ pipwerks.SCORM.debug.getDiagnosticInfo = function (errorCode) { - var scorm = pipwerks.SCORM, API = scorm.API.getHandle(), trace = pipwerks.UTILS.trace, result = ""; if (API) { - switch (scorm.version) { case "1.2" : result = API.LMSGetDiagnostic(errorCode); @@ -820,15 +656,11 @@ pipwerks.SCORM.debug.getDiagnosticInfo = function (errorCode) { result = API.GetDiagnostic(errorCode); break; } - } else { - trace("SCORM.debug.getDiagnosticInfo failed: API is null."); - } return String(result); - }; @@ -889,14 +721,11 @@ pipwerks.UTILS.StringToBoolean = function (value) { ---------------------------------------------------------------------------- */ pipwerks.UTILS.trace = function (msg) { - if (pipwerks.debug.isActive) { - if (window.console && window.console.log) { window.console.log(msg); } else { //alert(msg); } - } }; diff --git a/js/libs/scorm/scorm.js b/js/libs/scorm/scorm.js index 36c333b2..d7574567 100644 --- a/js/libs/scorm/scorm.js +++ b/js/libs/scorm/scorm.js @@ -79,12 +79,12 @@ function initScormEvents() { } } else if (currentLocation.indexOf('{') === 0) { var location = JSON.parse(currentLocation); - if (location.page) { - fluidbook.setCurrentPage(location.page); - } if (location.maxPage) { fluidbook.setMaxPage(location.maxPage, true); } + if (location.page) { + fluidbook.setCurrentPage(location.page); + } } } catch (err) { console.log(err); @@ -125,9 +125,17 @@ function startScormTimer() { } function scormComplete() { + setScormValue('exit', 'suspend'); setScormValue('status', "completed"); + if (fluidbook.scorm.manageScore) { + setScormValue('success_status', 'passed'); + } finishScorm(); - window.close(); + setTimeout(function(){ + parent.close(); + top.close(); + window.close(); + },1500); } function getScormValue(elementName) { @@ -279,7 +287,7 @@ function updateInteractionsScore() { status = 'failed'; } } - setScormValue('cmi.success_status', status); + setScormValue('success_status', status); } function setSessionTime() { @@ -331,6 +339,7 @@ function getScormTimeInterval(start, end) { } function scormSecondsToTimeInterval(diff) { + var diff = Math.round(diff); var h = Math.floor(diff / 3600); diff = diff % 3600; var m = Math.floor(diff / 60);