// +------------------------------------------------------------+
// | yx_menu Version 3 |
// | Copyright 1999 Xin Yang yangxin@iname.com |
// | Created 11/01/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 flagCommand = "C";
var flagSeparator = "S";
var charWidth = 7; // character width
var charHeight = 15; // character height
var colorNormal = "#ccccff"; // menu pad color
var colorHighlighted = "#eeeeff"; // menu highlighted item color
var colorTopLine = "navy"; // separator upper line color
var colorBottomLine = "#ffffff"; // separator lower line color
var borderSize = 2;
var marginSize = 4;
var marginString = " ";
var subMenuFlagSize = 4;
var menuHolder = "menuHolder";
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 menuDone = new Array();
var itemOn = false;
var nnWidth = 0, nnHeight = 0;
function launchCommand(commandString) {
eval(commandString);
}
function launchPage(pageURL) {
document.location.assign(pageURL);
}
function clickMenu(itemIndex) {
var menuIndex = menuItem[itemIndex].myFolder;
var folderIndex = menuItem[itemIndex].folder;
var itemX = menuItem[itemIndex].x;
var itemY = menuItem[itemIndex].y;
if (menuItem[itemIndex].type == flagMenu) {
if (menuFolderSwitch[folderIndex])
hideMenu(folderIndex)
else
showMenu(folderIndex,itemX + menuWidth[menuIndex] * charWidth + subMenuFlagSize,itemY);
}
else if (menuItem[itemIndex].type == flagLink) {
hideSubMenu();
launchPage(menuItem[itemIndex].url);
}
else if (menuItem[itemIndex].type == flagCommand) {
hideSubMenu();
launchCommand(menuItem[itemIndex].command);
}
}
function mouseOver() {
var itemIndex = this.itemIndex;
var menuIndex = menuItem[itemIndex].myFolder;
var menuLength = menuFolder[menuIndex].length;
var folderIndex = menuItem[itemIndex].folder;
var itemX = menuItem[itemIndex].x;
var itemY = menuItem[itemIndex].y;
var thisFolder = 0;
var thisItem = 0;
itemOn = true;
if (menuItem[itemIndex].type != flagSeparator) {
if (isIE4) {
this.style.backgroundColor = colorHighlighted;
}
else if (isNN4) {
this.document.bgColor = colorHighlighted;
}
}
for (var i = 0; i < menuLength; i++) {
thisItem = menuFolder[menuIndex][i];
if (thisItem != itemIndex)
if (menuItem[thisItem].type == flagMenu) {
thisFolder = menuItem[thisItem].folder;
if (menuFolderSwitch[thisFolder])
hideMenu(thisFolder);
}
}
if (menuItem[itemIndex].type == flagMenu)
if (!menuFolderSwitch[folderIndex])
showMenu(folderIndex,itemX + menuWidth[menuIndex] * charWidth + subMenuFlagSize,itemY);
window.status = menuItem[itemIndex].description;
return true;
}
function mouseOut() {
itemOn = false;
if (isIE4)
this.style.backgroundColor = colorNormal
else if (isNN4)
this.document.bgColor = colorNormal;
window.status = "";
}
function menuItemUnit() {
this.type = "";
this.name = "";
this.description = "";
this.url = "";
this.command = "";
this.menu = "";
this.folder = -1;
this.myFolder = -1;
this.x = -1;
this.y = -1;
}
function readMenu(menuName) {
var menu = eval(menuName);
var menuLength = menu.length
var thisFolder = ++menuFolderCount;
menuFolder[thisFolder] = new Array();
menuFolderSwitch[thisFolder] = false;
menuWidth[thisFolder] = 0;
menuLayer[thisFolder] = false;
menuDone[thisFolder] = false;
for (var i = 0; i < menuLength; i++) {
menuFolder[thisFolder][i] = ++menuItemCount;
itemLayer[menuItemCount] = false;
menuItem[menuItemCount] = new menuItemUnit();
menuItem[menuItemCount].myFolder = thisFolder;
menuItem[menuItemCount].type = menu[i][0];
menuItem[menuItemCount].name = menu[i][1];
menuItem[menuItemCount].description = menu[i][2];
if (menuWidth[thisFolder] < (menuItem[menuItemCount].name.length + marginSize))
menuWidth[thisFolder] = menuItem[menuItemCount].name.length + marginSize;
if (menuItem[menuItemCount].type == flagMenu) {
menuItem[menuItemCount].menu = menu[i][3];
menuItem[menuItemCount].folder = menuFolderCount + 1;
readMenu(menuItem[menuItemCount].menu);
}
else if (menuItem[menuItemCount].type == flagLink) {
menuItem[menuItemCount].url = menu[i][3];
}
else if (menuItem[menuItemCount].type == flagCommand) {
menuItem[menuItemCount].command = menu[i][3];
}
else if (menuItem[menuItemCount].type != flagSeparator) {
alert("Menu Error");
}
}
}
function getItem(itemIndex,itemDimX,itemDimY,menuIndex) {
var thisItem = null;
var subMenuFlag = (menuItem[itemIndex].type == flagMenu)?"subMenu.gif":"onePixel.gif";
var singleQuote = "'";
var itemID = "item" + itemIndex + "";
var layerString = '
';
var htmlString = (menuItem[itemIndex].type == flagSeparator)?(' |
|
'):(' | |
');
if (!itemLayer[itemIndex]) {
itemLayer[itemIndex] = true;
if (isIE4) {
document.all[menuHolder].insertAdjacentHTML("BeforeEnd",layerString);
thisItem = document.all[itemID];
thisItem.innerHTML = htmlString;
thisItem.style.zIndex = menuIndex * 2 + 1;
thisItem.onmouseover = mouseOver;
if (menuItem[itemIndex].type != flagSeparator)
thisItem.onmouseout = mouseOut;
thisItem.itemIndex = itemIndex;
}
else if (isNN4) {
document.layers[itemID] = new Layer(itemDimX,document.layers[menuHolder]);
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[itemIndex].type != flagSeparator)
thisItem.onmouseout = mouseOut;
thisItem.itemIndex = itemIndex;
}
}
return itemID;
}
function getMenu(menuIndex,menuDimX,menuDimY) {
var menuID = "menu" + menuIndex + "";
var menuPadX = menuDimX + borderSize * 2;
var menuPadY = menuDimY + borderSize * 2;
var layerString = '';
var htmlString = '';
if (!menuLayer[menuIndex]) {
menuLayer[menuIndex] = true;
if (isIE4) {
document.all[menuHolder].insertAdjacentHTML("BeforeEnd",layerString);
document.all[menuID].innerHTML = htmlString;
document.all[menuID].style.zIndex = menuIndex * 2;
}
else if (isNN4) {
document.layers[menuID] = new Layer(menuPadX,document.layers[menuHolder]);
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 if (isNN4)
document.layers[layerID].visibility = "show";
}
function hideLayer(layerID) {
if (isIE4)
document.all[layerID].style.visibility = "hidden"
else if (isNN4)
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 if (isNN4) {
document.layers[layerID].left = x;
document.layers[layerID].top = y;
}
}
function hideMenu(menuIndex) {
var menuLength = menuFolder[menuIndex].length;
var menuID = getMenu(menuIndex,0,0);
var itemID = "";
var itemIndex = 0;
for (var i = 0; i < menuLength; i++) {
itemIndex = menuFolder[menuIndex][i];
if (menuItem[itemIndex].type == flagMenu)
if (menuFolderSwitch[menuItem[itemIndex].folder])
hideMenu(menuItem[itemIndex].folder);
itemID = getItem(itemIndex,0,0,0);
hideLayer(itemID);
}
hideLayer(menuID);
menuFolderSwitch[menuIndex] = false;
}
function hideSubMenu() {
var menuLength = menuFolder[0].length;
for (var i = 0; i < menuLength; i++) {
itemIndex = menuFolder[0][i];
if (menuItem[itemIndex].type == flagMenu) {
if (menuFolderSwitch[menuItem[itemIndex].folder])
hideMenu(menuItem[itemIndex].folder);
}
}
}
function showMenu(menuIndex,menuX,menuY) {
var itemDimY = menuY;
var menuLength = menuFolder[menuIndex].length;
var menuDimX = menuWidth[menuIndex] * charWidth + subMenuFlagSize;
var menuID = "";
var itemID = "";
var itemIndex = 0;
if (!menuDone[menuIndex]) {
for (var i = 0; i < menuLength; i++) {
itemIndex = menuFolder[menuIndex][i];
menuItem[itemIndex].x = menuX;
menuItem[itemIndex].y = itemDimY;
itemDimY += (menuItem[itemIndex].type != flagSeparator)?charHeight:2;
itemID = getItem(itemIndex,menuDimX,charHeight,menuIndex);
moveLayerTo(itemID,menuItem[itemIndex].x,menuItem[itemIndex].y);
}
menuID = getMenu(menuIndex,menuDimX,itemDimY-menuY);
moveLayerTo(menuID,menuX-borderSize,menuY-borderSize);
menuDone[menuIndex] = true;
}
for (var i = 0; i < menuLength; i++)
showLayer(getItem(menuFolder[menuIndex][i],0,0,0));
showLayer(getMenu(menuIndex,0,0));
menuFolderSwitch[menuIndex] = true;
}
function getMenuSizeX(menuIndex) {
var menuLength = menuFolder[menuIndex].length;
var itemIndex = 0;
var thisMenuDimX = menuWidth[menuIndex] * charWidth + subMenuFlagSize;
var menuDimX = thisMenuDimX;
var subMenuDimX = 0;
for (var i = 0; i < menuLength; i++) {
itemIndex = menuFolder[menuIndex][i];
if (menuItem[itemIndex].type == flagMenu) {
subMenuDimX = getMenuSizeX(menuItem[itemIndex].folder);
if (menuDimX < (thisMenuDimX + subMenuDimX))
menuDimX = thisMenuDimX + subMenuDimX;
}
}
return menuDimX;
}
function getMenuSizeY(menuIndex) {
var menuLength = menuFolder[menuIndex].length;
var itemIndex = 0;
var menuDimY = 0;
var subMenuDimY = 0;
var maxSubMenuDimY = 0;
for (var i = 0; i < menuLength; i++) {
itemIndex = menuFolder[menuIndex][i];
if (menuItem[itemIndex].type == flagMenu) {
subMenuDimY = getMenuSizeY(menuItem[itemIndex].folder);
if (maxSubMenuDimY < (menuDimY + subMenuDimY))
maxSubMenuDimY = menuDimY + subMenuDimY;
menuDimY += charHeight;
}
else if (menuItem[itemIndex].type == flagSeparator)
menuDimY += 2
else
menuDimY += charHeight;
}
if (menuDimY < maxSubMenuDimY)
return maxSubMenuDimY
else
return menuDimY;
}
function setMenuSize(menuDimX,menuDimY) {
document.layers[menuHolder].clip.width=menuDimX;
document.layers[menuHolder].clip.height=menuDimY;
}
function buildMenu(menuName) {
isIE4 = document.all;
isNN4 = document.layers;
var menuSizeX = 0;
var menuSizeY = 0;
if (isIE4 || isNN4) {
readMenu(menuName);
if (isNN4) {
menuSizeX = getMenuSizeX(0) + borderSize * 2;
menuSizeY = getMenuSizeY(0) + borderSize * 2;
setMenuSize(menuSizeX,menuSizeY);
nnWidth = window.innerWidth;
nnHeight = window.innerHeight;
window.onResize = reloadMenu;
}
showMenu(0,borderSize,borderSize);
captureClick();
}
}
function switchMenu() {
if (!itemOn)
hideSubMenu();
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();
}
// Script ends