Leaked source code of windows server 2003
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.

256 lines
8.5 KiB

  1. <!------------------------------------------------------------------------
  2. //
  3. // Copyright 2000 Microsoft Corporation. All Rights Reserved.
  4. //
  5. // File: SmartNav.js
  6. //
  7. // Description: this file implements a smart navigation mecanism
  8. //
  9. //----------------------------------------------------------------------->
  10. if (window.__smartNav == null)
  11. {
  12. window.__smartNav = new Object();
  13. window.__smartNav.update = function()
  14. {
  15. var sn = window.__smartNav;
  16. var fd;
  17. document.detachEvent("onstop", sn.stopHif);
  18. sn.inPost = false;
  19. try { fd = frames["__hifSmartNav"].document; } catch (e) {return;}
  20. var fdr = fd.getElementsByTagName("asp_smartnav_rdir");
  21. if (fdr.length > 0)
  22. {
  23. if (sn.sHif == null)
  24. {
  25. sn.sHif = document.createElement("IFRAME");
  26. sn.sHif.name = "__hifSmartNav";
  27. sn.sHif.style.display = "none";
  28. }
  29. try {window.location = fdr[0].url;} catch (e) {};
  30. return;
  31. }
  32. var fdurl = fd.location.href;
  33. if (fdurl == "javascript:smartnav=1" || fdurl == "about:blank")
  34. return;
  35. var fdurlb = fdurl.split("?")[0];
  36. if (document.location.href.indexOf(fdurlb) < 0)
  37. {
  38. document.location.href=fdurl;
  39. return;
  40. }
  41. if (sn.sHif != null)
  42. {
  43. sn.sHif.removeNode(true);
  44. sn.sHif = null;
  45. }
  46. var fd = frames["__hifSmartNav"].document;
  47. var hdm = document.getElementsByTagName("head")[0];
  48. var hk = hdm.childNodes;
  49. var tt = null;
  50. for (var i = hk.length - 1; i>= 0; i--)
  51. {
  52. if (hk[i].tagName == "TITLE")
  53. {
  54. tt = hk[i].outerHTML;
  55. continue;
  56. }
  57. if (hk[i].tagName != "BASEFONT" || hk[i].innerHTML.length == 0)
  58. hdm.removeChild(hdm.childNodes[i]);
  59. }
  60. var kids = fd.getElementsByTagName("head")[0].childNodes;
  61. for (var i = 0; i < kids.length; i++)
  62. {
  63. var tn = kids[i].tagName;
  64. var k = document.createElement(tn);
  65. k.id = kids[i].id;
  66. k.mergeAttributes(kids[i]);
  67. switch(tn)
  68. {
  69. case "TITLE":
  70. if (tt == kids[i].outerHTML)
  71. continue;
  72. k.innerText = kids[i].text;
  73. hdm.insertAdjacentElement("afterbegin", k);
  74. continue;
  75. case "BASEFONT" :
  76. if (kids[i].innerHTML.length > 0)
  77. continue;
  78. break;
  79. default:
  80. var o = document.createElement("BODY");
  81. o.innerHTML = "<BODY>" + kids[i].outerHTML + "</BODY>";
  82. k = o.firstChild;
  83. break;
  84. }
  85. hdm.appendChild(k);
  86. }
  87. document.body.clearAttributes();
  88. document.body.id = fd.body.id;
  89. document.body.mergeAttributes(fd.body);
  90. var newBodyLoad = fd.body.onload;
  91. if (newBodyLoad != null)
  92. document.body.onload = newBodyLoad;
  93. var s = "<BODY>" + fd.body.innerHTML + "</BODY>";
  94. if (sn.hif != null)
  95. {
  96. var hifP = sn.hif.parentElement;
  97. if (hifP != null)
  98. sn.sHif=hifP.removeChild(sn.hif);
  99. }
  100. document.body.innerHTML = s;
  101. var sc = document.scripts;
  102. for (var i = 0; i < sc.length; i++)
  103. {
  104. sc[i].text = sc[i].text;
  105. }
  106. sn.hif = document.all("__hifSmartNav");
  107. if (sn.hif != null)
  108. {
  109. var hif = sn.hif;
  110. sn.hifName = "__hifSmartNav" + (new Date()).getTime();
  111. frames["__hifSmartNav"].name = sn.hifName;
  112. sn.hifDoc = hif.contentWindow.document;
  113. if (sn.ie5)
  114. hif.parentElement.removeChild(hif);
  115. window.setTimeout(sn.restoreFocus,0);
  116. }
  117. if (typeof(window.onload) == "string")
  118. {
  119. try { eval(window.onload) } catch (e) {};
  120. }
  121. else if (window.onload != null)
  122. {
  123. try { window.onload() } catch (e) {};
  124. }
  125. sn.attachForm();
  126. };
  127. window.__smartNav.restoreFocus = function()
  128. {
  129. if (window.__smartNav.inPost == true) return;
  130. var curAe = document.activeElement;
  131. var sAeId = window.__smartNav.ae;
  132. if (sAeId==null || curAe!=null && (curAe.id==sAeId||curAe.name==sAeId))
  133. return;
  134. var ae = document.all(sAeId);
  135. if (ae == null) return;
  136. try { ae.focus(); } catch(e){};
  137. }
  138. window.__smartNav.saveHistory = function()
  139. {
  140. if (window.__smartNav.hif != null)
  141. window.__smartNav.hif.removeNode();
  142. if (window.__smartNav.sHif != null)
  143. document.all[window.__smartNav.siHif].insertAdjacentElement(
  144. "BeforeBegin", window.__smartNav.sHif);
  145. }
  146. window.__smartNav.stopHif = function()
  147. {
  148. document.detachEvent("onstop", window.__smartNav.stopHif);
  149. var sn = window.__smartNav;
  150. if (sn.hif != null)
  151. sn.hifDoc = sn.hif.contentWindow.document;
  152. if (sn.hifDoc != null)
  153. sn.hifDoc.execCommand("stop");
  154. }
  155. window.__smartNav.init = function()
  156. {
  157. var sn = window.__smartNav;
  158. document.detachEvent("onstop", sn.stopHif);
  159. document.attachEvent("onstop", sn.stopHif);
  160. if (sn.form.__InitDone == true) return;
  161. sn.form.__InitDone = true;
  162. try { if (window.event.returnValue == false) return;} catch(e) {}
  163. sn.inPost = true;
  164. if (document.activeElement != null)
  165. {
  166. var ae = document.activeElement.id;
  167. if (ae.length == 0)
  168. ae = document.activeElement.name;
  169. sn.ae = ae;
  170. }
  171. else
  172. sn.ae = null;
  173. try {document.selection.empty();} catch (e) {}
  174. if (sn.hif == null)
  175. {
  176. sn.hif = document.all("__hifSmartNav");
  177. sn.hifDoc = sn.hif.contentWindow.document;
  178. }
  179. if (sn.hifDoc != null)
  180. sn.hifDoc.designMode = "On";
  181. if (sn.hif.parentElement == null)
  182. document.body.appendChild(sn.hif);
  183. var hif = sn.hif;
  184. hif.detachEvent("onload", sn.update);
  185. hif.attachEvent("onload", sn.update);
  186. };
  187. window.__smartNav.submit = function()
  188. {
  189. window.__smartNav.init();
  190. window.__smartNav.form._submit();
  191. };
  192. window.__smartNav.attachForm = function()
  193. {
  194. var cf = document.forms;
  195. for (var i=0; i<cf.length; i++)
  196. {
  197. if (cf[i].__smartNavEnabled != null)
  198. {
  199. window.__smartNav.form = cf[i];
  200. break;
  201. }
  202. }
  203. var snfm = window.__smartNav.form;
  204. if (snfm == null) return false;
  205. var sft = snfm.target;
  206. if (sft.length != 0 && sft.indexOf("__hifSmartNav") != 0) return false;
  207. var sfc = snfm.action.split("?")[0];
  208. var url = window.location.href.split("?")[0];
  209. if (url.lastIndexOf(sfc) + sfc.length != url.length) return false;
  210. if (snfm.__formAttached == true) return true;
  211. snfm.__formAttached = true;
  212. snfm.attachEvent("onsubmit", window.__smartNav.init);
  213. snfm._submit = snfm.submit;
  214. snfm.submit = window.__smartNav.submit;
  215. snfm.target = window.__smartNav.hifName;
  216. return true;
  217. };
  218. window.__smartNav.hifName = "__hifSmartNav" + (new Date()).getTime();
  219. window.__smartNav.ie5 = navigator.appVersion.indexOf("MSIE 5") > 0;
  220. var rc = window.__smartNav.attachForm();
  221. var hif = document.all("__hifSmartNav");
  222. if (rc)
  223. {
  224. var fsn = frames["__hifSmartNav"];
  225. fsn.name = window.__smartNav.hifName;
  226. window.__smartNav.siHif = hif.sourceIndex;
  227. try {
  228. if (fsn.document.location != "javascript:smartnav=1")
  229. {
  230. fsn.document.designMode = "On";
  231. hif.attachEvent("onload",window.__smartNav.update);
  232. window.__smartNav.hif = hif;
  233. }
  234. }
  235. catch (e) { window.__smartNav.hif = hif; }
  236. window.attachEvent("onbeforeunload", window.__smartNav.saveHistory);
  237. }
  238. else
  239. window.__smartNav = null;
  240. }