]> _ Git - fluidbook-html5.git/commitdiff
#scorm : improve status management
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 23 Mar 2016 19:01:17 +0000 (19:01 +0000)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 23 Mar 2016 19:01:17 +0000 (19:01 +0000)
@2

js/libs/scorm/apiwrapper.js
js/libs/scorm/scorm.js
js/main.js

index 6752f01b8f4ba86c1d3ccbcbb490950f7b8df5b8..113feee0959a6be1e4e481e8061a4087b3da6194 100644 (file)
@@ -1,24 +1,24 @@
 /*******************************************************************************\r
-**\r
-** This software is provided "AS IS," without a warranty of any kind.  ALL\r
-** EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY\r
-** IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-\r
-** INFRINGEMENT, ARE HEREBY EXCLUDED.  PAUL BECKWITH AND HIS LICENSORS SHALL NOT BE LIABLE\r
-** FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR\r
-** DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES.  IN NO EVENT WILL PAUL BECKWITH OR ITS\r
-** LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,\r
-** INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER\r
-** CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF\r
-** OR INABILITY TO USE SOFTWARE, EVEN IF CTC  HAS BEEN ADVISED OF THE POSSIBILITY\r
-** OF SUCH DAMAGES.\r
-**    javascript:\r
-**          var result = doLMSInitialize();\r
-**          if (result != true) \r
-**          {\r
+ **\r
+ ** This software is provided "AS IS," without a warranty of any kind.  ALL\r
+ ** EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY\r
+ ** IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-\r
+ ** INFRINGEMENT, ARE HEREBY EXCLUDED.  PAUL BECKWITH AND HIS LICENSORS SHALL NOT BE LIABLE\r
+ ** FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR\r
+ ** DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES.  IN NO EVENT WILL PAUL BECKWITH OR ITS\r
+ ** LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,\r
+ ** INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER\r
+ ** CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF\r
+ ** OR INABILITY TO USE SOFTWARE, EVEN IF CTC  HAS BEEN ADVISED OF THE POSSIBILITY\r
+ ** OF SUCH DAMAGES.\r
+ **    javascript:\r
+ **          var result = doLMSInitialize();\r
+ **          if (result != true)\r
+ **          {\r
 **             // handle error\r
 **          }\r
-**\r
-*******************************************************************************/\r
+ **\r
+ *******************************************************************************/\r
 \r
 \r
 var _Debug = false;  // set this to false to turn debugging off\r
@@ -46,460 +46,415 @@ var findAPITries = 0;
 \r
 \r
 /*******************************************************************************\r
-**\r
-** Function: doLMSInitialize()\r
-** Inputs:  None\r
-** Return:  CMIBoolean true if the initialization was successful, or\r
-**          CMIBoolean false if the initialization failed.\r
-**\r
-** Description:\r
-** Initialize communication with LMS by calling the LMSInitialize\r
-** function which will be implemented by the LMS.\r
-**\r
-*******************************************************************************/\r
-function doLMSInitialize()\r
-{\r
-   startTimer();\r
-\r
-   var api = getAPIHandle();\r
-   if (api == null)\r
-   {\r
-      alert("Unable to locate the LMS's API Implementation.\nLMSInitialize was not successful.");\r
-      return "false";\r
-   }\r
-\r
-   var result = api.LMSInitialize("");\r
-\r
-   if (result.toString() != "true")\r
-   {\r
-      var err = ErrorHandler();\r
-   }\r
-\r
-   return result.toString();\r
+ **\r
+ ** Function: doLMSInitialize()\r
+ ** Inputs:  None\r
+ ** Return:  CMIBoolean true if the initialization was successful, or\r
+ **          CMIBoolean false if the initialization failed.\r
+ **\r
+ ** Description:\r
+ ** Initialize communication with LMS by calling the LMSInitialize\r
+ ** function which will be implemented by the LMS.\r
+ **\r
+ *******************************************************************************/\r
+function doLMSInitialize() {\r
+    startTimer();\r
+\r
+    var api = getAPIHandle();\r
+    if (api == null) {\r
+        fb("Unable to locate the LMS's API Implementation.\nLMSInitialize was not successful.");\r
+        return "false";\r
+    }\r
+\r
+    var result = api.LMSInitialize("");\r
+\r
+    if (result.toString() != "true") {\r
+        var err = ErrorHandler();\r
+    }\r
+\r
+    return result.toString();\r
 }\r
 \r
 /*******************************************************************************\r
-**\r
-** Function doLMSFinish()\r
-** Inputs:  None\r
-** Return:  CMIBoolean true if successful\r
-**          CMIBoolean false if failed.\r
-**\r
-** Description:\r
-** Close communication with LMS by calling the LMSFinish\r
-** function which will be implemented by the LMS\r
-**\r
-*******************************************************************************/\r
-function doLMSFinish()\r
-{\r
-\r
-  setSessionTime();\r
-\r
-   var api = getAPIHandle();\r
-   if (api == null)\r
-   {\r
-      alert("Unable to locate the LMS's API Implementation.\nLMSFinish was not successful.");\r
-      return "false";\r
-   }\r
-   else\r
-   {\r
-      // call the LMSFinish function that should be implemented by the API\r
-\r
-      var result = api.LMSFinish("");\r
-      if (result.toString() != "true")\r
-      {\r
-         var err = ErrorHandler();\r
-      }\r
-\r
-   }\r
-\r
-   return result.toString();\r
+ **\r
+ ** Function doLMSFinish()\r
+ ** Inputs:  None\r
+ ** Return:  CMIBoolean true if successful\r
+ **          CMIBoolean false if failed.\r
+ **\r
+ ** Description:\r
+ ** Close communication with LMS by calling the LMSFinish\r
+ ** function which will be implemented by the LMS\r
+ **\r
+ *******************************************************************************/\r
+function doLMSFinish() {\r
+\r
+    setSessionTime();\r
+\r
+    var api = getAPIHandle();\r
+    if (api == null) {\r
+        fb("Unable to locate the LMS's API Implementation.\nLMSFinish was not successful.");\r
+        return "false";\r
+    }\r
+    else {\r
+        // call the LMSFinish function that should be implemented by the API\r
+\r
+        var result = api.LMSFinish("");\r
+        if (result.toString() != "true") {\r
+            var err = ErrorHandler();\r
+        }\r
+\r
+    }\r
+\r
+    return result.toString();\r
 }\r
 \r
 /*******************************************************************************\r
-**\r
-** Function doLMSGetValue(name)\r
-** Inputs:  name - string representing the cmi data model defined category or\r
-**             element (e.g. cmi.core.student_id)\r
-** Return:  The value presently assigned by the LMS to the cmi data model\r
-**       element defined by the element or category identified by the name\r
-**       input value.\r
-**\r
-** Description:\r
-** Wraps the call to the LMS LMSGetValue method\r
-**\r
-*******************************************************************************/\r
-function doLMSGetValue(name)\r
-{\r
-   var api = getAPIHandle();\r
-   if (api == null)\r
-   {\r
-      alert("Unable to locate the LMS's API Implementation.\nLMSGetValue was not successful.");\r
-      return "";\r
-   }\r
-   else\r
-   {\r
-      var value = api.LMSGetValue(name);\r
-      var errCode = api.LMSGetLastError().toString();\r
-      if (errCode != _NoError)\r
-      {\r
-         // an error was encountered so display the error description\r
-         var errDescription = api.LMSGetErrorString(errCode);\r
-         alert("LMSGetValue("+name+") failed. \n"+ errDescription);\r
-         return "";\r
-      }\r
-      else\r
-      {\r
-         \r
-         return value.toString();\r
-      }\r
-   }\r
+ **\r
+ ** Function doLMSGetValue(name)\r
+ ** Inputs:  name - string representing the cmi data model defined category or\r
+ **             element (e.g. cmi.core.student_id)\r
+ ** Return:  The value presently assigned by the LMS to the cmi data model\r
+ **       element defined by the element or category identified by the name\r
+ **       input value.\r
+ **\r
+ ** Description:\r
+ ** Wraps the call to the LMS LMSGetValue method\r
+ **\r
+ *******************************************************************************/\r
+function doLMSGetValue(name) {\r
+    var api = getAPIHandle();\r
+    if (api == null) {\r
+        fb("Unable to locate the LMS's API Implementation.\nLMSGetValue was not successful.");\r
+        return "";\r
+    }\r
+    else {\r
+        var value = api.LMSGetValue(name);\r
+        var errCode = api.LMSGetLastError().toString();\r
+        if (errCode != _NoError) {\r
+            // an error was encountered so display the error description\r
+            var errDescription = api.LMSGetErrorString(errCode);\r
+            fb("LMSGetValue(" + name + ") failed. \n" + errDescription);\r
+            return "";\r
+        }\r
+        else {\r
+\r
+            return value.toString();\r
+        }\r
+    }\r
 }\r
 \r
 /*******************************************************************************\r
-**\r
-** Function doLMSSetValue(name, value)\r
-** Inputs:  name -string representing the data model defined category or element\r
-**          value -the value that the named element or category will be assigned\r
-** Return:  CMIBoolean true if successful\r
-**          CMIBoolean false if failed.\r
-**\r
-** Description:\r
-** Wraps the call to the LMS LMSSetValue function\r
-**\r
-*******************************************************************************/\r
-function doLMSSetValue(name, value)\r
-{\r
-   var api = getAPIHandle();\r
-   if (api == null)\r
-   {\r
-      alert("Unable to locate the LMS's API Implementation.\nLMSSetValue was not successful.");\r
-      return;\r
-   }\r
-   else\r
-   {\r
-      var result = api.LMSSetValue(name, value);\r
-      if (result.toString() != "true")\r
-      {\r
-         var err = ErrorHandler();\r
-      }\r
-   }\r
-\r
-   return;\r
+ **\r
+ ** Function doLMSSetValue(name, value)\r
+ ** Inputs:  name -string representing the data model defined category or element\r
+ **          value -the value that the named element or category will be assigned\r
+ ** Return:  CMIBoolean true if successful\r
+ **          CMIBoolean false if failed.\r
+ **\r
+ ** Description:\r
+ ** Wraps the call to the LMS LMSSetValue function\r
+ **\r
+ *******************************************************************************/\r
+function doLMSSetValue(name, value) {\r
+    var api = getAPIHandle();\r
+    if (api == null) {\r
+        fb("Unable to locate the LMS's API Implementation.\nLMSSetValue was not successful.");\r
+        return;\r
+    }\r
+    else {\r
+        var result = api.LMSSetValue(name, value);\r
+        if (result.toString() != "true") {\r
+            var err = ErrorHandler();\r
+        }\r
+    }\r
+\r
+    return;\r
 }\r
 \r
 /*******************************************************************************\r
-**\r
-** Function doLMSCommit()\r
-** Inputs:  None\r
-** Return:  None\r
-**\r
-** Description:\r
-** Call the LMSCommit function \r
-**\r
-*******************************************************************************/\r
-function doLMSCommit()\r
-{\r
-   var api = getAPIHandle();\r
-   if (api == null)\r
-   {\r
-      alert("Unable to locate the LMS's API Implementation.\nLMSCommit was not successful.");\r
-      return "false";\r
-   }\r
-   else\r
-   {\r
-      var result = api.LMSCommit("");\r
-      if (result != "true")\r
-      {\r
-         var err = ErrorHandler();\r
-      }\r
-   }\r
-\r
-   return result.toString();\r
+ **\r
+ ** Function doLMSCommit()\r
+ ** Inputs:  None\r
+ ** Return:  None\r
+ **\r
+ ** Description:\r
+ ** Call the LMSCommit function\r
+ **\r
+ *******************************************************************************/\r
+function doLMSCommit() {\r
+    var api = getAPIHandle();\r
+    if (api == null) {\r
+        fb("Unable to locate the LMS's API Implementation.\nLMSCommit was not successful.");\r
+        return "false";\r
+    }\r
+    else {\r
+        var result = api.LMSCommit("");\r
+        if (result != "true") {\r
+            var err = ErrorHandler();\r
+        }\r
+    }\r
+\r
+    return result.toString();\r
 }\r
 \r
 /*******************************************************************************\r
-**\r
-** Function doLMSGetLastError()\r
-** Inputs:  None\r
-** Return:  The error code that was set by the last LMS function call\r
-**\r
-** Description:\r
-** Call the LMSGetLastError function \r
-**\r
-*******************************************************************************/\r
-function doLMSGetLastError()\r
-{\r
-   var api = getAPIHandle();\r
-   if (api == null)\r
-   {\r
-      alert("Unable to locate the LMS's API Implementation.\nLMSGetLastError was not successful.");\r
-      //since we can't get the error code from the LMS, return a general error\r
-      return _GeneralError;\r
-   }\r
-\r
-   return api.LMSGetLastError().toString();\r
+ **\r
+ ** Function doLMSGetLastError()\r
+ ** Inputs:  None\r
+ ** Return:  The error code that was set by the last LMS function call\r
+ **\r
+ ** Description:\r
+ ** Call the LMSGetLastError function\r
+ **\r
+ *******************************************************************************/\r
+function doLMSGetLastError() {\r
+    var api = getAPIHandle();\r
+    if (api == null) {\r
+        fb("Unable to locate the LMS's API Implementation.\nLMSGetLastError was not successful.");\r
+        //since we can't get the error code from the LMS, return a general error\r
+        return _GeneralError;\r
+    }\r
+\r
+    return api.LMSGetLastError().toString();\r
 }\r
 \r
 /*******************************************************************************\r
-**\r
-** Function doLMSGetErrorString(errorCode)\r
-** Inputs:  errorCode - Error Code\r
-** Return:  The textual description that corresponds to the input error code\r
-**\r
-** Description:\r
-** Call the LMSGetErrorString function \r
-**\r
-********************************************************************************/\r
-function doLMSGetErrorString(errorCode)\r
-{\r
-   var api = getAPIHandle();\r
-   if (api == null)\r
-   {\r
-      alert("Unable to locate the LMS's API Implementation.\nLMSGetErrorString was not successful.");\r
-   }\r
-\r
-   return api.LMSGetErrorString(errorCode).toString();\r
+ **\r
+ ** Function doLMSGetErrorString(errorCode)\r
+ ** Inputs:  errorCode - Error Code\r
+ ** Return:  The textual description that corresponds to the input error code\r
+ **\r
+ ** Description:\r
+ ** Call the LMSGetErrorString function\r
+ **\r
+ ********************************************************************************/\r
+function doLMSGetErrorString(errorCode) {\r
+    var api = getAPIHandle();\r
+    if (api == null) {\r
+        fb("Unable to locate the LMS's API Implementation.\nLMSGetErrorString was not successful.");\r
+    }\r
+\r
+    return api.LMSGetErrorString(errorCode).toString();\r
 }\r
 \r
 /*******************************************************************************\r
-**\r
-** Function doLMSGetDiagnostic(errorCode)\r
-** Inputs:  errorCode - Error Code(integer format), or null\r
-** Return:  The vendor specific textual description that corresponds to the \r
-**          input error code\r
-**\r
-** Description:\r
-** Call the LMSGetDiagnostic function\r
-**\r
-*******************************************************************************/\r
-function doLMSGetDiagnostic(errorCode)\r
-{\r
-   var api = getAPIHandle();\r
-   if (api == null)\r
-   {\r
-      alert("Unable to locate the LMS's API Implementation.\nLMSGetDiagnostic was not successful.");\r
-   }\r
-\r
-   return api.LMSGetDiagnostic(errorCode).toString();\r
+ **\r
+ ** Function doLMSGetDiagnostic(errorCode)\r
+ ** Inputs:  errorCode - Error Code(integer format), or null\r
+ ** Return:  The vendor specific textual description that corresponds to the\r
+ **          input error code\r
+ **\r
+ ** Description:\r
+ ** Call the LMSGetDiagnostic function\r
+ **\r
+ *******************************************************************************/\r
+function doLMSGetDiagnostic(errorCode) {\r
+    var api = getAPIHandle();\r
+    if (api == null) {\r
+        fb("Unable to locate the LMS's API Implementation.\nLMSGetDiagnostic was not successful.");\r
+    }\r
+\r
+    return api.LMSGetDiagnostic(errorCode).toString();\r
 }\r
 \r
 /*******************************************************************************\r
-**\r
-** Function LMSIsInitialized()\r
-** Inputs:  none\r
-** Return:  true if the LMS API is currently initialized, otherwise false\r
-**\r
-** Description:\r
-** Determines if the LMS API is currently initialized or not.\r
-**\r
-*******************************************************************************/\r
-function LMSIsInitialized()\r
-{\r
-   // there is no direct method for determining if the LMS API is initialized\r
-   // for example an LMSIsInitialized function defined on the API so we'll try\r
-   // a simple LMSGetValue and trap for the LMS Not Initialized Error\r
-\r
-   var api = getAPIHandle();\r
-   if (api == null)\r
-   {\r
-      alert("Unable to locate the LMS's API Implementation.\nLMSIsInitialized() failed.");\r
-      return false;\r
-   }\r
-   else\r
-   {\r
-      var value = api.LMSGetValue("cmi.core.student_name");\r
-      var errCode = api.LMSGetLastError().toString();\r
-      if (errCode == _NotInitialized)\r
-      {\r
-         return false;\r
-      }\r
-      else\r
-      {\r
-         return true;\r
-      }\r
-   }\r
+ **\r
+ ** Function LMSIsInitialized()\r
+ ** Inputs:  none\r
+ ** Return:  true if the LMS API is currently initialized, otherwise false\r
+ **\r
+ ** Description:\r
+ ** Determines if the LMS API is currently initialized or not.\r
+ **\r
+ *******************************************************************************/\r
+function LMSIsInitialized() {\r
+    // there is no direct method for determining if the LMS API is initialized\r
+    // for example an LMSIsInitialized function defined on the API so we'll try\r
+    // a simple LMSGetValue and trap for the LMS Not Initialized Error\r
+\r
+    var api = getAPIHandle();\r
+    if (api == null) {\r
+        fb("Unable to locate the LMS's API Implementation.\nLMSIsInitialized() failed.");\r
+        return false;\r
+    }\r
+    else {\r
+        var value = api.LMSGetValue("cmi.core.student_name");\r
+        var errCode = api.LMSGetLastError().toString();\r
+        if (errCode == _NotInitialized) {\r
+            return false;\r
+        }\r
+        else {\r
+            return true;\r
+        }\r
+    }\r
 }\r
 \r
 /*******************************************************************************\r
-**\r
-** Function ErrorHandler()\r
-** Inputs:  None\r
-** Return:  The current value of the LMS Error Code\r
-**\r
-** Description:\r
-** Determines if an error was encountered by the previous API call\r
-** and if so, displays a message to the user.  If the error code\r
-** has associated text it is also displayed.\r
-**\r
-*******************************************************************************/\r
-function ErrorHandler()\r
-{\r
-   var api = getAPIHandle();\r
-   if (api == null)\r
-   {\r
-      alert("Unable to locate the LMS's API Implementation.\nCannot determine LMS error code.");\r
-      return;\r
-   }\r
-\r
-   // check for errors caused by or from the LMS\r
-   var errCode = api.LMSGetLastError().toString();\r
-   if (errCode != _NoError)\r
-   {\r
-      // an error was encountered so display the error description\r
-      var errDescription = api.LMSGetErrorString(errCode);\r
-\r
-      if (_Debug == true)\r
-      {\r
-         errDescription += "\n";\r
-         errDescription += api.LMSGetDiagnostic(null);\r
-         // by passing null to LMSGetDiagnostic, we get any available diagnostics\r
-         // on the previous error.\r
-      }\r
-\r
-      alert(errDescription);\r
-   }\r
-\r
-   return errCode;\r
+ **\r
+ ** Function ErrorHandler()\r
+ ** Inputs:  None\r
+ ** Return:  The current value of the LMS Error Code\r
+ **\r
+ ** Description:\r
+ ** Determines if an error was encountered by the previous API call\r
+ ** and if so, displays a message to the user.  If the error code\r
+ ** has associated text it is also displayed.\r
+ **\r
+ *******************************************************************************/\r
+function ErrorHandler() {\r
+    var api = getAPIHandle();\r
+    if (api == null) {\r
+        fb("Unable to locate the LMS's API Implementation.\nCannot determine LMS error code.");\r
+        return;\r
+    }\r
+\r
+    // check for errors caused by or from the LMS\r
+    var errCode = api.LMSGetLastError().toString();\r
+    if (errCode != _NoError) {\r
+        // an error was encountered so display the error description\r
+        var errDescription = api.LMSGetErrorString(errCode);\r
+\r
+        if (_Debug == true) {\r
+            errDescription += "\n";\r
+            errDescription += api.LMSGetDiagnostic(null);\r
+            // by passing null to LMSGetDiagnostic, we get any available diagnostics\r
+            // on the previous error.\r
+        }\r
+\r
+        fb(errDescription);\r
+    }\r
+\r
+    return errCode;\r
 }\r
 \r
 /******************************************************************************\r
-**\r
-** Function getAPIHandle()\r
-** Inputs:  None\r
-** Return:  value contained by APIHandle\r
-**\r
-** Description:\r
-** Returns the handle to API object if it was previously set,\r
-** otherwise it returns null\r
-**\r
-*******************************************************************************/\r
-function getAPIHandle()\r
-{\r
-   if (apiHandle == null)\r
-   {\r
-      apiHandle = getAPI();\r
-   }\r
-\r
-   return apiHandle;\r
+ **\r
+ ** Function getAPIHandle()\r
+ ** Inputs:  None\r
+ ** Return:  value contained by APIHandle\r
+ **\r
+ ** Description:\r
+ ** Returns the handle to API object if it was previously set,\r
+ ** otherwise it returns null\r
+ **\r
+ *******************************************************************************/\r
+function getAPIHandle() {\r
+    if (apiHandle == null) {\r
+        apiHandle = getAPI();\r
+    }\r
+\r
+    return apiHandle;\r
 }\r
 \r
 \r
 /*******************************************************************************\r
-**\r
-** Function findAPI(win)\r
-** Inputs:  win - a Window Object\r
-** Return:  If an API object is found, it's returned, otherwise null is returned\r
-**\r
-** Description:\r
-** This function looks for an object named API in parent and opener windows\r
-**\r
-*******************************************************************************/\r
-function findAPI(win)\r
-{\r
-   while ((win.API == null) && (win.parent != null) && (win.parent != win))\r
-   {\r
-      findAPITries++;\r
-      // Note: 7 is an arbitrary number, but should be more than sufficient\r
-      if (findAPITries > 7) \r
-      {\r
-         alert("Error finding API -- too deeply nested.");\r
-         return null;\r
-      }\r
-      \r
-      win = win.parent;\r
-\r
-   }\r
-   return win.API;\r
+ **\r
+ ** Function findAPI(win)\r
+ ** Inputs:  win - a Window Object\r
+ ** Return:  If an API object is found, it's returned, otherwise null is returned\r
+ **\r
+ ** Description:\r
+ ** This function looks for an object named API in parent and opener windows\r
+ **\r
+ *******************************************************************************/\r
+function findAPI(win) {\r
+    while ((win.API == null) && (win.parent != null) && (win.parent != win)) {\r
+        findAPITries++;\r
+        // Note: 7 is an arbitrary number, but should be more than sufficient\r
+        if (findAPITries > 7) {\r
+            fb("Error finding API -- too deeply nested.");\r
+            return null;\r
+        }\r
+\r
+        win = win.parent;\r
+\r
+    }\r
+    return win.API;\r
 }\r
 \r
 \r
-\r
 /*******************************************************************************\r
-**\r
-** Function getAPI()\r
-** Inputs:  none\r
-** Return:  If an API object is found, it's returned, otherwise null is returned\r
-**\r
-** Description:\r
-** This function looks for an object named API, first in the current window's \r
-** frame hierarchy and then, if necessary, in the current window's opener window\r
-** hierarchy (if there is an opener window).\r
-**\r
-*******************************************************************************/\r
-function getAPI()\r
-{\r
-   var theAPI = findAPI(window);\r
-   if ((theAPI == null) && (window.opener != null) && (typeof(window.opener) != "undefined"))\r
-   {\r
-      theAPI = findAPI(window.opener);\r
-   }\r
-   if (theAPI == null)\r
-   {\r
-      alert("Unable to find an API adapter");\r
-   }\r
-   return theAPI\r
+ **\r
+ ** Function getAPI()\r
+ ** Inputs:  none\r
+ ** Return:  If an API object is found, it's returned, otherwise null is returned\r
+ **\r
+ ** Description:\r
+ ** This function looks for an object named API, first in the current window's\r
+ ** frame hierarchy and then, if necessary, in the current window's opener window\r
+ ** hierarchy (if there is an opener window).\r
+ **\r
+ *******************************************************************************/\r
+function getAPI() {\r
+    var theAPI = findAPI(window);\r
+    if ((theAPI == null) && (window.opener != null) && (typeof(window.opener) != "undefined")) {\r
+        theAPI = findAPI(window.opener);\r
+    }\r
+    if (theAPI == null) {\r
+        fb("Unable to find an API adapter");\r
+    }\r
+    return theAPI\r
 }\r
 \r
 \r
 var startTime;\r
 \r
-function startTimer()\r
-{\r
-   startTime = new Date().getTime();\r
+function startTimer() {\r
+    startTime = new Date().getTime();\r
 }\r
 \r
\r
+\r
 // call function right before LMSFinish\r
 function setSessionTime() {\r
 \r
-      var currentTime = new Date();\r
+    var currentTime = new Date();\r
+\r
+    var endTime = currentTime.getTime()\r
+\r
+    var calculatedTime = endTime - startTime;\r
+\r
+    var totalHours = Math.floor(calculatedTime / 1000 / 60 / 60);\r
 \r
-      var endTime = currentTime.getTime()\r
-     \r
-      var calculatedTime = endTime-startTime;\r
+    calculatedTime = calculatedTime - totalHours * 1000 * 60 * 60\r
 \r
-      var totalHours = Math.floor(calculatedTime/1000/60/60);\r
+    if (totalHours < 1000 && totalHours > 99) {\r
 \r
-      calculatedTime = calculatedTime - totalHours*1000*60*60\r
+        totalHours = "0" + totalHours;\r
 \r
-      if ( totalHours < 1000 && totalHours > 99 ) {\r
+    } else if (totalHours < 100 && totalHours > 9) {\r
 \r
-            totalHours = "0"+totalHours;\r
+        totalHours = "00" + totalHours;\r
 \r
-      } else if ( totalHours < 100 && totalHours > 9 ) {\r
+    } else if (totalHours < 10) {\r
 \r
-            totalHours = "00"+totalHours;\r
+        totalHours = "000" + totalHours;\r
 \r
-      } else if ( totalHours < 10 ) {\r
+    }\r
 \r
-            totalHours = "000"+totalHours;\r
 \r
-      }\r
-     \r
+    var totalMinutes = Math.floor(calculatedTime / 1000 / 60);\r
 \r
-      var totalMinutes = Math.floor(calculatedTime/1000/60);\r
+    calculatedTime = calculatedTime - totalMinutes * 1000 * 60;\r
 \r
-      calculatedTime = calculatedTime - totalMinutes*1000*60;\r
+    if (totalMinutes < 10) {\r
 \r
-      if ( totalMinutes < 10 ) {\r
+        totalMinutes = "0" + totalMinutes;\r
 \r
-            totalMinutes = "0"+totalMinutes;\r
+    }\r
 \r
-      }\r
-     \r
 \r
-      var totalSeconds = Math.floor(calculatedTime/1000);\r
+    var totalSeconds = Math.floor(calculatedTime / 1000);\r
 \r
-      if ( totalSeconds < 10 ) {\r
+    if (totalSeconds < 10) {\r
 \r
-            totalSeconds = "0"+totalSeconds;\r
+        totalSeconds = "0" + totalSeconds;\r
 \r
-      }\r
+    }\r
 \r
-      var sessionTime = totalHours+":"+totalMinutes+":"+totalSeconds;\r
+    var sessionTime = totalHours + ":" + totalMinutes + ":" + totalSeconds;\r
 \r
-      doLMSSetValue("cmi.core.session_time", sessionTime);\r
+    doLMSSetValue("cmi.core.session_time", sessionTime);\r
 \r
 }\r
 \r
index b7a5d09d16df0f2dfa653d9842090c52ca032e50..cfa032c8af1b11eb3b8d3269a58ea27648793d86 100644 (file)
@@ -1,11 +1,42 @@
 SCORM = true;\r
 $(function () {\r
-    doLMSInitialize();\r
+    if (fluidbook) {\r
+        initScormEvents();\r
+    } else {\r
+        $(document).on('fluidbookready', function () {\r
+            initScormEvents();\r
+        });\r
+    }\r
+});\r
 \r
+function initScormEvents() {\r
+    doLMSInitialize();\r
     $(window).on('unload', function () {\r
         doLMSFinish();\r
     });\r
-});\r
+\r
+    var currentStatus = getScormValue('cmi.core.lesson_status');\r
+    if (currentStatus != 'passed' || currentStatus != 'completed') {\r
+        setScormValue('cmi.core.lesson_status', 'incomplete');\r
+    }\r
+\r
+    var currentPage = getScormValue('cmi.core.lesson_location');\r
+    try {\r
+        if (currentPage != '') {\r
+            var e = currentPage.split('_');\r
+            if (e.length == 2 && e[0] == 'page') {\r
+                fluidbook.setCurrentPage(e[1]);\r
+            }\r
+        }\r
+    } catch (err) {\r
+        fb(err);\r
+    }\r
+\r
+    $(fluidbook).on('changePage', function (e, page) {\r
+        setScormValue('cmi.core.lesson_location', 'page_' + page);\r
+        doLMSCommit();\r
+    });\r
+}\r
 \r
 \r
 function getScormValue(elementName) {\r
@@ -15,5 +46,6 @@ function getScormValue(elementName) {
 \r
 function setScormValue(elementName, value) {\r
     var result = doLMSSetValue(elementName, value);\r
+    doLMSCommit();\r
     return result;\r
 }
\ No newline at end of file
index f19429698f7985fa756a224639d4c9a0394978d7..cfce6f38df97a3ede7257342af6d9139bf99a1b5 100644 (file)
@@ -426,6 +426,7 @@ try {
             return true;
         });
 
+        $(document).trigger('fluidbookready');
 
         setTimeout(function () {
             resize();