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

📄 hiermenus.js

📁 电脑知识十万个为什么-v1.5注册版.zip
💻 JS
📖 第 1 页 / 共 2 页
字号:
/*hierMenus.js - Cross-Browser/Full-Window
* by Peter Belesis. v3.06a 990624
* Copyright (c) 1999 internet.com LLC. All Rights Reserved.
* Originally published and documented at http://www.dhtmlab.com/
* You may use this code on a public Web site only if this entire
* copyright notice appears unchanged and you publicly display
* on the Web page a link to http://www.dhtmlab.com/.
*
* Contact pbel@internet.com for all other uses.
*/

if(NS4){
	Layer.prototype.dw = function(str){
		this.document.write(str);
		this.document.close();
	}
	origWidth = innerWidth;
	origHeight = innerHeight;
	onresize = function (){
		if (innerWidth==origWidth && innerHeight==origHeight) return;
		initVars();
		NSresized=true;
		location.reload();
	}
}
isLoaded = false;
NSresized = false;

isWin = (navigator.appVersion.indexOf("Win") != -1)
if (!isWin && !isMac) NSfontOver = false;

mSecsVis = secondsVisible*1000;

imgStr = "<IMG SRC='" + imgSrc + "' WIDTH=" + imgSiz + " HEIGHT=" + imgSiz +" BORDER=0 VSPACE=2 ALIGN=RIGHT>";

areCreated = false;
menuLoc = null;

function initVars() {
	if(areCreated) {
		for(i=1; i<topCount; i++) {
			cur = eval("elMenu"+i);
			clearTimeout(cur.hideTimer);
			cur.hideTimer=null;
		}
		clearTimeout(allTimer);
	}
	topCount = 1;
	areCreated = false;
	beingCreated = false;
	isOverMenu = false;
	currentMenu = null;
	allTimer = null;
}

initVars();

function startIt() {
	isLoaded = true;
	menuLoc = window;
	if (clickKill) {
		if (NS4) document.captureEvents(Event.MOUSEDOWN);
		document.onmousedown = clicked;
	}
	makeTop();	
}

function makeTop(){
	beingCreated = true;

	while(eval("window.arMenu" + topCount)) {
		(NS4) ? makeMenuNS(false,topCount) : makeMenuIE(false,topCount);
		topCount++
	}

//	status = (topCount-1) + " Hierarchical Menu Trees Created"
	areCreated = true;
	beingCreated = false;
}


function setObj(isChild,parMenu){

	if (!isChild) {
		this.menuWidth = this.array[0] ? this.array[0] : menuWidth;
		this.menuLeft = this.array[1];
		this.menuTop = this.array[2];
		this.menuFontColor = this.array[3] ? this.array[3] : fntCol;
		this.menuFontOver = this.array[4] ? this.array[4] : overFnt;
		this.menuBGColor = this.array[5] ? this.array[5] : backCol;
		this.menuBGOver = this.array[6] ? this.array[6] : overCol;

		this.menuBorCol = this.array[7] ? this.array[7] : borCol;
		this.menuSeparatorCol = this.array[8] ? this.array[8] : separatorCol;
		this.treeParent = this;
		this.startChild = this;

	}
	else {
		this.menuWidth = parMenu.menuWidth;

		this.menuLeft = parMenu.menuLeft;
		this.menuTop = parMenu.menuTop;
		this.menuFontColor = parMenu.menuFontColor;
		this.menuFontOver = parMenu.menuFontOver;
		this.menuBGColor = parMenu.menuBGColor;
		this.menuBGOver = parMenu.menuBGOver;

		this.menuBorCol = parMenu.menuBorCol;
		this.menuSeparatorCol = parMenu.menuSeparatorCol;
		this.treeParent = parMenu.treeParent;

	}

	this.maxItems = (isChild) ? this.array.length/3 : (this.array.length-9)/3;
	this.hasParent = isChild;
	this.itemCount = 0;
}


function makeMenuNS(isChild,menuCount,parMenu,parItem) {

	menu = new Object()
	menu.lyrid = "elMenu" + menuCount;
	menu.array = eval("arMenu" + menuCount);
	menu.menuWidth = menu.array[0] ? menu.array[0] : menuWidth;
	menu.menuBGColor = menu.array[5] ? menu.array[5] : backCol;

	menu.setObj = setObj;
	menu.setObj(isChild,parMenu);

	menu.itemStr = "";

	while (menu.itemCount < menu.maxItems) {
		menu.itemCount++;
	//	status = "Creating Hierarchical Menus: " + menuCount + " / " + menu.itemCount;
		itemName = "item" + menuCount + "_" + menu.itemCount;

		arrayPointer = (isChild) ? (menu.itemCount-1)*3 :((menu.itemCount-1)*3)+9;
		htmStr = menu.array[arrayPointer];
		hasMore = menu.array[arrayPointer + 2];
		if (fntBold) htmStr = htmStr.bold();
		if (fntItal) htmStr = htmStr.italics();
		htmStr = "<FONT FACE='" + fntFam + "' POINT-SIZE=" + fntSiz + ">" + htmStr+ "</FONT>";
		htmStrOver = htmStr.fontcolor(menu.menuFontOver);
		htmStr = htmStr.fontcolor(menu.menuFontColor);
		htmStr = (hasMore) ? imgStr + htmStr : htmStr;
		htmStrOver = (hasMore) ? imgStr + htmStrOver : htmStrOver;

		eval("menu."+ itemName + "= new Object()")
		eval("menu."+ itemName + ".htmStr = htmStr"); 
		eval("menu."+ itemName + ".htmStrOver = htmStrOver"); 
		menu.itemStr += "<LAYER ID=" + itemName + " WIDTH="+ menu.menuWidth + " BGCOLOR="+ menu.menuBGColor +" LEFT="+ (borWid + itemPad) +">";
		menu.itemStr += "<LAYER WIDTH="+ (menu.menuWidth-(borWid*2)-itemPad) +">"+ htmStr +"</LAYER>";
		menu.itemStr += "<LAYER LEFT="+ (-itemPad) + " TOP="+ (-itemPad) +"></LAYER>";
		menu.itemStr += "</LAYER>";
		if (hasMore) {
			menu.item = "document.elMenu"+ menuCount +".document."+ itemName;
			makeMenuNS(true,menuCount + "_" + menu.itemCount,menu,menu.item);
			menu = menu.parentMenu;
		}
	}
	menu.beginStr = "<LAYER ID=elMenu" + menuCount + " LEFT=0 TOP=0 Z-INDEX=500 VISIBILITY=HIDE WIDTH="+ menu.menuWidth +" BGCOLOR="+ menu.menuBorCol +">";
	document.write(menu.beginStr + menu.itemStr + "</LAYER>");
	eval("elMenu"+menuCount +"=document.elMenu"+menuCount);
	menuLyr = eval("elMenu"+menuCount);
	menuLyr.array = menu.array;

	menuLyr.hasParent = isChild;
	if (!isChild) menuLyr.startChild = menuLyr;
	
	itemColl = menuLyr.document.layers;
	for (var i=0; i<itemColl.length; i++) {
		it = itemColl[i];
		it.menuObj = menu;
		it.setup = itemSetup;
		it.setup(i+1,menuLyr.array);
		menuLyr.lastItem = it;
	}

	menuLyr.menuObj = menu;
	menuLyr.setup = menuSetup;
	menuLyr.setup(isChild,parMenu);
	menu.parentMenu = parMenu;

}

function makeMenuIE(isChild,menuCount,parMenu) {

	menu = new Object()
	menu.lyrid = "elMenu" + menuCount;
	menu.array = eval("arMenu" + menuCount);
	menu.menuWidth = menu.array[0] ? menu.array[0] : menuWidth;
	menu.menuBGColor = menu.array[5] ? menu.array[5] : backCol;

	menu.setObj = setObj;
	menu.setObj(isChild,parMenu);

	menu.itemStr = "";
	while (menu.itemCount < menu.maxItems) {
		menu.itemCount++;
	//	status = "Creating Hierarchical Menus: " + menuCount + " / " + menu.itemCount;

		itemName = "item" + menuCount + "_" + menu.itemCount;

		arrayPointer = (isChild) ? (menu.itemCount-1)*3 :((menu.itemCount-1)*3)+9;
		dispText = menu.array[arrayPointer];
		linkText = menu.array[arrayPointer + 1];
		hasMore = menu.array[arrayPointer + 2];
		htmStr = (hasMore) ? imgStr + dispText : dispText;
		menu.itemStr += "<SPAN ID=" + itemName + " STYLE='width:" + menu.menuWidth + ";background-color:"+ menu.menuBGColor +";";
		menu.itemStr += "padding:"+ itemPad +";color:"+ menu.menuFontColor +";";
		menu.itemStr += "font-size:"+ fntSiz +"pt;font-weight:"+ ((fntBold) ? "bold;" : "normal;");
		menu.itemStr += "font-style:"+ ((fntItal) ? "italic;" : "normal;");
		menu.itemStr += "font-family:"+ fntFam +";";
		if(menu.itemCount < menu.maxItems)menu.itemStr += "border-bottom:"+ separator + "px "+ menu.menuSeparatorCol +" solid;";
		menu.itemStr += "cursor:"+ ((linkText) ? "hand;" : "default;");
		menu.itemStr += "'>" + htmStr + "</SPAN><BR>";

		if (hasMore) {
			makeMenuIE(true,menuCount + "_" + menu.itemCount,menu);
			menu = menu.parentMenu;
		}	
	}

	menu.beginStr = "<DIV ID=elMenu" + menuCount + " onSelectStart='return false' STYLE='position:absolute;left:0;top:0;z-index:500;";
	menu.beginStr += "width:"+ menu.menuWidth +";";
	menu.beginStr += "border:"+ borWid +" "+ menu.menuBorCol +" "+ borSty +";";
	menu.beginStr += "'>";
	document.write( menu.beginStr + menu.itemStr + "</DIV>");
	menuLyr = eval("elMenu"+menuCount);
	menuLyr.array = menu.array;


	menuLyr.hasParent = isChild;
	if (!isChild) menuLyr.startChild = menuLyr;


	itemColl = menuLyr.children.tags("SPAN");
	for (var i=0; i<itemColl.length; i++) {
		it = itemColl(i);
		it.menuObj = menu;
		it.setup = itemSetup;
		it.setup(i+1,menuLyr.array);
		menuLyr.lastItem = it;
	}

	menuLyr.menuObj = menu;
	menuLyr.setup = menuSetup;
	menuLyr.setup(isChild,parMenu);
	menu.parentMenu = parMenu;
}

function itemSetup(whichItem,whichArray) {
	this.onmouseover = itemOver;
	this.onmouseout = itemOut;

	this.container = (NS4) ? this.parentLayer : this.offsetParent;

	arrayPointer = (this.menuObj.hasParent) ? (whichItem-1)*3 : ((whichItem-1)*3)+9;

	this.linkText = whichArray[arrayPointer + 1];
	this.hasMore = whichArray[arrayPointer + 2];

	if (this.hasMore) {
		this.child = eval("elMenu" + this.id.substr(4));
		this.child.parentMenu = this.container;
		this.child.parentItem = this;
	}

	if (this.linkText) {
		if (NS4) {
			this.captureEvents(Event.MOUSEUP)
			this.onmouseup = linkIt;
		}
		else {
			this.onclick = linkIt;
		}
	}

	if (NS4) {
		this.htmStr = eval("this.menuObj."+ this.id + ".htmStr");
		this.htmStrOver = eval("this.menuObj."+ this.id + ".htmStrOver");
		if (whichItem != 1)	this.top = this.siblingBelow.top + this.siblingBelow.clip.height + separator;
		else this.top = (borWid + itemPad)

		this.clip.top = this.clip.left = -itemPad;
		this.clip.right = (this.menuObj.menuWidth-(borWid*2)-itemPad);
		this.txtLyr = this.document.layers[0];
		this.clip.bottom = this.txtLyr.document.height+itemPad;
		this.dummyLyr = this.document.layers[1];
		this.dummyLyr.clip.width = this.clip.width;
		this.dummyLyr.clip.height = this.clip.height;
	}
}	

function menuSetup(hasParent,openCont) {
	this.onmouseover = menuOver;
	this.onmouseout = menuOut;
	
	this.showIt = showIt;
	this.keepInWindow = keepInWindow;
	this.hideTree = hideTree
	this.hideParents = hideParents;
	this.hideChildren = hideChildren;
	this.hideTop = hideTop;
	this.hasChildVisible = false;
	this.isOn = false;
	this.hideTimer = null;


	this.menuWidth = this.menuObj.menuWidth;
	this.menuLeft = this.menuObj.menuLeft;
	this.menuTop = this.menuObj.menuTop;
	this.menuFontColor = this.menuObj.menuFontColor;
	this.menuFontOver = this.menuObj.menuFontOver;
	this.menuBGColor = this.menuObj.menuBGColor;

	this.childOverlap = (perCentOver != null) ? ((perCentOver/100) * this.menuWidth) : childOverlap;
	this.currentItem = null;
	this.hideSelf = hideSelf;
		
	this.hasParent = hasParent

	if (NS4) {
		this.fullHeight = this.lastItem.top + this.lastItem.clip.bottom + borWid;
		this.clip.top = 0;
		this.clip.right = this.menuWidth;
		this.clip.bottom = this.fullHeight;

⌨️ 快捷键说明

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