file:coolmenu1_0_2.js
//------------------------------------------------------------
// Copyright (c) 2003-2004 LeadinSoft. All rights reserved.
// Version 1.0.2
// Ahthor dolphin
//------------------------------------------------------------
//单个菜单的结构
function menu(mnuName,mnuText,mnuAlt,mnuIcon,mnuTarget,mnuKey,mnuType,mnuCmd){
this.name = mnuName;
this.text = mnuText;
this.alt = mnuAlt;
this.icon = mnuIcon;
this.target = mnuTarget;
this.key = mnuKey;
this.type = mnuType;
this.cmd = mnuCmd;
}
//菜单组结构
function CMenu(mnuName){
this.name = mnuName;
this.menu = new Array();
}
function ActiveMenu(mnuID,mnuType){
this.id = mnuID;
this.type = mnuType;
}
//打印主菜单(Main-CM)
function drawMainMenu(CM, width, height){
var HTMLStr, posLeft, posTop, i;
HTMLStr = "<div id='" + CM.name + "' class='CM_MainMenuBar' style='width:"+ width + ";height:"+ height + "'>";
document.write(HTMLStr);
var obj = document.all(CM.name);
posLeft = obj.offsetLeft;
posTop = obj.offsetTop;
var pobj = obj.offsetParent;
while(pobj.tagName.toUpperCase() != "BODY"){
posLeft += pobj.offsetLeft;
posTop += pobj.offsetTop;
pobj = pobj.offsetParent;
}
posLeft += 2;
posTop += 3;
for(i=0; i<CM.menu.length; i++){
HTMLStr = "<div id='" + CM.menu[i].name + "' nowrap class='CM_MainMenu' style='left:" + posLeft + ";top:" + posTop + ";height:21px' onmouseover='return CMM_Over(this,\"" + CM.menu[i].cmd + "\")' onmouseout='return CMM_Out(this)' " +
"onclick='return CMM_Click(this,\"" + CM.menu[i].cmd + "\")' title='" + CM.menu[i].alt + "'>" + CM.menu[i].text;
if(CM.menu[i].key != ""){
HTMLStr += "(<u>" + CM.menu[i].key + "</u>)";
}
HTMLStr += "</div>";
document.write(HTMLStr);
posLeft += document.all.item(CM.menu[i].name).offsetWidth + 1;
}
HTMLStr = "</div>";
document.write(HTMLStr);
}
function drawSubMenu(CM){
var HTMLStr, i, maxLn = 0;
HTMLStr = "<div id='"+ CM.name +"' style='left:0px;top:0px;width:150px;overflow:hidden' class='CM_SubMenuBar'>";
document.write(HTMLStr);
for(i=0; i<CM.menu.length; i++){
tmp = getTextLength(CM.menu[i].text);
if(maxLn < tmp) maxLn = tmp;
HTMLStr = "<div id='"+ CM.menu[i].name +"' class='CM_SubMenu'"+
" title='"+ CM.menu[i].alt +"'"+
" onmouseover=\"CMS_Over(this,"+ CM.menu[i].type +",'"+ CM.menu[i].cmd +"')\""+
" onmouseout=\"CMS_Out(this,"+ CM.menu[i].type +",'"+ CM.menu[i].cmd +"')\""+
" onclick=\"CMS_Click(this,"+ CM.menu[i].type +",'"+ CM.menu[i].cmd +"')\">";
HTMLStr += "<table border=0 cellspacing=0 cellpadding=0 width='100%' align='center'>";
HTMLStr += "<tr nowrap height=20><td nowrap width=1></td>";
HTMLStr += formatImage(CM.menu[i].icon,CM.menu[i].name);
HTMLStr += "<td id='"+ CM.menu[i].name +"_text' class='CM_Text'>"+ CM.menu[i].text;
if(CM.menu[i].key != ""){
HTMLStr += "(<u>"+ CM.menu[i].key +"</u>)";
}
HTMLStr += "</td>";
HTMLStr += "<td id='"+ CM.menu[i].name +"_sub' nowrap align=center width=16 class='CM_Sub'>";
if(CM.menu[i].type == 0){
HTMLStr += "<span class='SubFlag'>}</span>";
}
else{
HTMLStr += " "
}
HTMLStr += "</td>"+
"<td nowrap width=1 class='CM_Space'></td></tr></table></div>";
document.write (HTMLStr);
}
HTMLStr = "</div>";
document.write(HTMLStr);
document.all.item(CM.name).style.width = maxLn*10+40;
//test.value += document.all.item(CM.name).outerHTML;
}
function formatImage(mnuIcon, mnuName){
var result = "<td id='"+ mnuName +"_ico' nowrap align=center width=20 class='CM_Icon'>";
if(mnuIcon != ""){
result += "<IMG SRC='"+ mnuIcon +"' BORDER='0'>";
}
else{
result += " ";
}
result += "</td>";
return result;
}
function getTextLength(text){
var ln = 0;
for(var i=0; i<text.length; i++){
if(text.charCodeAt(i) > 256){
ln++;
}
ln++;
}
return ln;
}
function showMenu(mnuObj,mnuSubID){
var l = mnuObj.offsetLeft - 1;
var t = mnuObj.offsetTop + mnuObj.offsetHeight;
document.all.item(mnuSubID).style.left = l; //设置子菜单位置
document.all.item(mnuSubID).style.top = t; //设置子菜单的位置
document.all.item("overline").style.left = l + 2;
document.all.item("overline").style.top = t;
document.all.item("overline").style.width = mnuObj.offsetWidth - 2;
document.all.item("overline").style.visibility = "visible";
document.all.item(mnuSubID).style.visibility = "visible"; //显示子菜单
g_actMenu[g_actMenu.length] = new ActiveMenu(mnuSubID,1);
if(g_shadowStr != null){
mnuObj.style.filter = g_shadowStr;
document.all.item(mnuSubID).style.filter = g_shadowStr;
}
}
function showSubMenu(mnuObj,mnuSubID){
var l = mnuObj.parentElement.offsetLeft + mnuObj.offsetLeft + mnuObj.offsetWidth + 2;
var t = mnuObj.parentElement.offsetTop + mnuObj.offsetTop + 1;
var mnuSubObj = document.all.item(mnuSubID);
if(l+mnuSubObj.offsetWidth>g_scrWidth)
mnuSubObj.style.left = mnuObj.parentElement.offsetLeft - mnuSubObj.offsetWidth - 2;
else
mnuSubObj.style.left = l;
if(t+mnuSubObj.offsetHeight>g_scrHeight)
mnuSubObj.style.top = g_scrHeight - mnuSubObj.offsetHeight;
else
mnuSubObj.style.top = t;
mnuSubObj.style.visibility = "visible";
g_actMenu[g_actMenu.length] = new ActiveMenu(mnuSubID,1);
}
function CMM_Over(obj, cmd){
if(!g_blnMMClick){
obj.className = "CM_MainMenuOver";
g_actMenu[g_actMenu.length] = new ActiveMenu(obj.id,0);
}
else{
if(g_actMenu[0].id == obj.id) return;
document.all.item(g_actMenu[0].id).className = "CM_MainMenu";
for(var i=1;i<g_actMenu.length;i++){
if (g_actMenu[i].type == 0) {
document.all.item(g_actMenu[i].id + "_ico").className = "CM_Icon";
document.all.item(g_actMenu[i].id + "_text").className = "CM_Text";
document.all.item(g_actMenu[i].id + "_sub").className = "CM_Sub";
}
else{
document.all.item(g_actMenu[i].id).style.visibility = "hidden";
}
}
g_actMenu.length = 0;
obj.className = "CM_MainMenuClick";
g_actMenu[g_actMenu.length] = new ActiveMenu(obj.id,0);
showMenu(obj,cmd);
}
}
function CMM_Out(obj){
if(!g_blnMMClick){
obj.className = "CM_MainMenu";
g_actMenu.length --;
}
}
function CMM_Click(obj,cmd){
if(!g_blnMMClick){
obj.className = "CM_MainMenuClick";
showMenu(obj,cmd);
g_blnMMClick = true;
}
else{
document_click();
}
g_blnSMClick = true;
if(!g_blnMMClick) CMM_Over(obj, cmd);
}
function CMS_Over(obj, type, cmd){
for(var i=1;i<g_actMenu.length;i++){
if(g_actMenu[i].id == obj.parentElement.id){
for(var j=i+1;j<g_actMenu.length;j++){
if(g_actMenu[j].type == 0){
document.all.item(g_actMenu[j].id + "_ico").className = "CM_Icon";
document.all.item(g_actMenu[j].id + "_text").className = "CM_Text";
document.all.item(g_actMenu[j].id + "_sub").className = "CM_Sub";
}
else{
document.all.item(g_actMenu[j].id).style.visibility = "hidden";
}
}
g_actMenu.length = i+1;
break;
}
}
g_actMenu[g_actMenu.length] = new ActiveMenu(obj.id,0);
//showstatus();
document.all.item(obj.id + "_ico").className = "CM_IconOver";
document.all.item(obj.id + "_text").className = "CM_TextOver";
document.all.item(obj.id + "_sub").className = "CM_SubOver";
if(type == 0){
showSubMenu(obj,cmd);
}
//showstatus();
}
function CMS_Out(obj, type, cmd){
if(type != 0){
document.all.item(obj.id + "_ico").className = "CM_Icon";
document.all.item(obj.id + "_text").className = "CM_Text";
document.all.item(obj.id + "_sub").className = "CM_Sub";
if(g_actMenu.length > 0) g_actMenu.length --;
}
//showstatus();
}
function CMS_Click(obj, type, cmd){
if(type == 1){
document_click();
document.all.item("overline").style.visibility = "hidden";
lblMsg.innerText = cmd;
}
else{
评论1