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.

205 lines
6.8 KiB

  1. <!------------------------------------------------------------------------
  2. //
  3. // Copyright 2000 Microsoft Corporation. All Rights Reserved.
  4. //
  5. // File: SmartNavie5.js
  6. //
  7. // Description: this file implements a smart navigation mecanism for IE5.0
  8. //
  9. //----------------------------------------------------------------------->
  10. if (window.__smartNav == null && (window.parent.__smartNav == null
  11. || window.parent.frames["__hifSmartNav"] != window))
  12. {
  13. var sn = new Object();
  14. window.__smartNav = sn;
  15. sn.hif = document.all("__hifSmartNav");
  16. sn.siHif = sn.hif.sourceIndex;
  17. sn.update = function()
  18. {
  19. var sn = window.__smartNav;
  20. if (sn.xmli.XMLDocument.readyState < 4 || sn.updated == true)
  21. return;
  22. sn.updated = true;
  23. try { fd = frames["__hifSmartNav"].document; } catch (e) {return;}
  24. var fdr = fd.getElementsByTagName("asp_smartnav_rdir");
  25. if (fdr.length > 0)
  26. {
  27. if (sn.sHif == null)
  28. {
  29. sn.sHif = document.createElement("IFRAME");
  30. sn.sHif.name = "__hifSmartNav";
  31. sn.sHif.style.display = "none";
  32. }
  33. try {window.location = fdr[0].url;} catch (e) {};
  34. return;
  35. }
  36. var fdurl = fd.location.href;
  37. if (fdurl == "javascript:smartnav=1")
  38. return;
  39. var fdurlb = fdurl.split("?")[0];
  40. if (document.location.href.indexOf(fdurlb) < 0)
  41. {
  42. document.location.href=fdurl;
  43. return;
  44. }
  45. var hdm = document.getElementsByTagName("head")[0];
  46. var hk = hdm.childNodes;
  47. for (var i = hk.length - 1; i>= 0; i--)
  48. {
  49. if (hk[i].tagName != "BASEFONT" || hk[i].innerHTML.length == 0)
  50. hdm.removeChild(hdm.childNodes[i]);
  51. }
  52. var kids = fd.getElementsByTagName("head")[0].childNodes;
  53. for (var i = 0; i < kids.length; i++)
  54. {
  55. var tn = kids[i].tagName;
  56. var k = document.createElement(tn);
  57. k.id = kids[i].id;
  58. switch(tn)
  59. {
  60. case "TITLE":
  61. k.innerText = kids[i].text;
  62. hdm.insertAdjacentElement("afterbegin", k);
  63. continue;
  64. case "BASEFONT" :
  65. if (kids[i].innerHTML.length > 0)
  66. continue;
  67. k.mergeAttributes(kids[i]);
  68. break;
  69. default:
  70. var o = document.createElement("BODY");
  71. o.innerHTML = "<BODY>" + kids[i].outerHTML + "</BODY>";
  72. k = o.firstChild;
  73. k.mergeAttributes(kids[i]);
  74. break;
  75. }
  76. hdm.appendChild(k);
  77. }
  78. var colSelect = document.body.getElementsByTagName("SELECT");
  79. for (var i = 0; i < colSelect.length; i ++)
  80. colSelect[i].removeNode(true);
  81. var obody = document.body;
  82. sn.sHif = sn.hif;
  83. obody.insertAdjacentElement("beforeBegin", sn.hif);
  84. obody.innerHTML = fd.body.innerHTML;
  85. obody.clearAttributes();
  86. obody.id = fd.body.id;
  87. obody.mergeAttributes(fd.body);
  88. window.setTimeout(sn.restoreFocus, 0);
  89. sn.attachForm();
  90. };
  91. window.__smartNav.restoreFocus = function()
  92. {
  93. var curAe = document.activeElement;
  94. var sAeId = window.__smartNav.ae;
  95. if (sAeId==null || curAe!=null && (curAe.id==sAeId||curAe.name==sAeId))
  96. return;
  97. var ae = document.all(sAeId);
  98. if (ae == null) return;
  99. try { ae.focus(); } catch(e){};
  100. }
  101. window.__smartNav.saveHistory = function()
  102. {
  103. if (window.__smartNav.sHif != null)
  104. {
  105. if (window.__smartNav.hif != null)
  106. window.__smartNav.hif.parentElement.removeChild(window.__smartNav.hif);
  107. document.all[window.__smartNav.siHif].insertAdjacentElement(
  108. "beforeBegin", window.__smartNav.sHif);
  109. }
  110. }
  111. window.__smartNav.init = function()
  112. {
  113. try { if (window.event.returnValue == false) return;} catch(e) {}
  114. var sn = window.__smartNav;
  115. if (document.activeElement != null)
  116. {
  117. var ae = document.activeElement.id;
  118. if (ae.length == 0)
  119. ae = document.activeElement.name;
  120. sn.ae = ae;
  121. }
  122. else
  123. sn.ae = null;
  124. if (document.selection.type != "None")
  125. try {document.selection.empty();} catch (e) {}
  126. var hif = sn.sHif;
  127. try { if (hif) hif.parentElement.removeChild(hif);} catch(e){}
  128. sn.hif = document.all["__hifSmartNav"];
  129. if (sn.hif.tagName != "IFRAME")
  130. sn.hif = window.__smartNav.hif[0];
  131. sn.hifName = "__hifSmartNav" + (new Date()).getTime();
  132. frames["__hifSmartNav"].name = sn.hifName;
  133. sn.form.target = sn.hifName;
  134. sn.updated = false;
  135. };
  136. window.__smartNav.submit = function()
  137. {
  138. window.__smartNav.init();
  139. window.__smartNav.form._submit();
  140. };
  141. window.__smartNav.attachForm = function()
  142. {
  143. var cf = document.forms;
  144. var sn = window.__smartNav;
  145. for (var i=0; i<cf.length; i++)
  146. {
  147. if (cf[i].__smartNavEnabled != null)
  148. {
  149. sn.form = cf[i];
  150. break;
  151. }
  152. }
  153. if (sn.form == null)
  154. return false;
  155. var sft = sn.form.target;
  156. if (sft.length != 0 && sft != "__hifSmartNav") return false;
  157. var sfc = sn.form.action.split("?")[0];
  158. var url = window.location.href.split("?")[0];
  159. if (url.lastIndexOf(sfc) + sfc.length != url.length) return false;
  160. if (sn.form.__formAttached == true) return true;
  161. sn.form.__formAttached = true;
  162. sn.form.attachEvent("onsubmit", sn.init);
  163. sn.form._submit = sn.form.submit;
  164. sn.form.submit = sn.submit;
  165. return true;
  166. };
  167. sn.sFn = "if (document.readyState != 'complete')"
  168. + "return;"
  169. + "var wpd = window.parent.document;"
  170. + "var xmli = wpd.createElement('XML');"
  171. + "wpd.body.appendChild(xmli);"
  172. + "window.parent.__smartNav.xmli = xmli;"
  173. + "xmli.onreadystatechange=window.parent.__smartNav.update;"
  174. + "xmli.src = '';";
  175. var rc = sn.attachForm();
  176. if (rc)
  177. window.attachEvent("onbeforeunload", sn.saveHistory);
  178. else
  179. window.__smartNav = null;
  180. }
  181. if (window.parent != window && window.parent.__smartNav != null
  182. && window.parent.frames["__hifSmartNav"] == window)
  183. {
  184. var f = new Function(window.parent.__smartNav.sFn);
  185. document.attachEvent("onreadystatechange", f);
  186. }