BSRightMenu
/**
* <p>标题: BSRightMenu</p>
* <p>功能描述: BS右键菜单对象。装载所有的右键菜单块</p>
* <p>作者: BinaryStar原创B/S框架</p>
* <p>版本: 0.1</p>
* <p>创建日期: 2005-12-21</p>
*/
function BSRightMenu(id)...{
this.id = id||"BSRightMenu_1";//ID
this.itemAreaList = new Array();//右键集合
this.showItemAreaIndex = -1;//当前显示的右键菜单块
this.clickItemIndex = -1;//当前鼠标单击所在的子菜单项索引。
this.maxLevel = 0;//菜单树深度
var rmlist = null;
this.imagePath = "";//缺省的路径
this.popupList = new Array();//popup窗口列表
this.setImagesPath = function(inPath)...{
this.imagePath = inPath;
}
//设置最大深度值
this.setMaxLevel = function (inLevel)...{
if (inLevel > this.maxLevel)...{
this.maxLevel = inLevel;
}
}
//添加一个右键菜单块
this.addItemArea = function (text)...{
var area = new BSRightItemArea(this.id, this.itemAreaList.length, text);
this.itemAreaList.length++;
this.itemAreaList[this.itemAreaList.length-1] = area;
return area;
}
//激发右键菜单
this.doRightMenu = function (areaIndex)...{
window.event.cancelBubble=true;
this.rmIni();
var curAreaIndex = 0;
if (areaIndex != null)...{
curAreaIndex = areaIndex;
}
this.hiddenAll(0);
if (areaIndex < 0)...{
event.srcElement.oncontextmenu = null;
return;
}
if(window.event.button == this.itemAreaList[areaIndex].mouseType)...{
this.setRMIndex(areaIndex, -1);
event.srcElement.oncontextmenu = function()...{return false;};
//展现前的准备
if (this.itemAreaList[areaIndex].preShowFun.Trim() != "")...{
try...{
eval(this.itemAreaList[areaIndex].preShowFun);
}
catch(e)...{
var errStr = "*^_^*恭喜你中招了! "+e.name+":"+e.message+" 激发右键前的准备方法 "+this.itemAreaList[areaIndex].preShowFun+" 发生严重错误!";
return;
}
}
//展现第一层子菜单
this.createPopDiv(curAreaIndex);
}
else...{
event.srcElement.oncontextmenu = null;
}
}
this.rmIni = function()...{
if (document.getElementById(this.id + "_thisAreaIndex") == null)...{
var temp = document.createElement("input");
temp.id = this.id + "_thisAreaIndex";
temp.value = -1;
temp.style.display="none";
temp.type = "hidden";
document.body.appendChild(temp);
}
if (document.getElementById(this.id + "_thisItemIndex") == null)...{
var temp = document.createElement("input");
temp.id = this.id + "_thisItemIndex";
temp.value = -1;
temp.style.display="none";
temp.type = "hidden";
document.body.appendChild(temp);
}
}
this.setRMIndex = function (areaIndex, itemIndex)...{
document.getElementById(this.id+"_thisAreaIndex").value = areaIndex;
this.showItemAreaIndex = areaIndex;
document.getElementById(this.id+"_thisItemIndex").value = itemIndex;
this.clickItemIndex = itemIndex;
}
this.createPopDiv = function(curAreaIndex)...{
var div = null;
//创建popup
if (this.popupList[0] == null)...{
this.popupList[0] = window.createPopup();
if (this.popupList[0].document.charset != "GB2312")...{
try...{
this.popupList[0].document.charset="GB2312";
}
catch(ex)...{
}
}
this.popupList[0].document.oncontextmenu = function()...{return false;};
}
this.popupList[0].document.body.innerHTML = "";
this.popupList[0].show(0,0,1,1);
if (this.popupList[0].document.getElementById(this.id+"_ItemDiv") == null)...{
div = this.popupList[0].document.createElement("div");
div.style.cssText = bs_rm_div;
div.id = this.id+"_ItemDiv";
div.innerHTML = this.itemAreaList[curAreaIndex].show();
this.popupList[0].document.body.appendChild(div);
div.innerHTML += "<input type="hidden" id=""+this.id+"_selectItem" name=""+this.id+"_selectItem" value="-1"/>";
}
else...{
div = this.popupList[0].document.getElementById(this.id+"_ItemDiv");
div.innerHTML = this.itemAreaList[curAreaIndex].show();
div.innerHTML += "<input type="hidden" id=""+this.id+"_selectItem" name=""+this.id+"_selectItem" value="-1"/>";
}
var left = window.event.clientX-1;
var top = window.event.clientY-1;
//window.status = (left+window.screenLeft);
if (((left+window.screenLeft) + div.offsetWidth) >= window.screen.availWidth)...{
left -= (div.offsetWidth-1);
}
if(((top+window.screenTop)+div.offsetHeight) >= window.screen.availHeight)...{
top -= (div.offsetHeight-1);
}
var width = div.offsetWidth;
var Height = div.offsetHeight;
this.popupList[0].show(left, top, width, Height, document.body);
}
//隐藏指定深度下所有展现的菜单
this.hiddenAll = function(inLevel)...{
var tlevel = 0;
if (inLevel != null)...{
var tlevel = inLevel
}
for (var i=this.popupList.length-1; i>=inLevel; i--)...{
if (this.popupList[i] !=null && this.popupList[i].isOpen)...{
this.popupList[i].hide();
//this.popupList[i] = null;
}
}
}
//得到当前显示的菜单块
this.getThisRMArea = function()...{
return this.itemAreaList[this.showItemAreaIndex];
}
//得到指定显示的菜单块
this.getThisRMAreaByIndex = function(inIndex)...{
if (inIndex >=0 && inIndex<this.itemAreaList.length)...{
return this.itemAreaList[inIndex];
}
alert("对不起,没有找到指定的菜单块!");
return null;
}
//得到当前显示的菜单项
this.getThisRMItem = function()...{
return this.getThisRMArea().itemList[this.clickItemIndex];
}
//得到指定Key的菜单项
this.getThisRMItemByKey = function(inKey, inAreaIndex)...{
var tArea = this.getThisRMArea();
if (tArea == null && inAreaIndex != null)...{
tArea = this.getThisRMAreaByIndex(inAreaIndex);
}
if (tArea != null)...{
for (var i=0; i<tArea.itemList.length; i++)...{
if (tArea.itemList[i].key == inKey)...{
return tArea.itemList[i];
}
}
}
alert("对不起,没有找到指定的菜单项!");
return null;
}
//得到父亲名称
this.getRMName = function(level)...{
var fname = "";
for (var i=0; i<level+1; i++)...{
fname += "parent."
}
fname += this.id;
return fname;
}
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/mynickel2000/archive/2006/09/12/1214632.aspx