preload.js
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 9k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. // preload.js
  2. //
  3. // This file contains the script necessary for the initial load of the page.
  4. // We want to minimize this size as much as possible to mitigate the initial
  5. // hit at load time.
  6. //
  7. /*-------------------------------------------------------------------------
  8. Purpose: Display a generic message box if we hit a script error.
  9. */
  10. function EatErrors(szMsg, szUrl, iLine)
  11. {
  12.     // Prevent scripting errors from displaying ugly messages
  13.     alert("An unexpected error occurred.nn" + szMsg + "n" + szUrl + "nLine: " + iLine);
  14.     window.event.returnValue = true;    // Suppress IE error messaging
  15. }
  16. /*-------------------------------------------------------------------------
  17. Purpose: Load the given script file into the tree
  18. */
  19. function LoadScriptFile(szScriptID, szUrl)
  20. {
  21.     // Is the script loaded?
  22.     if (null == g_docAll(szScriptID))
  23.     {
  24.         // No; create it
  25.         var elemScript = document.createElement("<SCRIPT id=" + szScriptID + " src='" + szUrl + "' language='javascript'></SCRIPT>");
  26.         if (elemScript)
  27.         {
  28.             // Load it by adding it to the body
  29.             document.body.insertBefore(elemScript);
  30.         }
  31.     }
  32. }
  33. /*-------------------------------------------------------------------------
  34. Purpose: Returns true or false for the given policy
  35. */
  36. function Dso_IsRestricted(szPolicy)
  37. {
  38.     var bResult;
  39.     
  40.     bResult = g_docAll.idCtlAppsDso.IsRestricted(szPolicy);
  41.     /* Fake version
  42.     // alert("IsRestricted: " + szPolicy);
  43.     
  44.     bResult = false;     // default
  45.     
  46.     switch (szPolicy)
  47.     {
  48.     case "ShowPostSetup":           bResult = true;     break;
  49.     case "NoRemovePage":            bResult = false;     break;
  50.     case "NoAddPage":               bResult = false;     break;
  51.     case "NoWindowsSetupPage":      bResult = false;     break;
  52.     case "NoAddFromCDorFloppy":     bResult = false;     break;
  53.     case "NoAddFromInternet":       bResult = false;     break;
  54.     case "NoAddFromNetwork":        bResult = false;     break;
  55.     case "NoComponents":            bResult = false;     break;
  56.     case "NoServices":              bResult = false;     break;
  57.     case "NoSupportInfo":           bResult = false;     break;
  58.     }
  59.     */
  60.     
  61.     return bResult;
  62. }
  63. // --------------------------------------------------------------------------------
  64. // --------------------------------------------------------------------------------
  65. /*-------------------------------------------------------------------------
  66. Purpose: Determine which page to show at startup
  67. */
  68. function _ParseCmdLine()
  69. {
  70.     var szCmdLine = g_docAll.idAppARP.commandLine;
  71.     
  72.     // The command line will be something like: 
  73.     //  "c:lfnpathdefault.hta <params>"
  74.     
  75.     var ichParam = szCmdLine.indexOf("default.hta") + 12;
  76.     var cch = szCmdLine.length;
  77.     while (ichParam < cch)
  78.     {
  79.         if (szCmdLine.charAt(ichParam) != ' ')
  80.             break;
  81.         ichParam++;
  82.     }
  83.     // First parameter is the button index indicating which page
  84.     // to open
  85.     var nPage = parseInt(szCmdLine.charAt(ichParam));
  86.     if (isNaN(nPage) || 2 < nPage)
  87.         nPage = g_iPageDefault;
  88.     // Set the page by pushing the button
  89.     g_docAll.idPlaces.currentButton = nPage;
  90. }
  91. /*-------------------------------------------------------------------------
  92. Purpose: Initialize the Places bar.
  93. */
  94. function _InitPlacesBar()
  95. {
  96.     var _idPlaces = g_docAll.idPlaces;
  97.     
  98.     if (Dso_IsRestricted("NoRemovePage"))
  99.     {
  100.         _idPlaces.ShowButton('idChangeRemove', false);
  101.         g_iPageDefault++;
  102.     }
  103.     if (Dso_IsRestricted("NoAddPage"))
  104.     {
  105.         _idPlaces.ShowButton('idAdd', false);
  106.         if (1 == g_iPageDefault)
  107.             g_iPageDefault++;
  108.     }
  109.         
  110.     if (Dso_IsRestricted("NoWindowsSetupPage"))
  111.     {
  112.         _idPlaces.ShowButton('idConfig', false);
  113.         if (2 == g_iPageDefault)
  114.             g_iPageDefault++;
  115.     }
  116. }
  117. /*-------------------------------------------------------------------------
  118. Purpose: Handle the 'onload' event for the whole page. 
  119.          This function processes the commandline paremeters passed in and launches 
  120.          the correct page. 
  121. */
  122. function Body_OnLoad()
  123. {
  124.     window.onerror = EatErrors;     // Catch onerror events
  125.     // Bind to some events
  126.     document.body.onkeydown = Body_OnKeyDown;
  127.     g_docAll.idBtnClose.onclick = _CloseWindow;
  128.     // Determine whether to make the Config page simply exec the OC Manager or not
  129.     var bExecOCMgr;
  130.     
  131.     bExecOCMgr = !g_docAll.idCtlAppsDso.ShowPostSetup;
  132.     
  133.     /* Fake version
  134.     bExecOCMgr = true;
  135.     */
  136.     // The 'ShowPostSetup' policy overrides this.  If this is true, show the config page.
  137.     if (Dso_IsRestricted("ShowPostSetup"))
  138.         bExecOCMgr = false;
  139.     else if (Dso_IsRestricted("NoServices"))
  140.         bExecOCMgr = true;
  141.     // Allow the places bar to switch to this page using ctrl-tab
  142.     // (normally clicking the button would exec the Optional Components Manager)
  143.     var _idPlaces = g_docAll.idPlaces;
  144.     
  145.     _idPlaces.SetExecButton("idConfig", bExecOCMgr);
  146.     // Set the width of the places column.  We set this once at start up.  We avoid
  147.     // expressions since those are more expensive.
  148.     //
  149.     // Trick: we need to set the width of the dummy image too, to make sure 
  150.     // idColPlaces isn't squeezed.
  151.     
  152.     g_docAll.idColPlaces.width = g_docAll.idPlaces.offsetWidth;
  153.     g_docAll.idImgDummy1.width = g_docAll.idPlaces.offsetWidth;
  154.     g_docAll.idImgDummy2.width = g_docAll.idPlaces.offsetWidth;
  155.     g_docAll.idImgDummy3.width = g_docAll.idPlaces.offsetWidth;
  156.     // Parse the command line and set the active page
  157.     _ParseCmdLine();
  158. }
  159. /*-------------------------------------------------------------------------
  160. Purpose: Handle the 'onkeydown' for the documents
  161. */
  162. function Body_OnKeyDown() 
  163. {
  164.     // Is this a F5 key?
  165.     if (KC_F5 == event.keyCode) 
  166.     {
  167.         // Call the correct refresh functions
  168.         switch (g_idCur)
  169.         {
  170.         case 'idChangeRemove':
  171.             Dso_Refresh("Remove");
  172.             break;
  173.         case 'idAdd':
  174.             Dso_Refresh("Categories");
  175.             Dso_Refresh("Add");
  176.             break;
  177.         case 'idConfig':
  178.             Dso_Refresh("ocsetup");
  179.             break;
  180.         }
  181.         // Block this event
  182.         event.returnValue=false;
  183.     }
  184. }
  185. function _CloseWindow()
  186. {
  187.     window.parent.close();
  188. }
  189. /*-------------------------------------------------------------------------
  190. Purpose: Switch pages based upon the given idElem (button id)
  191. */
  192. function _SetPage(idElem)
  193. {
  194.     // Load the corresponding script first
  195.     switch (idElem)
  196.     {
  197.     case 'idChangeRemove':
  198.         LoadScriptFile("idScriptRemove", "remove.js");
  199.         break;
  200.     case 'idAdd':
  201.         LoadScriptFile("idScriptAdd", "add.js");
  202.         break;
  203.     case 'idConfig':
  204.         LoadScriptFile("idScriptConfig", "config.js");
  205.         break;
  206.     }
  207.     // Clean up after the current page
  208.     switch (g_idCur)
  209.     {
  210.     case 'idChangeRemove':
  211.         Remove_Deactivate();
  212.         break;
  213.     case 'idAdd':
  214.         Add_Deactivate();
  215.         break;
  216.     case 'idConfig':
  217.         Config_Deactivate();
  218.         break;
  219.     }
  220.     // Now set up for the new page
  221.     switch (idElem)
  222.     {
  223.     case 'idChangeRemove':
  224.         Remove_Activate();
  225.         break;
  226.     case 'idAdd':
  227.         Add_Activate();
  228.         break;
  229.     case 'idConfig':
  230.         Config_Activate(false);
  231.         break;
  232.     }
  233.     g_idCur = idElem;
  234. }
  235. /*-------------------------------------------------------------------------
  236. Purpose: Handle the 'onexecitem' for the places bar.
  237. */
  238. function Places_OnExecItem()
  239. {
  240.     var idElem = window.event.srcID;
  241.     
  242.     if ('idConfig' == idElem)
  243.     {
  244.         LoadScriptFile("idScriptConfig", "config.js");
  245.         Config_Activate(true);
  246.     }
  247. }
  248. /*-------------------------------------------------------------------------
  249. Purpose: Handle the 'onselectitem' for the places bar
  250. */
  251. function Places_OnSelectItem()
  252. {
  253.     if (g_idCur == window.event.srcID)
  254.     {
  255.         switch (g_idCur)
  256.         {
  257.         case 'idChangeRemove':
  258.             Remove_SetFocus();
  259.             break;
  260.         case 'idAdd':
  261.             Add_SetFocus();
  262.             break;
  263.         case 'idConfig':
  264.             Config_SetFocus();
  265.             break;
  266.         }
  267.         return;
  268.     }
  269.     _SetPage(window.event.srcID);
  270. }
  271. /*-------------------------------------------------------------------------
  272. Purpose: Handle the 'onreadystatechange' for the places bar
  273. */
  274. function Places_OnComplete()
  275. {
  276.     // Depending on the speed of the machine, this event might get
  277.     // fired before the inline <SCRIPT> in default.hta is run.  If this
  278.     // is the case, then initialize g_docAll here, since this code uses 
  279.     // it.
  280.     if ("undefined" == typeof g_docAll)
  281.         g_docAll = document.all;
  282.         
  283.     _InitPlacesBar();
  284. }
  285. var KC_SPACE    = 32;
  286. var KC_RETURN   = 13;
  287. /*-------------------------------------------------------------------------
  288. Purpose: Handle the onKeyDown event
  289. */
  290. function _OnKeyDownFakeAnchor()
  291. {
  292.     var keyCode = window.event.keyCode;
  293.     if (KC_SPACE == keyCode || KC_RETURN == keyCode)
  294.     {
  295.         window.event.srcElement.click();
  296.     }
  297. }