home *** CD-ROM | disk | FTP | other *** search
- /**
- * MenuBar 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 menu.js, which can be used with or w/o menubar.js
- */
-
- function MenuBar(width, height) {
- this.version = "0.3 [menubar.js 980210]";
- this.menuBarWidth = width;
- this.menuBarHeight = height;
- this.menuBarBgColor = '#C1CDCD'; //CDB79E
- this.menuBarParentLayer = null;
-
- this.setMenuBar = setMenuBar;
- this.addMenuBarItem = addMenuBarItem;
- this.moveMenuBarItem = moveMenuBarItem;
- this.moveMenuBar = moveMenuBar;
- this.onMenuBar = onMenuBar;
- this.setMenuBarWidth = setMenuBarWidth;
- this.setMenuBarHeight = setMenuBarHeight;
- this.setMenuBarBgColor = setMenuBarBgColor;
- this.resizeMenuBar = resizeMenuBar;
- this.hideMenuBarItems = hideMenuBarItems;
- }
-
- function setMenuBar() {
- if (this.menuBarParentLayer)
- this.bar = new Layer(0);
- else
- this.bar = new Layer(0);
- this.bar.document.bgColor = "#000000";
- this.bar.document.writeln(' ');
- this.bar.document.close();
- this.bar.clip.width = this.menuBarWidth || window.innerWidth || 100;
- this.bar.clip.height = this.menuBarHeight || 20;
- this.barWidth = this.bar.clip.width;
- this.bar.clip.height += 3;
- this.barHeight = this.bar.clip.height;
- this.bar.visibility = 'inherit';
- this.bar.shadow = makeLayer('m', ' ', this.bar, this.barWidth -1, this.barHeight -1, 0,0, '#888888');
- this.bar.lite = makeLayer('m', ' ', this.bar, this.barWidth -2, this.barHeight -2, 0,0, '#EEEEEE');
- this.bar.gray = makeLayer('m', ' ', this.bar, this.barWidth -3, this.barHeight -3, 1,1, this.menuBarBgColor);
- this.bar.focus = makeLayer('m', "", this.bar, 0,0, 2,2);
- this.bar.gray.saveBgColor = this.menuBarBgColor;
- this.bar.focus.captureEvents(Event.MOUSEUP);
- this.bar.focus.onmouseup = this.onMenuBar;
- this.bar.focus.ID = "focus";
- this.bar.focus.that = this;
- this.countItems = 0;
- this.items = new Array();
- this.activeMenuBarItems = new Array();
- if (!window.NMenuHide) {
- window.NMenuHide = true;
- }
- }
-
- function addMenuBarItem(item, action) {
- if (typeof(item) != 'string') {
- var label = item.menuLayer.label;
- this.items[label] = item;
- } else {
- var label = item;
- item = new Layer(0);
- this.items[label] = item;
- }
- if (label.indexOf("IMG") == -1) {
- var m = label.substring(0,1);
- label = label.substring(1);
- label = '<SPAN ID=sysFont> '+ '<U>' + m + '</U>' + label +' </SPAN>';
- }
- item.labelLayer = makeLayer('label', label, this.bar, 0,0, 1,1, null, "hide");
- item.labelLayer.focus = makeLayer('label', '<FONT COLOR="#FFFFFF">'+ label +'</FONT>', this.bar, 0,0, 1,1, '#000084');
- item.labelLayer.bar = this.bar;
- item.labelLayer.focus.item = item;
- if (this.items[this.countItems -1])
- item.labelLayer.left = this.items[this.countItems -1].left + this.items[this.countItems -1].clip.width +5;
- item.labelLayer.focus.left = item.labelLayer.left;
- item.labelLayer.visibility = 'inherit';
- item.labelLayer.focus.visibility = 'hide';
- item.labelLayer.onMouseOver = onMenuBarItem_MouseOver;
- item.labelLayer.onFocus = this.onMenuBar;
- item.labelLayer.focus.captureEvents(Event.MOUSEUP);
- item.labelLayer.focus.onmouseup = this.onMenuBar;
- item.labelLayer.focus.action = action;
- item.labelLayer.that = this;
- item.labelLayer.menuLayer = item.menuLayer;
- this.bar.focus.zIndex = item.labelLayer.focus.zIndex +1;
- this.items[this.countItems] = item.labelLayer;
- this.countItems++;
- }
-
- function onMenuBarItem_MouseOver(e) {
- if (window.hideMenus) {
- window.hideMenus();
- }
- this.parentLayer.focus.left = this.left;
- this.parentLayer.focus.clip.width = this.clip.width;
- this.parentLayer.focus.clip.height = this.clip.height;
- window.NActiveMenuBarItem = this;
- if (window.NMenuHide) {
- return;
- }
- this.focus.visibility = "inherit";
- onMenuBar(null,this);
- }
-
- function onMenuBar(e,l) {
- if (window.hideMenus) {
- window.hideMenus();
- }
- if (!l) {
- if (window.NActiveMenuBarItem) {
- l = window.NActiveMenuBarItem;
- } else {
- l = this;
- }
- if (window.NMenuHide) {
- window.NMenuHide = false;
- }
- if (l.action) {
- eval( l.action );
- }
- }
- if (l.that) {
- if (window.NActiveMenuBarItem) {
- l = window.NActiveMenuBarItem;
- } else if (l.that.hideMenuBarItems) {
- l.that.hideMenuBarItems();
- }
- }
- if (l.menuLayer) {
- var m = l.menuLayer;
- m.left = l.left + l.bar.left;
- m.top = l.top + l.clip.height + l.bar.top;
- if (l.that.previousLayer) {
- var p = l.that.previousLayer;
- if (p != l) {
- p.menuLayer.visibility = "hide";
- p.focus.visibility = "hide";
- m.visibility = "inherit";
- l.focus.visibility = "inherit";
- window.NMenuHide = false;
- } else if (m.visibility == "hide") {
- m.visibility = "inherit";
- l.focus.visibility = "inherit";
- } else {
- m.visibility = "hide";
- p.focus.visibility = "hide";
- window.NMenuHide = true;
- }
- } else {
- m.visibility = "inherit";
- l.focus.visibility = "inherit";
- }
- l.that.previousLayer = l;
- window.NActiveMenu = l.menuLayer;
-
- }
- }
-
- function hideMenuBarItems(menu) {
- menu = menu || this;
- for(var i=0; i < menu.activeMenuBarItems.length; i++) {
- menu.hideMenuBarItems[i].visibility = "hide";
- }
- menu.activeMenuBarItems.length = 0;
- if (window.NActiveMenuBarItem) {
- window.NActiveMenuBarItem.focus.visibility = "hide";
- window.NActiveMenuBarItem = null;
- }
- }
-
- function moveMenuBarItem(item, x, y) {
- if (typeof(item) == 'string') {
- item = this.items[item];
- }
- if (x) {
- item.labelLayer.left = x;
- item.labelLayer.focus.left = x;
- }
- if (y) {
- item.labelLayer.top = y;
- item.labelLayer.focus.top = y;
- }
- }
-
- function moveMenuBar(x,y) {
- if (x) this.bar.left = x;
- if (y) this.bar.top = y;
- }
-
- function resizeMenuBar(w) {
- this.bar.clip.width = w;
- this.bar.shadow.clip.width = w -1;
- this.bar.lite.clip.width = w -2;
- this.bar.gray.clip.width = w -3;
- }
-
- function setMenuBarWidth(i) {
- this.menuBarWidth = i;
- }
-
- function setMenuBarHeight(i) {
- this.menuBarHeight = i;
- }
-
- function setMenuBarBgColor(str) {
- this.menuBarBgColor = str;
- }
-
- function setMenuBarParentLayer(l) {
- this.menuBarParentLayer = l;
- }
-
- 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;
- }