home *** CD-ROM | disk | FTP | other *** search
- /**
- * Menu Class 0.3
- * by gary smith July 1997
- * Copyright (c) 1997-98 Netscape Communications Corp.
- *
- * Netscape grants you a royalty free license to use or modify this
- * software provided that this copyright notice appears on all copies.
- * This software is provided "AS IS," without a warranty of any kind.
- *
- * see also menubar.js, which can be used with or w/o menu.js
- */
-
- function Menu(label) {
- this.version = "0.3 [menu.js 980210]";
- this.label = label;
- this.menuBgColor = '#C1CDCD';
- this.separators = new Array();
- this.subMenus = new Array();
- this.subMenuIcons = new Array();
- this.countItems = 0;
- this.items = new Array();
-
- this.menuLayer = makeLayer(label, "", null, 5, 5, 0,-1, '#000000', "hide");
- this.menuLayer.label = this.label;
- this.menuLayer.edge = makeLayer('m', "", this.menuLayer, this.menuLayer.clip.width -1, this.menuLayer.clip.height -1, -1,-1, '#DDDDDD');
- this.menuLayer.dark = makeLayer('m', "", this.menuLayer, this.menuLayer.clip.width -1, this.menuLayer.clip.height -1, 1,1, '#888888');
- this.menuLayer.lite = makeLayer('m', "", this.menuLayer, this.menuLayer.clip.width -2, this.menuLayer.clip.height -2, 1,1, '#FFFFFF');
- this.menuLayer.main = makeLayer('m', "", this.menuLayer, this.menuLayer.clip.width -3, this.menuLayer.clip.height -3, 2,2, this.menuBgColor);
- this.menuLayer.hilite = makeLayer('m', "", this.menuLayer, 0,0, 2,2);
- this.menuLayer.focus = makeLayer('m', "", this.menuLayer, 0,0, 2,2, null, "hide");
- this.menuLayer.focus.captureEvents(Event.MOUSEDOWN);
- this.menuLayer.focus.onmousedown = onMenuItem;
- this.menuLayer.focus.onMouseOut = onMenuItem_MouseOut;
- this.menuLayer.main.saveBgColor = this.menuBgColor;
- this.menuLayer.that = this;
-
- this.addMenuItem = addMenuItem;
- this.addSeparator = addSeparator;
- this.updateMenu = updateMenu;
- this.setMenuBgColor = setMenuBgColor;
- this.menuLayeroveMenu = moveMenu;
- this.onMenuItem = onMenuItem;
- this.onMenuItem_MouseOver = onMenuItem_MouseOver;
- this.nsMenuObject = nsMenuObject;
- this.showMenu = showMenu;
- this.hideMenu = hideMenu;
- this.hideMenus = hideMenus;
- this.hideMenuItems = hideMenuItems;
- if (!window.NActiveMenus) {
- window.NActiveMenus = new Array();
- }
- }
-
- function addMenuItem(label, action) {
- var trueLabel = label;
- var label_focus = label;
- if (label.menuLayer) {
- label = trueLabel.menuLayer.label;
- label_focus = label;
- var subMenu = true;
- }
- if (label.indexOf("<DIV ID") == -1 || label != "<HR>") {
- label = '<NOBR><DIV ID=sysFont> '+ label +' </DIV></NOBR>';
- label_focus = '<NOBR><DIV ID=sysFont><FONT COLOR="white"> '+ label_focus +' </FONT></DIV></NOBR>';
- }
- var l = makeLayer('m', label, this.menuLayer, 0,0, 2,2);
- l.focus = makeLayer('m', label_focus, this.menuLayer, 0,0, 1,1);
- l.label = label;
- l.onMouseOver = onMenuItem_MouseOver;
- l.action = action;
- l.focus.visibility = "hide";
- if (this.items[this.countItems -1]) {
- l.top = this.items[this.countItems -1].top + this.items[this.countItems -1].clip.height +5;
- }
- if (l.clip.width > this.menuLayer.clip.width) {
- this.menuLayer.clip.width = l.clip.width;
- }
- if (subMenu) {
- l.subMenuIcon = makeLayer('m', '<IMG SRC="images/gs.gif">', this.menuLayer, 0,0, 1,1);
- l.subMenuIcon.clip.left += 3;
- l.subMenuIcon.top = l.top -2;
- l.subMenuIcon.subMenu = trueLabel.menuLayer;
- l.subMenu = trueLabel.menuLayer;
- l.subMenu.parentMenu = this.menuLayer;
- this.subMenus[this.subMenus.length] = trueLabel;
- this.subMenuIcons[this.subMenuIcons.length] = l.subMenuIcon;
- this.menuLayer.clip.width += 10;
- }
- l.clip.width -= 4;
- l.focus.top = l.top;
- this.menuLayer.clip.height = l.top + l.clip.height +5;
- this.menuLayer.edge.clip.height = this.menuLayer.clip.height;
- this.menuLayer.edge.clip.width = this.menuLayer.clip.width;
- this.menuLayer.dark.clip.height = this.menuLayer.clip.height -2;
- this.menuLayer.dark.clip.width = this.menuLayer.clip.width -2;
- this.menuLayer.lite.clip.height = this.menuLayer.clip.height -3;
- this.menuLayer.lite.clip.width = this.menuLayer.clip.width -3;
- this.menuLayer.main.clip.height = this.menuLayer.clip.height -4;
- this.menuLayer.main.clip.width = this.menuLayer.clip.width -4;
- this.menuLayer.hilite.clip.height = l.clip.height;
- this.menuLayer.hilite.clip.width = this.menuLayer.clip.width -4;
- this.menuLayer.focus.clip.height = l.clip.height;
- this.menuLayer.focus.clip.width = this.menuLayer.clip.width -4;
- this.menuLayer.focus.zIndex = l.focus.zIndex +1;
- this.items[trueLabel] = l;
- this.items[this.countItems] = l;
- this.countItems++;
- this.updateMenu();
- }
-
- function updateMenu() {
- for (var i in this.items) {
- this.items[i].clip.width = this.menuLayer.clip.width -6;
- }
- for (var i in this.separators) {
- this.separators[i].clip.width = this.menuLayer.clip.width -6;
- this.separators[i].dark.clip.width = this.menuLayer.clip.width -6;
- }
- for (var i in this.subMenuIcons) {
- this.subMenuIcons[i].left = this.menuLayer.clip.width -15;
- }
- }
-
-
- function addSeparator(label) {
- var l = makeLayer('m', "", this.menuLayer, 2,2, 3,2, "#FFFFFF");
- l.focus = makeLayer('m', "", this.menuLayer, 2,2, 3,2, "#FFFFFF", "hide");
- if (this.items[this.countItems -1])
- l.top = this.items[this.countItems -1].top + this.items[this.countItems -1].clip.height +5;
- if (l.clip.width > this.menuLayer.clip.width)
- this.menuLayer.clip.width = l.clip.width;
- l.dark = makeLayer('m', "", l, l.clip.width, 1, 0,0, '#999999');
- l.clip.width -= 4;
- this.items[label || "separator" + this.countItems] = l;
- this.separators[this.separators.length] = l;
- this.items[this.countItems] = l;
- this.countItems++;
- }
-
- function onMenuItem(e, l, p) {
- if (!l) {
- l = e.target.parentLayer || this.parentLayer;
- }
- if (window.NActiveMenuBarItem) {
- window.NActiveMenuBarItem.focus.visibility = "hide";
- }
- l.visibility = "hide";
- l.that.hideMenuItems(l.that,true);
- if (window.NActiveMenuItem) {
- eval( window.NActiveMenuItem.action );
- }
- window.NActiveMenuItem = null;
- window.NMenuHide = true;
- }
-
- function onMenuItem_MouseOver(e, l) {
- if (!l) {
- var l = e.target;
- }
- if (!l) return;
- l.parentLayer.activeMenuItem = l;
- l.parentLayer.that.hideMenuItems(l.parentLayer.that);
- l.focus.visibility = "inherit";
- l.parentLayer.hilite.bgColor = "#000084";
- l.parentLayer.hilite.top = l.top;
- l.parentLayer.focus.top = l.top;
- l.parentLayer.focus.visibility = "inherit";
- l.parentLayer.action = l;
- window.NActiveMenuItem = l;
- if (l.subMenu) {
- l.subMenu.zIndex = l.parentLayer.zIndex +1;
- l.subMenu.top = l.top + l.parentLayer.top;
- l.subMenu.left = l.parentLayer.left + l.parentLayer.clip.width -3;
- if (l.subMenu.left + l.subMenu.clip.width > window.innerWidth) {
- l.subMenu.left = l.parentLayer.left - l.subMenu.clip.width +15;
- }
- l.subMenu.visibility = "inherit";
- window.NActiveMenus[window.NActiveMenus.length] = l.subMenu;
- }
- }
-
- function onMenuItem_MouseOut(e,l) {
- l = l || this;
- l.parentLayer.hilite.bgColor = null;
- l.parentLayer.hilite.top = l.top;
- l.parentLayer.focus.top = l.top;
- l.visibility = "hide";
- if (window.NActiveMenuItem) {
- window.NActiveMenuItem.focus.visibility = "hide";
- }
- }
-
- function hideMenuItems(menu, parents) {
- if (!menu && window.NActiveMenus) {
- for (var i=0; i < window.NActiveMenus.length; i++) {
- window.NActiveMenus[i].visibility = "hide";
- }
- } else {
- for (var i=0; i < menu.countItems; i++) {
- menu.items[i].focus.visibility = "hide";
- }
- for (var i=0; i < menu.subMenuIcons.length; i++) {
- menu.subMenuIcons[i].subMenu.visibility = "hide";
- if (menu.subMenuIcons[i].subMenu.that.subMenuIcons.length) {
- menu.subMenuIcons[i].subMenu.that.hideMenuItems(menu.subMenuIcons[i].subMenu.that);
- }
- }
- if (parents && menu.menuLayer.parentMenu) {
- menu.menuLayer.parentMenu.visibility = "hide";
- menu.menuLayer.parentMenu.that.hideMenuItems(menu.menuLayer.parentMenu.that,true);
- }
- }
- }
-
- function hideMenus() {
- for(var i=0; i < window.NActiveMenus.length; i++) {
- window.NActiveMenus[i].visibility = "hide";
- }
- window.NActiveMenu = null;
- window.NActiveMenus.length = 0;
- }
-
- function moveMenu(x,y) {
- this.menuLayer.left = x;
- this.menuLayer.top = y;
- }
-
- function setMenuBgColor(str) {
- this.menuLayer.main.document.bgColor = str;
- this.menuLayer.main.saveBgColor = str;
- this.menuBgColor = str;
- }
-
- function nsMenuObject() {
- if (!window.nsMenuObjects) {
- window.nsMenuObjects = new Array();
- window.nsMenuObjects[0] = this;
- } else {
- window.nsMenuObjects[window.nsMenuObjects.length++] = this;
- }
- }
-
- function hideMenu(menu) {
- if (menu.menuLayer) {
- menu.menuLayer.visibility = "hide";
- } else {
- window.NMenuHide = true;
- if (window.NActiveMenu) {
- window.NActiveMenu.visibility = "hide";
- window.NActiveMenu.that.hideMenuItems(window.NActiveMenu.that, true);
- }
- if (window.NActiveMenuBarItem) {
- window.NActiveMenuBarItem.focus.visibility = "hide";
- }
- }
- }
-
- function showMenu(menu) {
- if (menu.menuLayer) {
- menu.menuLayer.visibility = "inherit";
- } else {
- window.NMenuHide = false;
- if (window.NActiveMenu)
- window.NActiveMenu.visibility = "inherit";
- if (window.NActiveMenuBarItem)
- window.NActiveMenuBarItem.focus.visibility = "inherit";
- }
- }
-
- function makeLayer(label, content, parentLyr, width, height, x, y, color, viso) {
- content = content || " ";
- if (parentLyr) {
- var l = new Layer(width || 0, parentLyr);
- } else {
- var l = new Layer(width || 0);
- }
- l.document.ids.font14.fontSize = 14;
- l.document.ids.sysFont.fontSize = 12;
- l.document.ids.sysFont.fontFamily = "Arial, Espy, sans-serif";
- l.document.open("text/html");
- l.document.writeln(content);
- l.document.close();
- l.label = label;
- if (x)
- l.left += x;
- if (y)
- l.top += y;
- if (color)
- l.bgColor = color;
- if (width)
- l.clip.width = width;
- if (height)
- l.clip.height = height;
- if (!viso)
- l.visibility = "inherit";
- return l;
- }