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