home *** CD-ROM | disk | FTP | other *** search
/ ftp.novell.com / 2014.06.ftp.novell.com.tar / ftp.novell.com / forge / camtasia.msi / Cabs.w1.cab / scormwrapper.js < prev    next >
Text File  |  2009-08-17  |  7KB  |  239 lines

  1. // SCORM 1.2 and SCORM 2004 API Wrapper
  2.  
  3. var MAX_PARENTS_TO_SEARCH = 500;
  4. var apiHandle             = null;
  5. var noAPIFound            = "false";
  6. var apiVersion;
  7.  
  8. /*******************************************************************************
  9. **
  10. ** This function is used to communicate with the API, if it is found.
  11. **
  12. ** Inputs:  String - Name of the api function to call
  13. **
  14. **         String - Name of the data model defined category or element value
  15. **
  16. **          String - The value that the named element or category will be
  17. **                   assigned
  18. **
  19. ** Return:  String - Value returned from the api call.
  20. **
  21. *******************************************************************************/
  22. function apiCall( functionCall, dmeName, dmeValue )
  23. {
  24.    var api = getAPIHandle();
  25.    var result;
  26.       
  27.    if( noAPIFound != "true" )
  28.    {
  29.       switch ( functionCall )
  30.       {
  31.          case "initialize":
  32.                var dmeName = "";
  33.             if ( apiVersion >=1 )
  34.             {
  35.                dmeName = "cmi.completion_status";
  36.                     result = api.Initialize("");            
  37.             }
  38.             else
  39.             {
  40.                dmeName = "cmi.core.lesson_status";
  41.                     result = api.LMSInitialize("");    
  42.             }
  43.             
  44.             if ( result == "true" )
  45.             {   
  46.                     if ( apiVersion >= 1 )
  47.                     {
  48.                         result = api.GetValue( dmeName );
  49.                     }
  50.                     else
  51.                     {
  52.                   result = api.LMSGetValue( dmeName );
  53.                     }
  54.             } 
  55.             break;
  56.          
  57.          case "terminate":
  58.             if ( apiVersion >= 1 )
  59.             {
  60.                result = api.Terminate("");
  61.             }
  62.             else
  63.             {
  64.                result = api.LMSFinish("");
  65.             }
  66.             break;
  67.          
  68.          case "getValue":
  69.             if ( apiVersion >=1 )
  70.             {
  71.                result = api.GetValue( dmeName );
  72.             }
  73.             else
  74.             {
  75.                result = api.LMSGetValue( dmeName );
  76.             }
  77.             break;
  78.          
  79.          case "setValue":
  80.             if ( apiVersion >= 1 )
  81.             {
  82.                result = api.SetValue( dmeName, dmeValue );
  83.             }
  84.             else
  85.             {
  86.                result = api.LMSSetValue( dmeName, dmeValue );
  87.             }
  88.             break;
  89.          
  90.          case "commit":
  91.             if ( apiVersion >= 1 )
  92.             {
  93.                result = api.Commit("");
  94.             }
  95.             else
  96.             {
  97.                result = api.LMSCommit("");
  98.             }
  99.             break;
  100.          
  101.          case "getLastError":
  102.             if ( apiVersion >= 1 )
  103.             {
  104.                result = api.GetLastError();
  105.             }
  106.             else
  107.             {
  108.                result = api.LMSGetLastError();
  109.             }
  110.             break;
  111.          
  112.          case "getErrorString":
  113.             if ( apiVersion >= 1 )
  114.             {
  115.                result = api.GetErrorString( errCode );
  116.             }
  117.             else
  118.             {
  119.                result = api.LMSGetErrorString( errCode );
  120.             }
  121.             break;
  122.          
  123.          case "getDiagnostic":
  124.             if ( apiVersion >= 1 )
  125.             {
  126.                result = api.GetDiagnostic( error );
  127.             }
  128.             else
  129.             {
  130.                result = api.LMSGetDiagnostic( errorCode );
  131.             }
  132.             break;
  133.       }
  134.       return result;
  135.    }
  136. }
  137.  
  138. /*******************************************************************************
  139. **
  140. ** Searches all the parents of a given window until it finds an object named "API_1484_11" or "API".
  141. ** If an object of that name is found, a reference to it is returned. Otherwise, this function
  142. ** returns null.
  143. **
  144. ** Inputs:  Object - The Window Object
  145. **
  146. ** Return:  Object - If the API object is found, it's returned, otherwise null
  147. **          is returned
  148. **
  149. *******************************************************************************/ 
  150. function findAPI( win )
  151. {
  152.     var findAPITries = 0;
  153.     var theAPI       = null;
  154.     // Search each parent window until we find the API, encounter a window with no parent / the 
  155.     // same as the current window, or have reached our MAX_PARENTS_TO_SEARCH to search threshold
  156.     
  157.     while ( ( win.API_1484_11 == null                  ) 
  158.           && ( win.API         == null                  ) 
  159.           && ( win.parent      != null                  ) 
  160.           && ( win.parent      != win                   ) 
  161.           && ( findAPITries    <= MAX_PARENTS_TO_SEARCH ) )
  162.     {
  163.         findAPITries++;
  164.         win = win.parent;
  165.     }
  166.     if ( win.API_1484_11 != null )
  167.     {
  168.         apiVersion = 1;
  169.         theAPI = win.API_1484_11;
  170.     }
  171.     else if ( win.API != null )
  172.     {
  173.         apiVersion = 0;
  174.         theAPI = win.API;    
  175.     }
  176.     return theAPI;
  177. }
  178.  
  179. /*******************************************************************************
  180. **
  181. ** This function looks for an object named API, first in the current window's
  182. ** frame hierarchy and then, if necessary, in the current window's opener window
  183. ** hierarchy (if there is an opener window).
  184. **
  185. ** Inputs:  none
  186. **
  187. ** Return:  Object - If the API object is found, it's returned, otherwise null
  188. **                   is returned
  189. **
  190. *******************************************************************************/
  191. function getAPI()
  192. {
  193.     var api = null;
  194.     // If there are any, search all the parents of the current window
  195.     if ( ( window.parent != null ) && ( window.parent != window ) )
  196.     {
  197.         api = findAPI( window.parent );    
  198.     }
  199.     // If no api was found in this window's chain of parents, then, if there is one, search all 
  200.     // the parents of the opener window
  201.     if ( ( api == null ) && ( window.top.opener != null ) )
  202.     {
  203.         api = findAPI( window.top.opener );    
  204.     }
  205.     if ( api == null )
  206.    {
  207.       alert( "Unable to locate the LMS's API Implementation.\n" + "Communication with the LMS will not occur." );
  208.       noAPIFound = "true";
  209.    }
  210.     
  211.     return api;
  212. }
  213.  
  214. /*******************************************************************************
  215. **
  216. ** Returns the handle to API object if it was previously set, otherwise it
  217. ** returns null
  218. **
  219. ** Inputs:  None
  220. **
  221. ** Return:  Object - The value contained by the apiHandle variable.
  222. **
  223. *******************************************************************************/
  224. function getAPIHandle()
  225. {
  226.    if ( apiHandle == null )
  227.    {
  228.       if ( noAPIFound == "false" )
  229.       {
  230.          apiHandle = getAPI();
  231.       }
  232.    }   
  233.    return apiHandle;
  234. }
  235.  
  236.  
  237.  
  238.  
  239.