Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

375 lines
9.3 KiB

  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.\n\n" + 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. bResult = g_docAll.idCtlAppsDso.IsRestricted(szPolicy);
  40. /* Fake version
  41. // alert("IsRestricted: " + szPolicy);
  42. bResult = false; // default
  43. switch (szPolicy)
  44. {
  45. case "ShowPostSetup": bResult = true; break;
  46. case "NoRemovePage": bResult = false; break;
  47. case "NoAddPage": bResult = false; break;
  48. case "NoWindowsSetupPage": bResult = false; break;
  49. case "NoAddFromCDorFloppy": bResult = false; break;
  50. case "NoAddFromInternet": bResult = false; break;
  51. case "NoAddFromNetwork": bResult = false; break;
  52. case "NoComponents": bResult = false; break;
  53. case "NoServices": bResult = false; break;
  54. case "NoSupportInfo": bResult = false; break;
  55. }
  56. */
  57. return bResult;
  58. }
  59. // --------------------------------------------------------------------------------
  60. // --------------------------------------------------------------------------------
  61. /*-------------------------------------------------------------------------
  62. Purpose: Determine which page to show at startup
  63. */
  64. function _ParseCmdLine()
  65. {
  66. var szCmdLine = g_docAll.idAppARP.commandLine;
  67. // The command line will be something like:
  68. // "c:\lfnpath\default.hta <params>"
  69. var ichParam = szCmdLine.indexOf("default.hta") + 12;
  70. var cch = szCmdLine.length;
  71. while (ichParam < cch)
  72. {
  73. if (szCmdLine.charAt(ichParam) != ' ')
  74. break;
  75. ichParam++;
  76. }
  77. // First parameter is the button index indicating which page
  78. // to open
  79. var nPage = parseInt(szCmdLine.charAt(ichParam));
  80. if (isNaN(nPage) || 2 < nPage)
  81. nPage = g_iPageDefault;
  82. // Set the page by pushing the button
  83. g_docAll.idPlaces.currentButton = nPage;
  84. }
  85. /*-------------------------------------------------------------------------
  86. Purpose: Initialize the Places bar.
  87. */
  88. function _InitPlacesBar()
  89. {
  90. var _idPlaces = g_docAll.idPlaces;
  91. if (Dso_IsRestricted("NoRemovePage"))
  92. {
  93. _idPlaces.ShowButton('idChangeRemove', false);
  94. g_iPageDefault++;
  95. }
  96. if (Dso_IsRestricted("NoAddPage"))
  97. {
  98. _idPlaces.ShowButton('idAdd', false);
  99. if (1 == g_iPageDefault)
  100. g_iPageDefault++;
  101. }
  102. if (Dso_IsRestricted("NoWindowsSetupPage"))
  103. {
  104. _idPlaces.ShowButton('idConfig', false);
  105. if (2 == g_iPageDefault)
  106. g_iPageDefault++;
  107. }
  108. }
  109. /*-------------------------------------------------------------------------
  110. Purpose: Handle the 'onload' event for the whole page.
  111. This function processes the commandline paremeters passed in and launches
  112. the correct page.
  113. */
  114. function Body_OnLoad()
  115. {
  116. window.onerror = EatErrors; // Catch onerror events
  117. if (document.dir == "rtl")
  118. {
  119. //
  120. // BiDi. Adjust alignment of the "Close", "CD or Floppy"
  121. // and "Windows Update" buttons
  122. //
  123. g_docAll.idTdClose.align = "left";
  124. g_docAll.idTdCDFloppy.align = "left";
  125. g_docAll.idTdWindowsUpdate.align = "left";
  126. }
  127. // Bind to some events
  128. document.body.onkeydown = Body_OnKeyDown;
  129. g_docAll.idBtnClose.onclick = _CloseWindow;
  130. // Determine whether to make the Config page simply exec the OC Manager or not
  131. var bExecOCMgr;
  132. bExecOCMgr = !g_docAll.idCtlAppsDso.ShowPostSetup;
  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. _idPlaces.SetExecButton("idConfig", bExecOCMgr);
  145. // Set the width of the places column. We set this once at start up. We avoid
  146. // expressions since those are more expensive.
  147. //
  148. // Trick: we need to set the width of the dummy image too, to make sure
  149. // idColPlaces isn't squeezed.
  150. g_docAll.idColPlaces.width = g_docAll.idPlaces.offsetWidth;
  151. g_docAll.idImgDummy1.width = g_docAll.idPlaces.offsetWidth;
  152. g_docAll.idImgDummy2.width = g_docAll.idPlaces.offsetWidth;
  153. g_docAll.idImgDummy3.width = g_docAll.idPlaces.offsetWidth;
  154. // Parse the command line and set the active page
  155. _ParseCmdLine();
  156. }
  157. /*-------------------------------------------------------------------------
  158. Purpose: Handle the 'onkeydown' for the documents
  159. */
  160. function Body_OnKeyDown()
  161. {
  162. // Is this a F5 key?
  163. if (KC_F5 == event.keyCode)
  164. {
  165. // Call the correct refresh functions
  166. switch (g_idCur)
  167. {
  168. case 'idChangeRemove':
  169. Dso_Refresh("Remove");
  170. break;
  171. case 'idAdd':
  172. Dso_Refresh("Categories");
  173. Dso_Refresh("Add");
  174. break;
  175. case 'idConfig':
  176. Dso_Refresh("ocsetup");
  177. break;
  178. }
  179. // Block this event
  180. event.returnValue=false;
  181. }
  182. }
  183. function _CloseWindow()
  184. {
  185. window.parent.close();
  186. }
  187. /*-------------------------------------------------------------------------
  188. Purpose: Switch pages based upon the given idElem (button id)
  189. */
  190. function _SetPage(idElem)
  191. {
  192. // Load the corresponding script first
  193. switch (idElem)
  194. {
  195. case 'idChangeRemove':
  196. LoadScriptFile("idScriptRemove", "remove.js");
  197. break;
  198. case 'idAdd':
  199. LoadScriptFile("idScriptAdd", "add.js");
  200. break;
  201. case 'idConfig':
  202. LoadScriptFile("idScriptConfig", "config.js");
  203. break;
  204. }
  205. // Clean up after the current page
  206. switch (g_idCur)
  207. {
  208. case 'idChangeRemove':
  209. Remove_Deactivate();
  210. break;
  211. case 'idAdd':
  212. Add_Deactivate();
  213. break;
  214. case 'idConfig':
  215. Config_Deactivate();
  216. break;
  217. }
  218. // Now set up for the new page
  219. switch (idElem)
  220. {
  221. case 'idChangeRemove':
  222. Remove_Activate();
  223. break;
  224. case 'idAdd':
  225. Add_Activate();
  226. break;
  227. case 'idConfig':
  228. Config_Activate(false);
  229. break;
  230. }
  231. g_idCur = idElem;
  232. }
  233. /*-------------------------------------------------------------------------
  234. Purpose: Handle the 'onexecitem' for the places bar.
  235. */
  236. function Places_OnExecItem()
  237. {
  238. var idElem = window.event.srcID;
  239. if ('idConfig' == idElem)
  240. {
  241. LoadScriptFile("idScriptConfig", "config.js");
  242. Config_Activate(true);
  243. }
  244. }
  245. /*-------------------------------------------------------------------------
  246. Purpose: Handle the 'onselectitem' for the places bar
  247. */
  248. function Places_OnSelectItem()
  249. {
  250. if (g_idCur == window.event.srcID)
  251. {
  252. switch (g_idCur)
  253. {
  254. case 'idChangeRemove':
  255. Remove_SetFocus();
  256. break;
  257. case 'idAdd':
  258. Add_SetFocus();
  259. break;
  260. case 'idConfig':
  261. Config_SetFocus();
  262. break;
  263. }
  264. return;
  265. }
  266. _SetPage(window.event.srcID);
  267. }
  268. /*-------------------------------------------------------------------------
  269. Purpose: Handle the 'onreadystatechange' for the places bar
  270. */
  271. function Places_OnComplete()
  272. {
  273. // Depending on the speed of the machine, this event might get
  274. // fired before the inline <SCRIPT> in default.hta is run. If this
  275. // is the case, then initialize g_docAll here, since this code uses
  276. // it.
  277. if ("undefined" == typeof g_docAll)
  278. g_docAll = document.all;
  279. _InitPlacesBar();
  280. }
  281. var KC_SPACE = 32;
  282. var KC_RETURN = 13;
  283. /*-------------------------------------------------------------------------
  284. Purpose: Handle the onKeyDown event
  285. */
  286. function _OnKeyDownFakeAnchor()
  287. {
  288. var keyCode = window.event.keyCode;
  289. if (KC_SPACE == keyCode || KC_RETURN == keyCode)
  290. {
  291. window.event.srcElement.click();
  292. }
  293. }