home *** CD-ROM | disk | FTP | other *** search
- // +------------------------------------------------------------+
- // | yx_menu Version 7 |
- // | Copyright 1999 Xin Yang yangxin@iname.com |
- // | Created 11/18/1999 Last Modified 04/11/2000 |
- // | Web Site: http://yx.webprovider.com |
- // +------------------------------------------------------------+
- // | Copyright 1999,2000 Xin Yang All Rights Reserved. |
- // +------------------------------------------------------------+
- // | For personal purpose, send me your URL and put a link back |
- // | to my web site, then you can use this script free. |
- // | |
- // | For commercial purpose, obtain quotation for referencing, |
- // | using, hosting, selling or distributing this script. |
- // | |
- // | In all cases copyright must remain intact. |
- // +------------------------------------------------------------+
-
- // Script begins
-
- var isIE4 = false;
- var isNN4 = false;
-
- var flagMenu = "M";
- var flagLink = "L";
- var flagInfo = "I";
- var flagCommand = "C";
- var flagSeparator = "S";
-
- var charWidth = 7; // character width
- var charHeight = 15; // character height
- var colorNormal = "#cccccc"; // menu pad color
- var colorHighlighted = "#ffffff"; // menu highlighted item color
- var colorTopLine = "#999999"; // separator upper line color
- var colorBottomLine = "#ffffff"; // separator lower line color
-
- var colorContent = "#ffffff"; // content box background color
- var colorBorder = "#666666"; // content box border color
- var contentPadding = 5; // content box padding
-
- var borderSize = 1;
- var marginSize = 4;
- var marginString = " ";
- var subMenuFlagSize = 4;
-
- var menuShown = -1;
- var itemOn = false;
- var nnWidth = 0, nnHeight = 0;
-
- var menuItemCount = -1;
- var menuItem = new Array();
- var menuFolderCount = -1;
- var menuFolder = new Array();
- var menuFolderSwitch = new Array();
- var menuWidth = new Array();
- var itemLayer = new Array();
- var menuLayer = new Array();
-
- var mouseX = 0;
- var mouseY = 0;
-
- var contentSwitch = 0;
- var contentID = "Content";
- var contentShown = false;
-
- function launchPage(pageURL) {
- //document.location.assign(pageURL);
- alert(pageURL);
- }
-
- function launchCommand(commandString) {
- //eval(commandString);
- alert(commandString);
- }
-
- function clickMenu(menuNum,itemIndex) {
- var menuIndex = menuItem[menuNum][itemIndex].myFolder;
- var folderIndex = menuItem[menuNum][itemIndex].folder;
- var itemX = menuItem[menuNum][itemIndex].x;
- var itemY = menuItem[menuNum][itemIndex].y;
- var menuX = itemX + menuWidth[menuNum][menuIndex] * charWidth + subMenuFlagSize;
-
- if (menuItem[menuNum][itemIndex].type == flagMenu) {
- if (menuFolderSwitch[menuNum][folderIndex])
- hideMenu(menuNum,folderIndex)
- else
- showMenu(menuNum,folderIndex,menuX,itemY);
- }
- else if (menuItem[menuNum][itemIndex].type == flagInfo) {
- if (contentShown)
- hideContent()
- else
- showContent(menuNum,itemIndex,menuX,itemY);
- }
- else if (menuItem[menuNum][itemIndex].type == flagLink) {
- closeMenu(menuNum);
- launchPage(menuItem[menuNum][itemIndex].url);
- }
- else if (menuItem[menuNum][itemIndex].type == flagCommand) {
- closeMenu(menuNum);
- launchCommand(menuItem[menuNum][itemIndex].command);
- }
- }
-
- function hideContent() {
- var contentxID = contentID + (1 - contentSwitch) + "";
-
- hideLayer(contentxID);
- contentShown = false;
- }
-
- function showContent(menuNum,itemIndex,menuX,menuY) {
- var menuIndex = menuItem[menuNum][itemIndex].myFolder;
- var contentImage = '<img src="a_pixel.gif" width=1 height=1 border=0>';
- var borderLine = '<tr><td bgcolor=' + colorBorder + ' colspan=3 height=' + borderSize + '>' + contentImage + '</td></tr>';
- var contentString = '<table align=center cellpadding=0 cellspacing=0 border=0>' + borderLine + '<tr><td bgcolor=' + colorBorder + ' width=' + borderSize + '>' + contentImage + '</td><td align=center valign=top><table bgcolor=' + colorContent + ' width=' + menuItem[menuNum][itemIndex].width + ' align=center cellpadding=' + contentPadding + ' cellspacing=0 border=0><tr align=left valign=top><td><span id="contentText">' + menuItem[menuNum][itemIndex].description + '</span></td></tr></table></td><td bgcolor=' + colorBorder + ' width=' + borderSize + '>' + contentImage + '</td></tr>' + borderLine + '</table>';
- var content0ID = contentID + (1 - contentSwitch) + "";
- var content1ID = contentID + contentSwitch + "";
-
- contentSwitch = 1 - contentSwitch;
- contentShown = true;
-
- if (isIE4) {
- document.all[content1ID].innerHTML = contentString;
- document.all[content1ID].style.zIndex = menuIndex * 2 + 2;
- }
- else {
- document.layers[content1ID].document.open();
- document.layers[content1ID].document.writeln(contentString);
- document.layers[content1ID].document.close();
- document.layers[content1ID].zIndex = menuIndex * 2 + 2;
- }
-
- moveLayerTo(content1ID,menuX,menuY);
- showLayer(content1ID);
- hideLayer(content0ID);
- }
-
- function mouseOver() {
- var menuNum = this.menuNum;
- var itemIndex = this.itemIndex;
- var menuIndex = menuItem[menuNum][itemIndex].myFolder;
- var menuLength = menuFolder[menuNum][menuIndex].length;
- var folderIndex = menuItem[menuNum][itemIndex].folder;
- var itemX = menuItem[menuNum][itemIndex].x;
- var itemY = menuItem[menuNum][itemIndex].y;
- var thisFolder = 0;
- var thisItem = 0;
- var menuX = itemX + menuWidth[menuNum][menuIndex] * charWidth + subMenuFlagSize;
-
- itemOn = true;
-
- if (menuItem[menuNum][itemIndex].type != flagSeparator) {
- if (isIE4) {
- this.style.backgroundColor = colorHighlighted;
- }
- else {
- this.document.bgColor = colorHighlighted;
- }
- }
-
- for (var i = 0; i < menuLength; i++) {
- thisItem = menuFolder[menuNum][menuIndex][i];
-
- if (thisItem != itemIndex)
- if (menuItem[menuNum][thisItem].type == flagMenu) {
- thisFolder = menuItem[menuNum][thisItem].folder;
-
- if (menuFolderSwitch[menuNum][thisFolder])
- hideMenu(menuNum,thisFolder);
- }
- }
-
- if (menuItem[menuNum][itemIndex].type == flagMenu) {
- hideContent();
-
- if (!menuFolderSwitch[menuNum][folderIndex])
- showMenu(menuNum,folderIndex,menuX,itemY);
- }
- else if (menuItem[menuNum][itemIndex].type == flagInfo) {
- if (contentShown)
- showContent(menuNum,itemIndex,menuX,itemY);
- }
- else
- hideContent();
-
- if (menuItem[menuNum][itemIndex].type != flagInfo)
- window.status = menuItem[menuNum][itemIndex].description;
- return true;
- }
-
- function mouseOut() {
- itemOn = false;
-
- if (isIE4)
- this.style.backgroundColor = colorNormal
- else
- this.document.bgColor = colorNormal;
-
- window.status = "";
- return true;
- }
-
- function menuItemUnit() {
- this.type = "";
- this.name = "";
- this.description = "";
- this.width = "";
- this.url = "";
- this.command = "";
- this.menu = "";
- this.folder = -1;
- this.myFolder = -1;
- this.x = -1;
- this.y = -1;
- }
-
- function readMenu(menuNum,menuName) {
- var menu = eval(menuName);
- var menuLength = menu.length
- var thisFolder = ++menuFolderCount;
-
- menuFolder[menuNum][thisFolder] = new Array();
- menuFolderSwitch[menuNum][thisFolder] = false;
- menuWidth[menuNum][thisFolder] = 0;
- menuLayer[menuNum][thisFolder] = false;
-
- for (var i = 0; i < menuLength; i++) {
- menuFolder[menuNum][thisFolder][i] = ++menuItemCount;
- itemLayer[menuNum][menuItemCount] = false;
-
- menuItem[menuNum][menuItemCount] = new menuItemUnit();
- menuItem[menuNum][menuItemCount].myFolder = thisFolder;
- menuItem[menuNum][menuItemCount].type = menu[i][0];
- menuItem[menuNum][menuItemCount].name = menu[i][1];
- menuItem[menuNum][menuItemCount].description = menu[i][2];
-
- if (menuWidth[menuNum][thisFolder] < (menuItem[menuNum][menuItemCount].name.length + marginSize))
- menuWidth[menuNum][thisFolder] = menuItem[menuNum][menuItemCount].name.length + marginSize;
-
- if (menuItem[menuNum][menuItemCount].type == flagMenu) {
- menuItem[menuNum][menuItemCount].menu = menu[i][3];
- menuItem[menuNum][menuItemCount].folder = menuFolderCount + 1;
- readMenu(menuNum,menuItem[menuNum][menuItemCount].menu);
- }
- else if (menuItem[menuNum][menuItemCount].type == flagInfo) {
- menuItem[menuNum][menuItemCount].width = parseInt(menu[i][3]);
- }
- else if (menuItem[menuNum][menuItemCount].type == flagLink) {
- menuItem[menuNum][menuItemCount].url = menu[i][3];
- }
- else if (menuItem[menuNum][menuItemCount].type == flagCommand) {
- menuItem[menuNum][menuItemCount].command = menu[i][3];
- }
- else if (menuItem[menuNum][menuItemCount].type != flagSeparator) {
- alert("Error found in " + menuName);
- }
- }
- }
-
- function getItem(menuNum,itemIndex,itemDimX,itemDimY,menuIndex) {
- var thisItem = null;
- var subMenuFlag = (menuItem[menuNum][itemIndex].type == flagMenu)?"subMenu.gif":"onePixel.gif";
- var singleQuote = "'";
- var itemID = "m" + menuNum + "i" + itemIndex + "";
- var layerString = '<div id="' + itemID + '" style="position:absolute; width:' + itemDimX + '; background-color:' + colorNormal + '; visibility:hidden;"></div>';
- var htmlString = (menuItem[menuNum][itemIndex].type == flagSeparator)?('<table width=' + itemDimX +' height=2 cellpadding=0 cellspacing=0 border=0><tr align=left valign=bottom><td bgcolor=' + colorTopLine + '><img src="onePixel.gif" width=1 height=1 border=0></td></tr><tr align=left valign=top><td bgcolor=' + colorBottomLine + '><img src="onePixel.gif" width=1 height=1 border=0></td></tr></table>'):('<table width=' + itemDimX +' height=' + itemDimY + ' cellpadding=0 cellspacing=0 border=0><tr align=left valign=middle><td nowrap><span id="menuText"><a class="menu" href="javascript:clickMenu(' + menuNum + ',' + itemIndex + ')" onMouseOver="window.status=' + singleQuote + (menuItem[menuNum][itemIndex].type == flagInfo?'':menuItem[menuNum][itemIndex].description) + singleQuote + ';return true;">' + marginString + menuItem[menuNum][itemIndex].name + marginString + '</a></span></td><td><img src="' + subMenuFlag + '" width=4 height=7 border=0 align=right></td></tr></table>');
-
- if (!itemLayer[menuNum][itemIndex]) {
- itemLayer[menuNum][itemIndex] = true;
-
- if (isIE4) {
- document.body.insertAdjacentHTML("BeforeEnd",layerString);
- thisItem = document.all[itemID];
-
- thisItem.innerHTML = htmlString;
- thisItem.style.zIndex = menuIndex * 2 + 1;
-
- thisItem.onmouseover = mouseOver;
- if (menuItem[menuNum][itemIndex].type != flagSeparator)
- thisItem.onmouseout = mouseOut;
- }
- else {
- document.layers[itemID] = new Layer(itemDimX);
- thisItem = document.layers[itemID];
-
- thisItem.visibility = "hidden";
- thisItem.document.open();
- thisItem.document.writeln(htmlString);
- thisItem.document.close();
- thisItem.document.bgColor = colorNormal;
- thisItem.zIndex = menuIndex * 2 + 1;
-
- thisItem.onmouseover = mouseOver;
- if (menuItem[menuNum][itemIndex].type != flagSeparator)
- thisItem.onmouseout = mouseOut;
- }
-
- thisItem.itemIndex = itemIndex;
- thisItem.menuNum = menuNum;
- }
-
- return itemID;
- }
-
- function getMenu(menuNum,menuIndex,menuDimX,menuDimY) {
- var menuID = "m" + menuNum + "f" + menuIndex + "";
- var menuPadX = menuDimX + borderSize * 2;
- var menuPadY = menuDimY + borderSize * 2;
- var layerString = '<div id="' + menuID + '" style="position:absolute; width:' + menuPadX + '; visibility:hidden;"></div>';
- var htmlString = '<table width=' + menuPadX +' height=' + menuPadY + ' cellpadding=0 cellspacing=0 border=' + borderSize + '><tr align=left valign=middle><td></td></tr></table>';
-
- if (!menuLayer[menuNum][menuIndex]) {
- menuLayer[menuNum][menuIndex] = true;
-
- if (isIE4) {
- document.body.insertAdjacentHTML("BeforeEnd",layerString);
-
- document.all[menuID].innerHTML = htmlString;
- document.all[menuID].style.zIndex = menuIndex * 2;
- }
- else {
- document.layers[menuID] = new Layer(menuPadX);
-
- document.layers[menuID].visibility = "hidden";
- document.layers[menuID].zIndex = menuIndex * 2;
- document.layers[menuID].document.open();
- document.layers[menuID].document.writeln(htmlString);
- document.layers[menuID].document.close();
- }
- }
-
- return menuID;
- }
-
- function showLayer(layerID) {
- if (isIE4)
- document.all[layerID].style.visibility = "visible"
- else
- document.layers[layerID].visibility = "show";
- }
-
- function hideLayer(layerID) {
- if (isIE4)
- document.all[layerID].style.visibility = "hidden"
- else
- document.layers[layerID].visibility = "hidden";
- }
-
- function moveLayerTo(layerID,x,y) {
- if (isIE4) {
- document.all[layerID].style.pixelLeft = x;
- document.all[layerID].style.pixelTop = y;
- }
- else {
- document.layers[layerID].left = x;
- document.layers[layerID].top = y;
- }
- }
-
- function hideMenu(menuNum,menuIndex) {
- var menuLength = menuFolder[menuNum][menuIndex].length;
- var menuID = getMenu(menuNum,menuIndex,0,0);
- var itemID = "";
- var itemIndex = 0;
-
- for (var i = 0; i < menuLength; i++) {
- itemIndex = menuFolder[menuNum][menuIndex][i];
-
- if (menuItem[menuNum][itemIndex].type == flagMenu)
- if (menuFolderSwitch[menuNum][menuItem[menuNum][itemIndex].folder])
- hideMenu(menuNum,menuItem[menuNum][itemIndex].folder);
-
- itemID = getItem(menuNum,itemIndex,0,0,0);
- hideLayer(itemID);
- }
-
- hideLayer(menuID);
-
- menuFolderSwitch[menuNum][menuIndex] = false;
- }
-
- function showMenu(menuNum,menuIndex,menuX,menuY) {
- var itemDimY = menuY;
- var menuLength = menuFolder[menuNum][menuIndex].length;
- var menuDimX = menuWidth[menuNum][menuIndex] * charWidth + subMenuFlagSize;
- var menuID = "";
- var itemID = "";
- var itemIndex = 0;
-
- if (menuShown != -1 && menuShown != menuNum)
- hideMenu(menuShown,0);
-
- menuShown = menuNum;
-
- for (var i = 0; i < menuLength; i++) {
- itemIndex = menuFolder[menuNum][menuIndex][i];
-
- menuItem[menuNum][itemIndex].x = menuX;
- menuItem[menuNum][itemIndex].y = itemDimY;
- itemDimY += (menuItem[menuNum][itemIndex].type != flagSeparator)?charHeight:2;
-
- itemID = getItem(menuNum,itemIndex,menuDimX,charHeight,menuIndex);
-
- moveLayerTo(itemID,menuItem[menuNum][itemIndex].x,menuItem[menuNum][itemIndex].y);
- //showLayer(itemID);
- }
-
- menuID = getMenu(menuNum,menuIndex,menuDimX,itemDimY-menuY);
- moveLayerTo(menuID,menuX-borderSize,menuY-borderSize);
- //showLayer(menuID);
-
- for (var i = 0; i < menuLength; i++)
- showLayer(getItem(menuNum,menuFolder[menuNum][menuIndex][i],0,0,0));
-
- showLayer(menuID);
-
- menuFolderSwitch[menuNum][menuIndex] = true;
- }
-
- function buildContent() {
- var content0ID = contentID + "0";
- var content1ID = contentID + "1";
-
- if (isIE4) {
- document.body.insertAdjacentHTML("BeforeEnd",'<div id="' + content0ID + '" style="position:absolute; width:1; visible:hidden;">')
- document.body.insertAdjacentHTML("BeforeEnd",'<div id="' + content1ID + '" style="position:absolute; width:1; visible:hidden;">')
- }
- else {
- document.layers[content0ID] = new Layer(1);
- document.layers[content0ID].visibility = "hidden";
- document.layers[content1ID] = new Layer(1);
- document.layers[content1ID].visibility = "hidden";
- }
- }
-
- function buildMenu(menuArrayName) {
- isIE4 = document.all;
- isNN4 = document.layers;
-
- var menuArray = eval(menuArrayName);
- var menuCount = menuArray.length;
-
- if (isNN4 || isIE4) {
- for (var i = 0; i < menuCount; i++) {
- menuItemCount = -1;
- menuFolderCount = -1;
-
- menuItem[i] = new Array();
- menuFolder[i] = new Array();
- menuFolderSwitch[i] = new Array();
- menuWidth[i] = new Array();
-
- itemLayer[i] = new Array();
- menuLayer[i] = new Array();
-
- readMenu(i,menuArray[i][0]);
- }
-
- if (isNN4) {
- nnWidth = window.innerWidth;
- nnHeight = window.innerHeight;
- window.onResize = reloadMenu;
- }
-
- buildContent();
- captureClick();
- }
- }
-
- function switchMenu(e) {
- mouseX = (isNN4)?(e.pageX+window.pageXOffset):(event.x+document.body.scrollLeft);
- mouseY = (isNN4)?(e.pageY+window.pageYOffset):(event.y+document.body.scrollTop);
-
- if (!itemOn)
- if (menuShown != -1)
- closeMenu(menuShown);
-
- return true;
- }
-
- function captureClick() {
- if (isIE4)
- document.onclick = switchMenu;
- else {
- document.onClick = switchMenu;
- document.captureEvents(Event.CLICK);
- }
- }
-
- function reloadMenu() {
- if (nnWidth != window.innerWidth || nnHeight != window.innerHeight)
- document.location.reload();
- }
-
- function openMenu(menuNum) {
- if (menuShown == menuNum)
- closeMenu(menuNum)
- else
- showMenu(menuNum,0,mouseX+borderSize,mouseY+borderSize);
- }
-
- function closeMenu(menuNum) {
- hideContent();
- menuShown = -1;
- hideMenu(menuNum,0);
- }
-
- // Script ends