www.pudn.com > 下拉菜单.rar > menu.js


if (document.all)    {n=0;ie=1;fShow="visible";fHide="hidden";} 
if (document.layers) {n=1;ie=0;fShow="show";   fHide="hide";} 
 
topY = 0;rightX = 0;bottomY = 0;leftX = 0; 
lastMenu = null; 
var mstyle; 
 
function MenuStyle() 
{ 
	this.bgColor     = "#008000"; 
	this.menuFont; 
	this.menuFontIE  = "bold xx-small Verdana"; 
	this.menuFontNS  = "bold x-small Verdana"; 
 
	this.clsMenuItemIE = "class=clsMenuItemIE"; 
	this.clsMenuItemNS = "class=clsMenuItemNS"; 
 
	this.mainMenuWidth = "100%"; 
 
	this.mainMenuBorder = 0; 
	this.subMenuBorder  = 0; 
	this.menuDelta = 3; 
 
	this.subMenueWidth = 100; 
 
	this.bMenuStatic = 0; 
 
	this.TranslateStyle = TranslateStyle; 
} 
 
function TranslateStyle() 
{ 
	if (n)  this.menuFont = this.menuFontNS; 
	if (ie) this.menuFont = this.menuFontIE; 
} 
 
 
function Menu(ms) 
{ 
	ms.TranslateStyle(); 
	mstyle = ms; 
 
	this.addItem    = addItem; 
	this.addSubItem = addSubItem; 
	this.showMenu   = showMenu; 
	this.displaySubMenu = displaySubMenu; 
 
 
 
	HTMLstr = ""; 
	HTMLstr += "\n"; 
	HTMLstr += "\n"; 
 
	if (ie) 
	{ 
	  if (mstyle.bMenuStatic > 0) HTMLstr += "
\n"; else HTMLstr += "
\n"; } if (n) { if (mstyle.bMenuStatic > 0) HTMLstr += "\n"; else HTMLstr += "\n"; } HTMLstr += "\n"; HTMLstr += "\n"; HTMLstr += "
\n"; HTMLstr += "
\n"; HTMLstr += "\n"; HTMLstr += "\n"; HTMLstr += "\n"; HTMLstr += "
\n"; HTMLstr += "
\n"; if (ie) HTMLstr+= "
\n"; if (n) { if (mstyle.bMenuStatic > 0) HTMLstr+= "\n"; else HTMLstr+= "\n"; } HTMLstr += "\n"; HTMLstr += "\n"; HTMLstr += "\n"; HTMLstr += "\n"; HTMLstr += "\n"; HTMLstr += "\n"; } function addItem(idItem, text, hint, location, altLocation) { var Lookup = ""; if (HTMLstr.indexOf(Lookup) != -1) { alert(idParent + " already exist"); return; } var MENUitem = ""; MENUitem += "\n\n"; if (n) { MENUitem += "\n"; MENUitem += ""; if (location == null) MENUitem += ""; else MENUitem += ""; MENUitem += " | "; MENUitem += text; MENUitem += ""; MENUitem += ""; MENUitem += "\n"; } if (ie) { MENUitem += "\n"; MENUitem += "
\n"; MENUitem += "\n"; MENUitem += "
\n"; MENUitem += "\n"; } MENUitem += "\n\n"; MENUitem += "\n"; HTMLstr = HTMLstr.replace("\n", MENUitem); } function addSubItem(idParent, text, hint, location, frame) { var MENUitem = ""; Lookup = ""; if (HTMLstr.indexOf(Lookup) == -1) { alert(idParent + " not found"); return; } Lookup = ""; if (HTMLstr.indexOf(Lookup) == -1) { if (n) { MENUitem += "\n"; MENUitem += "\n"; MENUitem += "\n"; MENUitem += "\n"; MENUitem += "
\n"; MENUitem += "
\n"; MENUitem += "\n"; } if (ie) { MENUitem += "\n"; MENUitem += "\n"; MENUitem += "\n"; } MENUitem += "\n"; HTMLstr = HTMLstr.replace("\n", MENUitem); } Lookup = "\n"; if (n) { MENUitem = "

\n"; } if (ie) { MENUitem = "

\n"; } MENUitem += Lookup; HTMLstr = HTMLstr.replace(Lookup, MENUitem); } function showMenu() { document.writeln(HTMLstr); if (mstyle.bMenuStatic > 0) UpdateIt(); } //////////////////////////////////////////////////////////////////////////// // Private declaration function displaySubMenu(idMainMenu) { var menu; var submenu; if (n) { submenu = document.layers[idMainMenu+"submenu"]; smp = document.layers["SmartMenu"].document.layers["SmartMenuPane"]; submenu.left = smp.document.layers[idMainMenu].pageX; submenu.top = document.layers["SmartMenu"].pageY+smp.clip.height+3; submenu.visibility = fShow; leftX = submenu.left; rightX = leftX + submenu.clip.width; topY = document.layers["SmartMenu"].pageY; bottomY = topY+document.layers["SmartMenu"].clip.height+submenu.clip.height; } else if (ie) { menu = eval(idMainMenu); submenu = eval(idMainMenu+"submenu.style"); smp = document.all["SmartMenu"]; submenu.left = calculateSumOffset(menu, 'offsetLeft'); submenu.top = calculateSumOffset(document.all["SmartMenu"], 'offsetTop')+smp.offsetHeight+mstyle.menuDelta; submenu.visibility = fShow; leftX = document.all[idMainMenu+"submenu"].style.posLeft; rightX = leftX + document.all[idMainMenu+"submenu"].offsetWidth; topY = document.all["SmartMenu"].offsetTop; bottomY = topY+document.all["SmartMenu"].offsetHeight+ document.all[idMainMenu+"submenu"].offsetHeight; } lastMenu = submenu; } function hideAll() { if (lastMenu != null) {lastMenu.visibility = fHide;lastMenu.left = 0;} } function calculateSumOffset(idItem, offsetName) { var totalOffset = 0; var item = eval('idItem'); do { totalOffset += eval('item.'+offsetName); item = eval('item.offsetParent'); } while (item != null); return totalOffset; } function updateIt(e) { if (ie) { var x = window.event.clientX; var y = window.event.clientY+document.body.scrollTop; if (x > rightX || x < leftX) hideAll(); else if (y < topY || y > bottomY) hideAll(); } if (n) { var x = e.pageX; var y = e.pageY; if (x > rightX || x < leftX) hideAll(); else if (y > bottomY || y < topY) hideAll(); } } function UpdateIt() { if (ie) document.all["SmartMenu"].style.top = document.body.scrollTop; if (n) document.layers["SmartMenu"].top = top.pageYOffset; setTimeout("UpdateIt()", 200); } if (document.all) { document.body.onclick=hideAll; document.body.onscroll=hideAll; document.body.onmousemove=updateIt; } if (document.layers) { document.onmousedown=hideAll; window.captureEvents(Event.MOUSEMOVE); window.onmousemove=updateIt; }