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

📄 whthost.js

📁 阅读您的文件包然后写出其具体功能(至少要20个字)。尽量不要让站长把时间都花费在为您修正说明上。压缩包解压时不能有密码
💻 JS
📖 第 1 页 / 共 3 页
字号:
		{
			for(var j=0;j<aRelTocPaths.length;j++)
				for (var k=0;k<gaRoot[i].aRPath.length;k++)
				{
					var sPath=gaRoot[i].aRPath[k]+aRelTocPaths[j];
					aPaths[aPaths.length]=sPath.substring(1);
				}
			break;
		}
	return aPaths;
}

function syncInit()
{
	if(gsTP&&!gbNeedFillStub)
	{
		gInSync=true;
		var obj=document.body;
		var aIdList=new Array();
		var nRet=expandToc(obj,gsTP,aIdList);
		if(nRet!=-1)
		{
			if(nRet==1)
			{
				if(aIdList.length)
					for(var i=0;i<aIdList.length-1;i++)
						ExpandIt2(aIdList[i],true);
				gsCTPath=gsTP;
				HighLightElement(aIdList[aIdList.length-1],gsABgColor,"transparent");
				aIdList[aIdList.length-1].focus();
				gsTP=null;
			}
			if(gaBTPs!=""&&gaBTPs!=null)
			{
				var aPaths=gaBTPs;
				gsTP=null;
				gaBTPs=null;
				if(aPaths!=null)
				{
					var sPath=getClosestTocPath(aPaths);
					if(sPath!=null)
					{	
						gsTP=sPath;		
						setTimeout("syncInit()",1);
					}
				}
			}
		}
		gInSync=false;
	}
}

function loadToc()
{
	if(!gbLoadToc)
	{
		var oResMsg=new whMessage(WH_MSG_GETPROJINFO,this,1,null);
		if(SendMessage(oResMsg)&&oResMsg.oParam)
		{
			gbLoadToc=true;
			var oProj=oResMsg.oParam;
			gaProj=oProj.aProj;
			gbXML=oProj.bXML;
			load1B1();
		}
	}
}

function load1B1()
{
	if(gnLT+1<gaProj.length)
		for(var i=gnLT+1;i<gaProj.length;i++)
			if(gaProj[i].sToc)
			{
				gbToc=true;
				gnLT=i;
				setTimeout("loadTocInfo()",1);
				return true;
			}
	return false;
}

function loadTocInfo()
{
	loadData2(gaProj[gnLT].sPPath+gaProj[gnLT].sDPath+gaProj[gnLT].sToc);
}

function loadData2(sFile)
{
	if(gbXML)
		loadDataXML(sFile);
	else
		loadData(sFile);
}

function projReady(sRoot,aProj)
{
	if(gaRoot.length<=gnLT||!gaRoot[gnLT])
		gaRoot[gnLT]=new Object();
	gaRoot[gnLT].sToc=sRoot;
	
	if(gnLT==0)
	{
		gaRoot[gnLT].aRPath=new Array();
		gaRoot[gnLT].aRPath[0]=gsPathSplit;
	}

	updatePTPath(gnLT,aProj);

	if(!((gnLT+1<gaProj.length)&&load1B1()))
	{
		gbReady=true;
		if(gbIE4)
			setTimeout("loadImages();",1);
		else
			setTimeout("loadTData();",1);
	}
}

function loadTData()
{
	if(gaProj[0].sToc!="")
	{
		gbLData=true;
		goChunk=addTocChunk(gaProj[0].sPPath,gaProj[0].sDPath);
		gbToc=false;
		loadData2(gaProj[0].sPPath+gaProj[0].sDPath+gaRoot[0].sToc);
	}
}

function updatePTPath(n,aProj)
{
	if(aProj)
		for(var i=0;i<aProj.length;i++)
		{
			var sFullPath=_getFullPath(gaProj[n].sPPath,aProj[i].sPPath);
			for(var j=0;j<gaProj.length;j++)
				if(isSamePath(sFullPath,gaProj[j].sPPath))
				{
					if(gaRoot.length<=j||!gaRoot[j])
						gaRoot[j]=new Object();
					if(!gaRoot[j].aRPath)
						gaRoot[j].aRPath=new Array();

					if(gaRoot[n].aRPath)
						for(var k=0;k<gaRoot[n].aRPath.length;k++)
						{
							var bDup=false;
							var sTFPath=gaRoot[n].aRPath[k]+aProj[i].sRPath;
							for(var l=0;l<gaRoot[j].aRPath.length;l++)
								if(gaRoot[j].aRPath[l]==sTFPath)
								{
									bDup=true;
									break;
								}
							if(!bDup)
								gaRoot[j].aRPath[gaRoot[j].aRPath.length]=sTFPath;
						}
					else
						gaRoot[j].aRPath[gaRoot[j].aRPath.length]=aProj[i].sRPath;
					break;
				}
		}
}

function onLoadXMLError()
{
	if(gbToc)
	{
		var sRoot="";
		var aRProj=new Array();
		projReady(sRoot,aRProj);
	}
	else
	{
		var aToc=new Array();
		putData(aToc)
	}
}

function putDataXML(xmlDoc,sDocPath)
{
	if(gbToc)
	{
		var tocNode=xmlDoc.getElementsByTagName("toc")[0];
		if(tocNode)
		{
			var sRoot=tocNode.getAttribute("root");
			var rmtProject=tocNode.getElementsByTagName("project");
			var aRProj=new Array();
			if(rmtProject.length>0)
			{
				for(var i=0;i<rmtProject.length;i++)
				{
					aRProj[i]=new Object();
					var sURL=rmtProject[i].getAttribute("url");
					if(sURL)
					{
						if(sURL.lastIndexOf("/")!=sURL.length-1)
							sURL+="/";						
					}
					aRProj[i].sPPath=sURL;
					aRProj[i].sRPath = "";
					var oSubPath = rmtProject[i].getElementsByTagName("subpath")[0];
					if (oSubPath)
					{
						while (oSubPath)
						{
							aRProj[i].sRPath += oSubPath.getAttribute("name") + "\n";
							oSubPath = oSubPath.getElementsByTagName("subpath")[0];
						}
					}
					else
						aRProj[i].sRPath=rmtProject[i].getAttribute("path");
				}
			}
			projReady(sRoot,aRProj);
		}
	}
	else
	{
		var chunkNode=xmlDoc.getElementsByTagName("tocdata")[0];
		if(chunkNode)
		{
			var aToc=new Array();
			processBook(chunkNode,aToc);
			putData(aToc);
		}
	}
}

function processBook(node,aToc)
{
	var i=0;
	var entry=null;
	var prevEntry=null;
	var oChild=node.firstChild;
	do{
		if(oChild)
		{
			if(oChild.nodeName.indexOf("#")!=0)
			{
				var sName=oChild.getAttribute("name");
				var sURL=oChild.getAttribute("url");
				var sRef=oChild.getAttribute("ref");
				var sTarget=oChild.getAttribute("target");
				var sIcons=oChild.getAttribute("images");
				var item=new Object();
				item.sItemName=sName;
				if(sTarget)
					item.sTarget=sTarget;
				if(sIcons)
					item.sIconRef=sIcons;
				if(sURL==null) sURL="";

				item.sItemURL=sURL;
				
				if(oChild.nodeName=="book")
				{
					item.nType=1;
					aToc[aToc.length]=item;
					var nCurrPos=aToc.length;
					processBook(oChild,aToc);
					item.nContents=aToc.length-nCurrPos;
				}
				else if(oChild.nodeName=="item")
				{
					item.nType=2;
					item.nContents=0;
					aToc[aToc.length]=item;
				}
				else if(oChild.nodeName=="remoteitem")
				{
					item.nType=16;
					item.nContents=0;
					aToc[aToc.length]=item;
				}
				else if(oChild.nodeName=="project")
				{
					if(sRef)
					{
						if(sRef.lastIndexOf("/")!=sRef.length-1)
							sRef+="/";						
					}
					item.nType=4;
					item.sRefURL=sRef;
					item.nContents=0;
					aToc[aToc.length]=item;
				}
				else if(oChild.nodeName=="chunk")
				{
					item.nType=8;
					item.sRefURL=sRef;
					item.nContents=0;
					aToc[aToc.length]=item;
				}
			}
		}
		else
			break;
		oChild=oChild.nextSibling;
	}while(true);
}

function putData(aTocs)
{
	gaTocsNs61Fix=aTocs;
	setTimeout("realPutData();",1);
}

function realPutData()
{
	removeLoadingDiv();
	var aTocs=gaTocsNs61Fix;
	if(!aTocs) return;
	if(goChunk)
	{
		var n=gnMinIdx;
		goChunk.nMI=gnMinIdx;
		goChunk.aTocs=aTocs;
		gnMinIdx+=aTocs.length;
		if(gnInsIdx!=-1)
		{
			var oObj=getElement(getPBId(gnInsIdx));
			if(oObj)
			{
				oObj.insertAdjacentHTML("afterEnd",writeBookItems(n-1,aTocs.length));
				setTimeout("syncInit()",1);
			}
		}
		else{
			document.body.insertAdjacentHTML("beforeEnd",writeBookItems(n-1,aTocs.length));
			var oParam=new Object();
			oParam.oTocInfo=null;
			var oMsg=new whMessage(WH_MSG_GETTOCPATHS,this,1,oParam);
			if(SendMessage(oMsg))
			{
				if(oMsg.oParam.oTocInfo)
					syncWithPaths(oMsg.oParam.oTocInfo);
			}
		}	
	}
	gbLData=false;
	checkFillStub();
}

function syncWithPaths(oTopicParam)
{
	var aPaths=getTocPaths(oTopicParam);
	if(gsTP)
		gaBTPs=aPaths;
	else{
		var sPath=getClosestTocPath(aPaths);
		if(sPath!=null)
		{
			gsTP=sPath;
			setTimeout("syncInit()",1);
		}
	}
}

function window_OnLoad()
{
	if(gsBgImage&&gsBgImage.length>0)
	{
		document.body.background=gsBgImage;
	}
	if(gsBgColor&&gsBgColor.length>0)
	{
		document.body.bgColor=gsBgColor;
	}
	loadToc();
	var oMsg=new whMessage(WH_MSG_SHOWTOC,this,1,null)
	SendMessage(oMsg);
}

function loadImages()
{
	if(giBookClose)
	{
		gaImgs[gnImages]=giBookClose;
		gnImages++;
	}		
	if(giBookOpen)
	{
		gaImgs[gnImages]=giBookOpen;
		gnImages++;
	}		
	if(giBookItem)
	{
		gaImgs[gnImages]=giBookItem;
		gnImages++;
	}		
	if(giURLItem)
	{
		gaImgs[gnImages]=giURLItem;
		gnImages++;
	}		
	if(giNewBookClose)
	{
		gaImgs[gnImages]=giNewBookClose;
		gnImages++;
	}		
	if(giNewBookOpen)
	{
		gaImgs[gnImages]=giNewBookOpen;
		gnImages++;
	}		
	if(giNewBookItem)
	{
		gaImgs[gnImages]=giNewBookItem;
		gnImages++;
	}		
	if(giNewURLItem)
	{
		gaImgs[gnImages]=giNewURLItem;
		gnImages++;
	}
	if(gnImages>0)
	{
		setTimeout("loadDataAfter();",1000);
		loadImage(gaImgs[0]);
	}
	else
		loadDataAfter();
}

function loadImage(sURL)
{
	var oImg=new Image();
	oImg.onload=checkImageLoading;
	oImg.onerror=errorImageLoading;
	oImg.src=_getFullPath(gaProj[0].sPPath,sURL);
}

function loadDataAfter()
{
	if(!gbLoadData)
	{
		gbLoadData=true;
		loadTData();
	}
}

function errorImageLoading()
{
	gnLoadedImages++;
	if(gnImages==gnLoadedImages)
		loadDataAfter();
	else
		loadImage(gaImgs[gnLoadedImages]);	
}

function checkImageLoading()
{
	gnLoadedImages++;
	if(gnImages==gnLoadedImages)
		loadDataAfter();
	else
		loadImage(gaImgs[gnLoadedImages]);	
}

function window_unload()
{
	UnRegisterListener2(this,WH_MSG_PROJECTREADY);
	UnRegisterListener2(this,WH_MSG_SYNCTOC);
	UnRegisterListener2(this,WH_MSG_SHOWTOC);
}

function onSendMessage(oMsg)
{
	if(oMsg)
	{
		var nMsgId=oMsg.nMessageId;
		if(nMsgId==WH_MSG_PROJECTREADY)
		{
			loadToc();
		}
		else if(nMsgId==WH_MSG_SYNCTOC)
		{
			if(gbReady)
			{
				syncWithPaths(oMsg.oParam);
			}
		}
		else if(nMsgId==WH_MSG_SHOWTOC)
		{
			if(!gbNav6)
				document.body.focus();
		}
	}
	return true;
}

if(window.gbWhUtil&&window.gbWhVer&&window.gbWhMsg&&window.gbWhProxy)
{
	RegisterListener2(this,WH_MSG_PROJECTREADY);
	RegisterListener2(this,WH_MSG_SYNCTOC);
	RegisterListener2(this,WH_MSG_SHOWTOC);
	goFont=new whFont("Verdana","8pt","#000000","normal","normal","none");
	goHFont=new whFont("Verdana","8pt","#007f00","normal","normal","underline");

	window.onload=window_OnLoad;
	window.onbeforeunload=window_BUnload;
	window.onunload=window_unload;
	gbWhTHost=true;
}
else
	document.location.reload();

⌨️ 快捷键说明

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