⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rightmenu.js

📁 一个用jsp写的完整的论坛源代码
💻 JS
字号:

  function RightMenu(menuID)
  {
  	
    //增加submenu 参数:唯一ID,显示名字,父菜单ID.	
    RightMenu.prototype.AddExtendMenu= function (id,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 += "  &nbsp;&nbsp;"+name+"&nbsp;&nbsp;   </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);
    };
    
    //增加submenu 参数:唯一ID,显示名字,父菜单ID,连接url(输入为null的时候,调用此ID名的事件)
    RightMenu.prototype.AddItem= function (id,name,parent,location)
    {
    
    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+"\")'";
    TempStr += "><td nowrap>";
    TempStr += "  &nbsp;&nbsp;"+name+"&nbsp;&nbsp;  ";
    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);
    };
    
    //返回生成菜单的HTML CODE
    RightMenu.prototype.GetMenu=  function()
    {
    return HTMLstr;
    };
    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();
    eval("A_"+menuID+"= new Array()");
    HTMLstr  = "";
    HTMLstr += "<!-- RightButton PopMenu -->\n";
    HTMLstr += "\n";
    HTMLstr += "<!-- PopMenu Starts -->\n";
    HTMLstr += "<div id='E_"+menuID+"' class='rm_div'>\n";
                        // rbpm = right button pop menu
    HTMLstr += "<table width='100%' border='0' cellspacing='0'>\n";
    HTMLstr += "<!-- Insert A Extend Menu or Item On Here For E_"+menuID+" -->\n";
    HTMLstr += "</table>\n";
    HTMLstr += "</div>\n";
    HTMLstr += "<!-- Insert A Extend_Menu Area on Here For E_"+menuID+" -->";
    HTMLstr += "\n";
    HTMLstr += "<!-- PopMenu Ends -->\n";
  };
   
 
  //移动到菜单项上的方法
  function I_OnMouseOver(id,parent)
  {
    var Item;
    /*
    if(parent != menuID)
    {
      var Parentm = eval("P_"+parent);
      ParentItem.className="over";
    }
    */
    Item = eval("I_"+id);
    Item.className="over";
    HideAll(parent,1);Item;
      
  }
  
  //移出菜单项时的方法
  function I_OnMouseOut(id)
  {
    var Item;
    Item = eval("I_"+id);
    Item.className="out";
  }
  
  //点击菜单项的方法
  function I_OnMouseUp(id,parent,location)
  {
    
    if(event.srcElement.tagName=="FONT"){
    	return 	
    }
    var ParentMenu;
    window.event.cancelBubble=true;
    HideAll("all",0);
    ParentMenu = eval("E_"+parent);
    ParentMenu.display="none";
    if(location == null){
    	
    	//如果菜单项是选择
	if(id.substr(0,6)=="select"){
		
		var txt=trim((document.getElementById("I_"+id)).innerText);
    	 	//alert((document.getElementById("I_"+id)).children[0].tagName);
    	 	//
    	 	if(txt.indexOf("√")==-1){
    	 		//alert("got");v
    	 		(document.getElementById("I_"+id)).children[0].innerText="√"+txt;
    	 		eval(id+"(true)");
    	 		
    	 	}else {
    	 		//alert("no");
    	 		txt=txt.substr(1);
    			(document.getElementById("I_"+id)).children[0].innerText="  "+txt;
    			eval(id+"(false)");
    		}
	}else{
      //eval("Do_"+id+"()");
     		 eval(id+"()");
	}
     }
    else
      window.open(location);
  }
  
  
  //鼠标移过子菜单的触发事件
  function P_OnMouseOver(id,parent)
  {
    var Item;
    var Extend;
    var Parent;
    /*
    if(parent !=menuID)
    {
      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;
    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(id=="all"){
    	for(i=0;i<document.all.length;i++){
      	//alert(document.all.item(i).id);
      	if(document.all.item(i).id.substr(0,2)=="E_"){
      	      PopMenu=eval(document.all.item(i).id);
	      PopMenu.style.display="none";
      	}
      }
    }else{
	    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";
	      }
	    }
    }
  }

 
 

  
  function trim(st){
  	var str=new String(st);
  	return str.replace(/(^\s*)|(\s*$)/g,"");	
  }
  function disabledItem(cmd,itemName,display){
  	if(rng.queryCommandEnabled(cmd)){
  		var obj=eval("document.getElementById('I_"+itemName+"')");
  		obj.firstChild.innerHTML='&nbsp;&nbsp;'+display+'&nbsp;&nbsp;';
      	 }
      	 else{
      	        oldHtml=eval("document.getElementById('I_"+itemName+"').firstChild.innerHTML;");
      	 	var obj=eval("document.getElementById('I_"+itemName+"')");
      	 	obj.firstChild.innerHTML='<font disabled>'+oldHtml+'</font>';
      	 }
  }
  
  //根据用户输入要显示的菜单id,显示右键菜单
  
  function showMenu(menuID)
  
  {   
      window.event.cancelBubble=true;
      evt=window.event.srcElement;
      //如果触发对象是input.或者textarea.就创建一个textrange对象
      //(注意:rng这里现在是全局变量)
      if(evt!=null&&(evt.tagName=="INPUT"||evt.tagName=="TEXTAREA")){
      	 //创建一个选择范围
      	 rng=evt.createTextRange();
	 disabledItem("Cut","cut","剪切");
	disabledItem("Copy","copy","复制");
	disabledItem("Paste","paste","粘贴");
	disabledItem("Delete","Del","删除");
	disabledItem("SelectAll","selAll","全选");
	
      }
 
      HideAll("all",0);
      var PopMenu;
      PopMenu = eval("E_"+menuID);
      HideAll(menuID,0);
      PopMenu.style.display="block";
      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;
	event.returnValue=false;
  }
  
  
  function ClearMenu()
  {
    HideAll("all",0);
  }

//alert('here');
 document.attachEvent("onclick",ClearMenu);
 window.attachEvent("onmouseup",ClearMenu);
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -