home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 December / CMCD1203.ISO / Software / Shareware / Programare / toolkit / toolkitsetup.msi / Instal01.cab / _2DEA2F0175F14C6FB1A920254BD135C1 < prev    next >
Text File  |  2003-08-21  |  5KB  |  181 lines

  1. var apiHandle = null;
  2. var _NoError = 0, _GeneralException = 101, _ServerBusy = 102, _InvalidArgumentError = 201, _CannotHaveChildren = 202, _NotAnArray = 203, _NotInitialized = 301, _NotImplementedError = 401, _InvalidSetTime = 402, _ReadOnly = 403, _WriteOnly = 404, _IncorrectDataType = 405;
  3.  
  4. //Function: LMSInitialize()
  5. // Inputs:    None
  6. // Return:    true if the initialization was successful
  7. //        false if the initialization failed
  8. function LMSInitialize() 
  9. {
  10.     var api = getAPIHandle();
  11.     if(api == null)
  12.     {
  13.         alert("Unable to locate the LMS's API Implementation.\nLMSInitialize was not successful.");
  14.         return false;
  15.     }
  16.     var initResult = api.LMSInitialize("");
  17.     initResult = ConvertTF(initResult);
  18.     if(initResult != true)
  19.         alert("LMSInitialize was not successful.");
  20.     return initResult;
  21. }
  22.  
  23. //Function LMSFinish()
  24. // Inputs:    None
  25. // Return:    None
  26. function LMSFinish()
  27. {
  28.     var api = getAPIHandle();
  29.     if(api == null)
  30.         alert("Unable to locate the LMS's API Implementation.\nLMSFinish was not successful.");
  31.     else
  32.         api.LMSFinish("");
  33.     return;
  34. }
  35.  
  36. //Function LMSSetValue(theName, theValue) 
  37. // Inputs:    theName - string representing the cmi data model element
  38. //        theValue - the value that the named element or category will be assigned
  39. // Return:    None
  40. function LMSSetValue(theName, theValue) 
  41. {
  42.     var api = getAPIHandle();
  43.     if(api != null)
  44.     {
  45.         if(theName == "cmi.core.score")
  46.             theName = "cmi.core.score.raw";
  47.         api.LMSSetValue(theName, theValue);
  48.     }
  49.     return;
  50. }
  51.  
  52. //Function LMSGetValue(theName) 
  53. // Inputs:    theName - string representing the cmi data model defined category or element
  54. // Return:    Empty String
  55. function LMSGetValue(theName) 
  56. {
  57.     return "";
  58. }
  59.  
  60. //Function LMSCommit() 
  61. // Inputs:    None
  62. // Return:    None
  63. function LMSCommit()
  64. {
  65.     var api = getAPIHandle();
  66.     if(api != null)
  67.         api.LMSCommit("");
  68.     return;
  69. }
  70.  
  71. //Function LMSGetLastError() 
  72. // Inputs:    None
  73. // Return:    The error code (integer format) that was set by the last LMS function call
  74. function LMSGetLastError() 
  75. {
  76.     var api = getAPIHandle();
  77.     if(api == null)
  78.         return _GeneralException.toString();
  79.     return api.LMSGetLastError().toString();
  80. }
  81.  
  82. //Function LMSGetErrorString(errorCode)
  83. // Inputs:    errorCode - Error Code(integer format)
  84. // Return:    The textual description that corresponds to the input error code
  85. function LMSGetErrorString(errorCode) 
  86. {
  87.     var api = getAPIHandle();
  88.     return api.LMSGetErrorString(errorCode).toString();
  89. }
  90.  
  91. //Function LMSGetDiagnostic(errorCode) 
  92. // Inputs:    errorCode - Error Code(integer format), or null
  93. // Return:    The vendor specific textual description that corresponds to the input error code
  94. function LMSGetDiagnostic(errorCode) 
  95. {
  96.     var api = getAPIHandle();
  97.     return api.LMSGetDiagnostic(errorCode).toString();
  98. }
  99.  
  100. //Function ConvertTF()
  101. // Inputs: a string or other data type representing a boolean value
  102. // Return: a boolean value
  103. function ConvertTF(booleanToken)
  104. {
  105.     booleanStr = booleanToken.toString();
  106.     switch(booleanStr)
  107.     {
  108.         case "1": 
  109.         case "true":
  110.             realBoolean = true;
  111.             break;
  112.         case "false":
  113.         case "0":
  114.         default:
  115.             realBoolean = false;
  116.             break;
  117.     }
  118.     return realBoolean;
  119. }
  120.  
  121. //Function getAPIHandle()
  122. // Inputs:    None
  123. // Return:    value contained by APIHandle
  124. function getAPIHandle() 
  125. {
  126.     if(apiHandle == null)
  127.         apiHandle = getAPI();
  128.     return apiHandle;
  129. }
  130.  
  131. //Function findAPI(win)
  132. // Inputs:    win - a Window Object
  133. // Return:    If an API object is found, it is returned, otherwise null is returned
  134. function findAPI(win)
  135. {
  136.     if(win.API != null)
  137.         return win.API;
  138.  
  139.     if(win.length > 0)
  140.     {
  141.         for(var i=0; i<win.length; i++)
  142.         {
  143.             var theAPI = findAPI(win.frames[i]);
  144.             if(theAPI != null)
  145.                 return theAPI;
  146.         }
  147.     }
  148.     return null;
  149. }
  150.  
  151. //Function getAPI()
  152. // Inputs:    none
  153. // Return:    If an API object is found, it is returned, otherwise null is returned
  154. function getAPI()
  155. {
  156.     var theAPI = findAPI(this.top);
  157.     if(theAPI == null)
  158.         if(typeof(this.top.opener) != "undefined")
  159.             if(this.top.opener != null)
  160.                 theAPI = findAPI(this.top.opener.top);
  161.     return theAPI;
  162. }
  163.  
  164. //Function LMSIsInitialized() 
  165. // Inputs:    none
  166. // Return:    true if the LMS API is currently initialized, otherwise false
  167. function LMSIsInitialized()
  168. {
  169.     var api = getAPIHandle();
  170.     var theReturn = false;
  171.     if(api == null)
  172.     {
  173.         alert("Unable to locate the LMS's API Implementation.\nLMSIsInitialized() failed.");
  174.     }else{
  175.         var value = api.LMSGetValue("cmi.core.student_name");
  176.         var errCode = api.LMSGetLastError().toString();
  177.         if(errCode != _NotInitialized)
  178.             theReturn = true;
  179.     }
  180.     return theReturn;
  181. }