📄 menu.js
字号:
var cMenuItemHTML = "<tr id=\"?id?\" height=\"10\"><td width=\"15\" align=\"center\"></td><td></td><td width=\"10\" align=\"right\"></td></tr>\n";
var cSplitterHTML = "<tr height=\"10\"><td colspan=\"3\"><hr></td></tr>\n";
var cPopMenuHTMLBeforeItems = "<table id=\"?id?\" style=\"display: none;\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
var cPopMenuHTMLAfterItems = "</table>\n";
//array to save all popmenu and items menu whick is in show
var arrPopMenuInShow = [];
//array to save popmenus that have been defined
var arrAllPopMenu = [];
/**********for monitor*********************************************************/
var strHTMLTotal = "";
var strItemsHTMLTotal = "";
/**********for monitor*********************************************************/
function MenuItem(id,text,cls,hint,tag,onclick,onmouseover,onmouseout/*,oncontextmenu*/)
{
this.Id = id;
this.Text = text;
this.MenuLevel = 1;
this.Parent = null;
if(typeof(tag)=="undefined")
this.Tag = "";
else
this.Tag = tag;
if(typeof(cls)=="undefined")
this.Class = "menuitems";
else
this.Class = cls;
if(typeof(hint)=="undefined")
this.Hint = "";
else
this.Hint = hint;
this.Checked = false;
//this.Items = [];
this.SubItems = null;
//save path's string value help to find the menuitem
this.Path = "";
if(typeof(onclick)=="undefined")
this.OnClick = null;
else
this.OnClick = onclick;
if(typeof(onmouseover)=="undefined")
this.OnMouseOver = MenuItemOnOtherItemsHide;
else
this.OnMouseOver = onmouseover;
if(typeof(onmouseout)=="undefined")
this.OnMouseOut = null;
else
this.OnMouseOut = onmouseout;
this.HasItem = function()
{
if(this.SubItems == null)
return " ";
else
return "<img src=\"" + System.Path() + "RightArrow.gif\">";
}
this.ShowChecked = function()
{
if(this.Checked)
return " <img src=\"" + System.Path() + "check.gif\">";
else
return " ";
}
this.Add = function(id,text,cls,onclick)
{
this.AddItem(new MenuItem(id,text,cls,onclick));
}
this.AddItem = function(mi)
{
if(this.SubItems == null)
{
var cls = "menu3d";
if(this.Parent.Class.indexOf("plane") > -1)
cls = "menuplane";
this.SubItems = new PopMenu(this.Id+"SubItems",cls);
this.SubItems.MenuLevel = this.MenuLevel + 1;
if(this.OnMouseOver == MenuItemOnOtherItemsHide)
this.OnMouseOver = MenuItemOnItemsShow;
}
this.SubItems.AddItem(mi);
mi.MenuLevel = this.MenuLevel + 1;
mi.Path += ".Item(\"" + this.Id + "\")";
}
this.AddSplitter = function()
{
this.Add("","<hr>");
}
this.Remove = function(id)
{
//
}
this.Clear = function()
{
//this.SubItems.length = null;
}
this.GetItemPath = function(id,mi)
{
if(typeof(mi) == "undefined")
mi = this;
if(mi.Id == id)
return mi.Path;
else if(mi.SubItems != null)
for(i=0;i<mi.SubItems.Items.length;i++)
mi.GetItemPath(id,mi.SubItems.Items[i]);
return "";
}
this.Item = function(index)
{
var itm = null;
if(typeof(index) == "string")
{
var i;
for(i=0;i<this.SubItems.Items.length;i++)
if(this.SubItems.Items[i].Id == index)
itm = this.SubItems.Items[i];
}
else if(typeof(index) == "number")
{
itm = this.SubItems.Items[index];
}
return itm;
}
this.HTML = function()
{
if(this.Id == "")
return cSplitterHTML;
var strOutput;
strOutput = cMenuItemHTML.replace("?id?",this.Id);
return strOutput;
}
this.WriteHTML = function()
{
document.write(this.HTML());
strHTMLTotal += this.HTML();
}
this.UpdateHTML = function()
{
var ctl = document.all(this.Id);
if(ctl == null)
return;
//set class
ctl.className = this.Class;
//set menulevel
ctl.menulevel = this.MenuLevel;
//set onclick
ctl.onclick = this.OnClick;
//set onmouseover
ctl.onmouseover = this.OnMouseOver;
//set onmouseout
ctl.onmouseout = this.OnMouseOut;
//set checked
ctl.childNodes[0].innerHTML = this.ShowChecked();
//set text
ctl.childNodes[1].innerHTML = this.Text;
//set hasitem
ctl.childNodes[2].innerHTML = this.HasItem();
}
}
function MenuItemFromId(id)
{
var path = "";
var key;
for(key in arrAllPopMenu)
if(path = arrAllPopMenu[key].GetItemPath(id))
return eval(path);
return null;
}
function MenuItemOnHighLight(evt)
{
if(typeof(evt)=="undefined")
evt = event.srcElement;
if(evt == null)
return;
if (evt.className == "menuitems")
{
evt.style.backgroundColor = "highlight";
evt.style.color = "white";
}
else
{
evt = evt.parentElement;
MenuItemOnHighLight(evt);
//return;
}
}
function MenuItemOnLowLight(evt)
{
if(typeof(evt)=="undefined")
var evt = event.srcElement;
if(evt == null)
return;
if (evt.className == "menuitems")
{
evt.style.backgroundColor = "";
evt.style.color = "black";
window.status = "";
}
else
{
evt = evt.parentElement;
MenuItemOnLowLight(evt);
}
}
function MenuItemOnCheck(mi)
{
if(typeof(mi) == "undefined")
mi = event.srcElement;
else if(typeof(mi) == "string")
mi = document.all(mi);
if(!mi.menulevel)
{
MenuItemOnCheck(mi.parentElement)
return;
}
var aMenuItem = MenuItemFromId(mi.id);
aMenuItem.Checked = !aMenuItem.Checked;
aMenuItem.UpdateHTML();
}
function MenuItemOnItemsShow(mi)
{
if(typeof(mi) == "undefined")
mi = window.event.srcElement;
if(!mi.menulevel)
{
MenuItemOnItemsShow(mi.parentElement);
return ;
}
PopMenuOnHide(parseInt(mi.menulevel));
var pos=[0,0];
function CheckStyle(ctl,arrPos)
{
if(ctl.style.left=="")
{
if(ctl.tagName != "TBODY")
{
arrPos[0] += ctl.offsetWidth;
arrPos[1] += ctl.offsetTop;
}
CheckStyle(ctl.parentElement,arrPos);
}
else
{
arrPos[0] += parseInt(ctl.style.left);
arrPos[1] += parseInt(ctl.style.top);
}
return true;;
}
CheckStyle(mi,pos);
PopMenuOnShow(mi.id+"SubItems",pos[0]+2,pos[1]+2);
}
function MenuItemOnOtherItemsHide(mi)
{
if(typeof(mi) == "undefined")
mi = window.event.srcElement;
if(!mi.menulevel)
{
MenuItemOnOtherItemsHide(mi.parentElement);
return ;
}
PopMenuOnHide(mi);
}
function PopMenu(id,cls,onclick,onmouseover,onmouseout)
{
//arrAllPopMenu[arrAllPopMenu.length] = this;
arrAllPopMenu[id] = this;
//
this.Id = id;
this.Owner = null;
this.MenuLevel = 1;
if(typeof(cls)=="undefined")
this.Class = "menu3d";
else
this.Class = cls;
if(typeof(onclick)=="undefined")
this.OnClick = null;
else
this.OnClick = onclick;
if(typeof(onmouseover)=="undefined")
this.OnMouseOver = MenuItemOnHighLight;
else
this.OnMouseOver = onmouseover;
if(typeof(onmouseout)=="undefined")
this.OnMouseOut = MenuItemOnLowLight;
else
this.OnMouseOut = onmouseout;
this.Items = [];
this.HTMLBeforeItems = function()
{
var strOutput;
strOutput = cPopMenuHTMLBeforeItems.replace("?id?",this.Id);
//strOutput = strOutput.replace("?Class?",this.Class);
//strOutput = strOutput.replace("?OnClick?",this.OnClick);
//strOutput = strOutput.replace("?MenuLevel?",this.MenuLevel);
return strOutput;
}
this.Add = function(id,text,cls,hint,tag,onclick)
{
this.AddItem(new MenuItem(id,text,cls,hint,tag,onclick));
}
this.AddItem = function(mi)
{
var len = this.Items.length;
this.Items[len] = mi;
mi.MenuLevel = this.MenuLevel;
mi.Parent = this;
mi.Path += "arrAllPopMenu[\"" + this.Id + "\"].Items[" + len + "]";
}
this.AddSplitter = function()
{
this.Add("","<hr>");
}
this.Remove = function(id)
{
//
}
this.GetItemPath = function(id)
{
var i;
var path = "";
for(i=0;i<this.Items.length;i++)
if(path = this.Items[i].GetItemPath(id))
return path;
return path;
}
this.Item = function(id)
{
for(i=0;i<this.Items.length;i++)
if(this.Items[i].Id == id)
return this.Items[i];
}
this.WriteHTML = function()
{
var i;
document.write(this.HTMLBeforeItems());
strHTMLTotal += this.HTMLBeforeItems();
for(i=0;i<this.Items.length;i++)
this.Items[i].WriteHTML();
document.write(cPopMenuHTMLAfterItems);
strHTMLTotal += cPopMenuHTMLAfterItems;
}
this.UpdateHTML = function()
{
var ctl = document.all(this.Id);
ctl.className = this.Class;
ctl.menulevel = this.MenuLevel;
ctl.onclick = this.OnClick;
ctl.onmouseover = this.OnMouseOver;
ctl.onmouseout = this.OnMouseOut;
for(i=0;i<this.Items.length;i++)
this.Items[i].UpdateHTML();
}
this.WriteItemsHTML = function()
{
var i;
for(i=0;i<this.Items.length;i++)
if(this.Items[i].SubItems != null)
{
this.Items[i].SubItems.WriteHTML();
this.Items[i].SubItems.WriteItemsHTML();
}
}
this.UpdateItemsHTML = function()
{
var i;
for(i=0;i<this.Items.length;i++)
if(this.Items[i].SubItems != null)
{
this.Items[i].SubItems.UpdateHTML();
this.Items[i].SubItems.UpdateItemsHTML();
}
}
}
function PopMenuOnShow(menu,posX,posY)
{
if((menu == "") || (menu == null))
return;
window.event.returnValue = false;
if(typeof(menu)=="string")
menu = document.all(menu);
if(typeof(posX)=="undefined")
{
posX = event.clientX;
PopMenuOnHide();
}
if(typeof(posY)=="undefined")
posY = event.clientY;
var rightedge = document.body.clientWidth-posX;
var bottomedge = document.body.clientHeight-posY;
if (rightedge < menu.scrollWidth+10)
menu.style.left = document.body.scrollLeft + posX - menu.scrollWidth-10;
else
menu.style.left = document.body.scrollLeft + posX;
if (bottomedge < menu.scrollHeight)
menu.style.top = document.body.scrollTop + posY - menu.scrollHeight;
else
menu.style.top = document.body.scrollTop + posY;
menu.style.display = "block";
menu.style.visibility = "visible";
var i;
for(i=0;i<arrPopMenuInShow.length;i++)
if(arrPopMenuInShow[i] == menu)
return;
arrPopMenuInShow[arrPopMenuInShow.length] = menu;
}
function PopMenuOnHide(mi)
{
var i;
if(typeof(mi)=="undefined")
{
for(i=0;i<arrPopMenuInShow.length;i++)
arrPopMenuInShow[i].style.display = "none";
arrPopMenuInShow.length = 0;
var key;
for(key in arrAllMainMenu)
arrAllMainMenu[key].ItemOnShow = "";
}
else
for(i=0;i<arrPopMenuInShow.length;i++)
if((arrPopMenuInShow[i].menulevel>mi.menulevel) && (arrPopMenuInShow[i].id.indexOf(mi.id)<0))
arrPopMenuInShow[i].style.display = "none";
}
if(document.all)
document.onclick = PopMenuOnHide;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -