超强悍的右键菜单
//创建js文件
function RightMenu()
{
this.AddExtendMenu=AddExtendMenu;
this.AddItem=AddItem;
this.GetMenu=GetMenu;
this.HideAll=HideAll;
this.I_OnMouseOver=I_OnMouseOver;
this.I_OnMouseOut=I_OnMouseOut;
this.I_OnMouseUp=I_OnMouseUp;
this.P_OnMouseOver=P_OnMouseOver;
this.P_OnMouseOut=P_OnMouseOut;
A_rbpm = new Array();
HTMLstr = "";
HTMLstr += "<!-- RightButton PopMenu -->\n";
HTMLstr += "\n";
HTMLstr += "<!-- PopMenu Starts -->\n";
HTMLstr += "<div id='E_rbpm' class='rm_div'>\n";
// rbpm = right button pop menu
HTMLstr += "<table width='100%' border='0' cellspacing='0' cellPadding='0'>\n";
HTMLstr += "<tr>";
HTMLstr += "<td width='120' style='padding: 0' valign='bottom'>\n";
HTMLstr += "<table width='100%' border='0' cellspacing='0' cellPadding='0'>\n";
HTMLstr += "<!-- Insert A Extend Menu or Item On Here For E_rbpm -->\n";
HTMLstr += "</table></td></tr></table>\n";
HTMLstr += "</div>\n";
HTMLstr += "<!-- Insert A Extend_Menu Area on Here For E_rbpm -->";
HTMLstr += "\n";
HTMLstr += "<!-- PopMenu Ends -->\n";
}
function AddExtendMenu(id,img,wh,name,parent)
{
var TempStr = "";
eval("A_"+parent+".length++");
eval("A_"+parent+"[A_"+parent+".length-1] = id"); // 将此项注册到父菜单项的ID数组中去
TempStr += "<div id='E_"+id+"' class='rm_div'>\n";
TempStr += "<table width='100%' border='0' cellspacing='0'>\n";
TempStr += "<!-- Insert A Extend Menu or Item On Here For E_"+id+" -->";
TempStr += "</table>\n";
TempStr += "</div>\n";
TempStr += "<!-- Insert A Extend_Menu Area on Here For E_"+id+" -->";
TempStr += "<!-- Insert A Extend_Menu Area on Here For E_"+parent+" -->";
HTMLstr = HTMLstr.replace("<!-- Insert A Extend_Menu Area on Here For E_"+parent+" -->",TempStr);
eval("A_"+id+" = new Array()");
TempStr = "";
TempStr += "<!-- Extend Item : P_"+id+" -->\n";
TempStr += "<tr id='P_"+id+"' class='out'";
TempStr += " onmouseover='P_OnMouseOver(\""+id+"\",\""+parent+"\")'";
TempStr += " onmouseout='P_OnMouseOut(\""+id+"\",\""+parent+"\")'";
TempStr += " onmouseup=window.event.cancelBubble=true;";
TempStr += " onclick=window.event.cancelBubble=true;";
TempStr += "><td nowrap>";
TempStr += "<font face='Wingdings' style='font-size:18px'>0</font> "+name+" </td><td style='font-family: webdings; text-align: ;'>4";
TempStr += "</td></tr>\n";
TempStr += "<!-- Insert A Extend Menu or Item On Here For E_"+parent+" -->";
HTMLstr = HTMLstr.replace("<!-- Insert A Extend Menu or Item On Here For E_"+parent+" -->",TempStr);
}
function AddItem(id,img,wh,name,parent,location,target,selfLocFunc)
{
var TempStr = "";
var ItemStr = "<!-- ITEM : I_"+id+" -->";
if(id == "sperator")
{
TempStr += ItemStr+"\n";
TempStr += "<tr class='out' onclick='window.event.cancelBubble=true;' onmouseup='window.event.cancelBubble=true;'><td colspan='2' height='1'><hr class='sperator'></td></tr>";
TempStr += "<!-- Insert A Extend Menu or Item On Here For E_"+parent+" -->";
HTMLstr = HTMLstr.replace("<!-- Insert A Extend Menu or Item On Here For E_"+parent+" -->",TempStr);
return;
}
if(HTMLstr.indexOf(ItemStr) != -1)
{
alert("I_"+id+"already exist!");
return;
}
TempStr += ItemStr+"\n";
TempStr += "<tr id='I_"+id+"' class='out'";
TempStr += " onmouseover='I_OnMouseOver(\""+id+"\",\""+parent+"\")'";
TempStr += " onmouseout='I_OnMouseOut(\""+id+"\")'";
TempStr += " onclick='window.event.cancelBubble=true;'";
if(location == null)
TempStr += " onmouseup='I_OnMouseUp(\""+id+"\",\""+parent+"\",null)'";
else
{
TempStr += " onmouseup='I_OnMouseUp(\""+id+"\",\""+parent+"\",\"" + location + "\",\"" + (target == null ?"" : target) + "\",\"" + (selfLocFunc == null ? null : selfLocFunc) + "\")'" ;
//alert(TempStr);
}
TempStr += "><td nowrap>";
TempStr +="<font face='Wingdings' style='font-size:18px'>"+wh+"</font> "+ name+" ";
TempStr += "</td><td></td></tr>\n";
TempStr += "<!-- Insert A Extend Menu or Item On Here For E_"+parent+" -->";
HTMLstr = HTMLstr.replace("<!-- Insert A Extend Menu or Item On Here For E_"+parent+" -->",TempStr);
}
function GetMenu()
{
return HTMLstr;
}
function I_OnMouseOver(id,parent)
{
var Item;
if(parent != "rbpm")
{
var ParentItem;
ParentItem = eval("P_"+parent);
ParentItem.className="over";
}
Item = eval("I_"+id);
Item.className="over";
HideAll(parent,1);
}
function I_OnMouseOut(id)
{
var Item;
Item = eval("I_"+id);
Item.className="out";
}
//selfLocFunc 自定义的loction 方法
function I_OnMouseUp(id,parent,location,target,selfLocFunc)
{
var ParentMenu;
window.event.cancelBubble=true;
OnClick();
ParentMenu = eval("E_"+parent);
ParentMenu.display="none";
if(location == null)
eval("Do_"+id+"()");
else
{
if (selfLocFunc == null || selfLocFunc == '')
if (target == '_blank' || target == '' || target == 'null' )
window.open(location);
else
if (target == '_self')
window.location = location;
else
eval('window.parent.'+ target + '.location = "' + location + '";' );
else
{
var re = /@/i;
//alert(selfLocFunc);
selfLocFunc = selfLocFunc.replace(re,"'");
selfLocFunc = selfLocFunc.replace(re,"'");
eval(selfLocFunc);
}
}
}
function P_OnMouseOver(id,parent)
{
var Item;
var Extend;
var Parent;
if(parent != "rbpm")
{
var ParentItem;
ParentItem = eval("P_"+parent);
ParentItem.className="over";
}
HideAll(parent,1);
Item = eval("P_"+id);
Extend = eval("E_"+id);
Parent = eval("E_"+parent);
Item.className="over";
Extend.style.display="block";
Extend.style.posLeft=document.body.scrollLeft+Parent.offsetLeft+Parent.offsetWidth-4;
if(Extend.style.posLeft+Extend.offsetWidth > document.body.scrollLeft+document.body.clientWidth)
Extend.style.posLeft=Extend.style.posLeft-Parent.offsetWidth-Extend.offsetWidth+8;
if(Extend.style.posLeft < 0) Extend.style.posLeft=document.body.scrollLeft+Parent.offsetLeft+Parent.offsetWidth;
Extend.style.posTop=Parent.offsetTop+Item.offsetTop+1;
if(Extend.style.posTop+Extend.offsetHeight > document.body.scrollTop+document.body.clientHeight)
Extend.style.posTop=document.body.scrollTop+document.body.clientHeight-Extend.offsetHeight;
if(Extend.style.posTop < 0) Extend.style.posTop=0;
}
function P_OnMouseOut(id,parent)
{
}
function HideAll(id,flag)
{
var Area;
var Temp;
var i;
if(!flag)
{
Temp = eval("E_"+id);
Temp.style.display="none";
}
Area = eval("A_"+id);
if(Area.length)
{
for(i=0; i < Area.length; i++)
{
HideAll(Area[i],0);
Temp = eval("E_"+Area[i]);
Temp.style.display="none";
Temp = eval("P_"+Area[i]);
Temp.className="out";
}
}
}
// document.onmouseup=OnMouseUp;
document.onclick=OnClick;
function OnMouseUp()
{
if(window.event.button == 2)
{
if (event.srcElement.tagName=="TEXTAREA"||event.srcElement.tagName=="INPUT")
{
var PopMenu;
var UpdateM;
var cancelM;
var othercourseM;
var setM;
PopMenu = eval("E_rbpm");
HideAll("rbpm",0);
PopMenu.style.display="block";
if (event.srcElement.SliceId!="")
{
othercourseM = eval("I_othercourse");
setM = eval("I_Set");
UpdateM=eval("I_Update");
cancelM=eval("I_cancel");
if(event.srcElement.value=="其他" || event.srcElement.TeachArrangeId==36944)
{
setM.style.display="none";
othercourseM.style.display="block";
}
else
{
setM.style.display="block";
othercourseM.style.display="block";
}
UpdateM.style.display="block";
cancelM.style.display="block";
}
else
{
othercourseM = eval("I_othercourse");
setM = eval("I_Set");
UpdateM=eval("I_Update");
cancelM=eval("I_cancel");
if(event.srcElement.value=="其他" || event.srcElement.TeachArrangeId==36944)
{
setM.style.display="none";
othercourseM.style.display="block";
}
else
{
setM.style.display="block";
othercourseM.style.display="block";
}
UpdateM.style.display="none";
cancelM.style.display="none";
}
//setM=eval("I_Set");
//setM.style.display="none";
PopMenu.style.posLeft=document.body.scrollLeft+window.event.clientX;
PopMenu.style.posTop=document.body.scrollTop+window.event.clientY;
if(PopMenu.style.posLeft+PopMenu.offsetWidth > document.body.scrollLeft+document.body.clientWidth)
PopMenu.style.posLeft=document.body.scrollLeft+document.body.clientWidth-PopMenu.offsetWidth;
if(PopMenu.style.posLeft < 0) PopMenu.style.posLeft=0;
if(PopMenu.style.posTop+PopMenu.offsetHeight > document.body.scrollTop+document.body.clientHeight)
PopMenu.style.posTop=document.body.scrollTop+document.body.clientHeight-PopMenu.offsetHeight;
if(PopMenu.style.posTop < 0) PopMenu.style.posTop=0;
}
}
}
function OnClick()
{
HideAll("rbpm",0);
}
// Add Your Function on following
function Do_viewcode(){window.location="view-source:"+window.location.href;}
function Do_help(){window.showHelp(window.location);}
function Do_exit() {window.close();}
function Do_refresh() {window.location.reload();}
function Do_back() {history.back();}
function Do_forward() {history.forward();}
//页面调用
<script language="javascript" src="js/PopMenu.js"></script>
<script language="javascript">
var id
function PopmenuSelect()
{
OnMouseUp();
var container=window.event.srcElement.parentElement;
var text = container.childNodes(0);
id=text;
}
function Popmenu(location ,action)
{
if(action=="Set")
{
if (window.document .all .Flag.value=="")
{
window.alert ("没有选择课程,请选择!");
return;
}
else
{
eval('window.parent .main.location="'+location+'?action='+action+'&ID='+window.document .all .txtClassId.value+'&Week='+id.WeekNumber+'&SliceNumber='+id.SliceNumber+'&SliceId='+id.SliceId+'";');
}
//eval('window.location="' + location + '?action=' + action + '&Type='+ Type + '&DeptID='+ DeptID + '&DeptName=' + DeptName +'";' );
}
if (action=="update")
{
if (id.SliceId=="")
{
window.alert ("请先安排课程,再安排教室!");
return;
}
else
{
var source="";
//showModalDialog//+'&Id='+id.name
source=window.showModalDialog('selectRoom.aspx?ContentId='+id.SliceId,window,'dialogHeight:430px; dialogWidth:610px; dialogTop:screen.height/4;dialogLeft:screen.width/4; edge: Sunken; center: Yes; help: No; resizable: No; status: No;');
var target=id.ClassroomName;
try
{
if (source.length>0)
{
id.ClassroomName=source;
show();
}
else
{
id.ClassroomName=target;
show();
}
}
catch(e)
{
id.ClassroomName=target;
}
}
}
if (action=="cancel")
{
if (id.SliceId=="")
{
window.alert ("该时间点没有安排课程,不可以进行取消操作!");
return;
}
else
{
eval('window.parent .main.location="'+location+'?action='+action+'&ID='+window.document .all .txtClassId.value+'&Week='+id.WeekNumber+'&SliceNumber='+id.SliceNumber+'&SliceId='+id.SliceId+'";')
}
}
if(action=="othercourse")
{
var topValue = (screen.availHeight-190)/2;
var leftValue =(screen.availWidth- 250)/2;
window.open('SelectOtherCourse.aspx?classid='+window.document.all.txtClassId.value+'&Week='+id.WeekNumber+'&SliceNumber='+id.SliceNumber+'&SliceId='+id.SliceId+'&termid='+document.Form1.ddlTerm.value+'&Arrangeid='+document.Form1.ddlArrange.value,
'window','height=190,width=250,Top='+topValue+',Left='+leftValue+',center=Yes, help= No, resizable= No, status= No');
}
}
function Do_Add()
{
}
function Do_Nothing()
{
}
function Do_Set()
{
Popmenu("ArrangeCourse_Main.aspx","Set");
}
function Do_Update()
{
Popmenu("ArrangeCourse_Main.aspx","update");
}
function Do_cancel()
{
Popmenu("ArrangeCourse_Main.aspx","cancel");
}
function Do_othercourse()
{
Popmenu("ArrangeCourse_Main.aspx","othercourse");
}
var menu = new RightMenu();
//menu.AddItem("Nothing","Nothing",""," 选择操作 ","rbpm");
//menu.AddItem("sperator","","","","rbpm",null);
menu.AddItem("Set","Set",""," 设为选定课程 ","rbpm");
//menu.AddItem("sperator","","","","rbpm",null);
menu.AddItem("Update","Update",""," 选择教室 ","rbpm");
//menu.AddItem("sperator","","","","rbpm",null);
menu.AddItem("cancel","cancel",""," 撤销设定 ","rbpm");
//menu.AddItem("sperator","","","","rbpm",null);
//menu.AddItem("refresh","refresh",""," 刷 新 ","rbpm");
menu.AddItem("othercourse","othercourse",""," 其他课程设定 ","rbpm");
document.writeln(menu.GetMenu());
</script>