<p>This page contains all the code necessary to create a menu bar. Use your
browser's <code>View Source</code> option to see the full source code.</p>
<p>Note the last item link in the "Edit" menu. It opens a page in a new browser
window and uses an <code>onclick</code> event to deactivate the menu when
clicked.</p>
// Blur focus from the link to remove that annoying outline.
button.blur();
// Associate the named menu to this button if not already done.
if (!button.menu)
button.menu = document.getElementById(menuName);
// Reset the currently active button, if any.
if (activeButton && activeButton != button)
resetButton(activeButton);
// Toggle the button's state.
if (button.isDepressed)
resetButton(button);
else
depressButton(button);
return false;
}
function buttonMouseover(button, menuName) {
// If any other button menu is active, deactivate it and activate this one.
// Note: if this button has no menu, leave the active menu alone.
if (activeButton && activeButton != button) {
resetButton(activeButton);
if (menuName)
buttonClick(button, menuName);
}
}
function depressButton(button) {
var w, dw, x, y;
// Change the button's style class to make it look like it's depressed.
button.className = "menuButtonActive";
// For IE, set an explicit width on the first menu item. This will
// cause link hovers to work on all the menu's items even when the
// cursor is not over the link's text.
if (browser.isIE && !button.menu.firstChild.style.width) {
w = button.menu.firstChild.offsetWidth;
button.menu.firstChild.style.width = w + "px";
dw = button.menu.firstChild.offsetWidth - w;
w -= dw;
button.menu.firstChild.style.width = w + "px";
}
// Position the associated drop down menu under the button and
// show it. Note that the position must be adjusted according to
// browser, styling and positioning.
x = getPageOffsetLeft(button);
y = getPageOffsetTop(button) + button.offsetHeight;
if (browser.isIE) {
x += 2;
y += 2;
}
if (browser.isNS && browser.version < 6.1)
y--;
// Position and show the menu.
button.menu.style.left = x + "px";
button.menu.style.top = y + "px";
button.menu.style.visibility = "visible";
// Set button state and let the world know which button is
// active.