Here is the source code for the navigation menu. The code relies on a portion
of the pathname to identify the appropriate menu. This works for a small site
such as this but would be replaced with a more structure scheme in a more
complex environment. Timers are used to attempt "intelligent" decision-making about when to
activate the menus.
The source presented here is modified slightly from the actual code both
for content and formatting in this window.
// version 2001110600 change menu name stub code - uses pathname instead // of hostname et al in order to get around various // implementations showing or not showing port port // numbers when and when not port=80 // add delay of menu display - nowshow() called from showmenu // mydiv and obj now GLOBAL for nowshow() from showmenu() // protect hidemenus() if currmenu is NOT set (i.e. mouseout // before it ever gets set) var rootdir = "d.holmes/"; // top level of URL - used to trim pathname // to get menu name stub in whatmenu() // NOTE that using pathname instead of hostname // etc. gets around the various interpretations // of whether port appears in host and/or is // ever null etc. // NOTE2 that MSIE drops leading / while NS does not var showdelay = 70; // delay to ignore transients (mouseover-mouseout) var hidedelay = 1500; // delay until hide after mouseout var timeout = 7000; // timeout if no activity after initial top link // mouseover var mx = -1; // set for each menu var my = -1; // set once by first menu called var menuholdID // timer until menu re-hidden var currmenu = "x"; // currently displayed menu; "x" => none visible var mydiv // used for initial test IE vs NS // additional tests check specific functionality var whoami = navigator.userAgent + ''; var obj; function hold() { clearTimeout(menuholdID); } function drop() { clearTimeout(menuholdID); menuholdID = setTimeout("hidemenus()", hidedelay); } function hidemenus() { clearTimeout(menuholdID); if (currmenu != "x") { if (!document.all && document.getElementById) { // NS6 myobj = "div" + currmenu; obj = document.getElementById(myobj); obj.style.visibility = "hidden"; } else if (whoami.indexOf('MSIE')==-1) { obj = eval("document.div"+currmenu); // current drop menu obj.visibility = 'hidden'; } else { obj = eval("document.all.div"+currmenu+".style"); obj.visibility = 'hidden'; } currmenu = "x"; // mark currmenu as "all hidden" } } function showmenu(event,mythis) { clearTimeout(menuholdID); var a = mythis.pathname.indexOf(rootdir) + rootdir.length; var b = a + 4; // right index for substring cut mydiv = mythis.pathname.substring(a,b); // just the path with or without leading '/' // used to id the menu DIVs (home is // special-cased) for example: home phot // port art2 hard if (mydiv == "") { mydiv = "home"; } if(isNaN(mx)) { mx = -1; my = -1; } if (mydiv != currmenu) { if (!document.all && document.getElementById) { // NS6 mx = event.pageX - 20; mx = ((mx < 10) ? 10 : mx); if (my == -1) { // once "my" is set use it for both my = ((event.pageY < 20) ? 20 : event.pageY); } myobj = "div" + mydiv; obj = document.getElementById(myobj); obj.style.left = mx; obj.style.top = my + 10 ; menuholdID = setTimeout("nowshow()", showdelay); } else if (whoami.indexOf('MSIE')==-1) { mx = event.pageX - 20; mx = ((mx < 10) ? 10 : mx); if (my == -1) { // once "my" is set use it for both my = ((event.pageY < 20) ? 20 : event.pageY); } obj = eval("document.div"+mydiv); obj.pageX = mx; obj.pageY = my + 10 ; menuholdID = setTimeout("nowshow()", showdelay); } else { mx = window.event.clientX - 20; mx = ((mx < 10) ? 10 : mx); if (my == -1) { // once "my" is set use it for both my = ((window.event.clientY < 20) ? 20 : window.event.clientY); } obj = eval("document.all.div"+mydiv+".style"); obj.pixelLeft = mx; obj.pixelTop = my + 10 ; menuholdID = setTimeout("nowshow()", showdelay); } // NS or IE } // mydiv != currmenu } // showmenu function nowshow() { clearTimeout(menuholdID); if (!document.all && document.getElementById) { // NS6 obj.style.visibility = 'visible'; } else { obj.visibility = 'visible'; } if (currmenu != "x") { if (!document.all && document.getElementById) { // NS6 myobj = "div" + currmenu obj = document.getElementById(myobj); obj.style.visibility = 'hidden'; } else if (whoami.indexOf('MSIE')==-1) { obj.visibility = 'visible'; obj = eval("document.div"+currmenu); obj.visibility = 'hidden'; } else { obj.visibility = 'visible'; obj = eval("document.all.div"+currmenu+".style"); obj.visibility = 'hidden'; } } currmenu = mydiv; // default timeout on drop menus if there's no movement/change menuholdID = setTimeout("hidemenus()", timeout); } function makeMenus() { // writes HTML for menu DIVs // remember to update CSS as well document.write (' <DIV id="divhome"> \ <TABLE CELLPADDING=6 class="menutbl"> \ <TR><TD> \ <A class="menulink" onMouseOver="hold();" onMouseOut="drop();" \ HREF="/one/top_one.html" TARGET="_top">top one</A><BR> \ <A class="menulink" onMouseOver="hold();" onMouseOut="drop();" \ HREF="/two/top_two.html" TARGET="_top">top two</A><BR> \ <A class="menulink" onMouseOver="hold();" onMouseOut="drop();" \ HREF="/one/top_three.html" TARGET="_top">top three</A><BR> \ </TD></TR></TABLE> \ </DIV> \ \ <DIV id="divphot"> \ <TABLE CELLPADDING=6 class="menutbl"> \ <TR><TD> \ <A class="menulink" onMouseOver="hold();" onMouseOut="drop();" \ HREF="/aaa/second_one.html" TARGET="_top">second one</A><BR> \ <A class="menulink" onMouseOver="hold();" onMouseOut="drop();" \ HREF="/bbb/second_two.html" TARGET="_top">second two</A><BR> \ </TD></TR></TABLE> \ </DIV> \ \ }