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

📄 whtopic.js

📁 阅读您的文件包然后写出其具体功能(至少要20个字)。尽量不要让站长把时间都花费在为您修正说明上。压缩包解压时不能有密码
💻 JS
📖 第 1 页 / 共 3 页
字号:
			if ( doesTagRecursiveProcess( node ) )
			{
				if ( a_aSuspendedNodes.length > 0 )
				{
					processSuspendNodes( a_aSuspendedNodes );
					a_aSuspendedNodes.length = 0;
				}
			}
			doHighLightDomElement( a_aSuspendedNodes, node );
		}
		else if ( node.nodeType == 3 )
		{	//text
			a_aSuspendedNodes[a_aSuspendedNodes.length] = node;
		}
	}
}

function highlightDocument()
{
	if ( !document.body || document.body == null )
		return;
		
	var aSuspendedNodes = new Array();
	doHighLightDomElement( aSuspendedNodes, document.body );
	processSuspendNodes( aSuspendedNodes );
}

/////// start routine /////////
function IsHighLightRequired()
{
	var bRetVal = false;
	var searchSetting = gsHiliteSearchSetting.match( "^(.+),(.+),(.*)$" );

	if(searchSetting != null)
	{
		if(searchSetting[1] == "enable")
		{
			gsBkgndColor = searchSetting[2];
			gsTextColor = searchSetting[3];
			bRetVal = true;
		}
	}
	return bRetVal;
}

function highlightSearch()
{
	if(!IsHighLightRequired())	return;

	//check pane in focus is Search pane.
	var oMsg=new whMessage(WH_MSG_GETPANEINFO,this,1,null);
	if(SendMessage(oMsg)) {
		if (oMsg.oParam != "fts") 
			return;
	}

	//check highlight result is enabled.
	var oMsg=new whMessage(WH_MSG_HILITESEARCH,this,1,null);
	if(SendMessage(oMsg))
	{
		if(oMsg.oParam == false)
			return;
	}
	
	//check num of results greater than 0
	var oMsg=new whMessage(WH_MSG_GETNUMRSLT,this,1,null);
	if(SendMessage(oMsg))
	{
		if(oMsg.oParam <= 0)
			return;
	}
	
	//get string in search box.
	var oMsg = new whMessage(WH_MSG_GETSEARCHSTR, this, 1, null);
	var strTerms = "";
	if (SendMessage(oMsg))
	{
		strTerms = oMsg.oParam;		
	}
	
	StartHighLightSearch(strTerms);	

}

function StartHighLightSearch(strTerms)
{
	if(!IsHighLightRequired())	return;

	findSearchTerms(strTerms, false);
	
	highlightDocument();
}

//////// common with FTS routines to identify stop word etc. ////////////

function findSearchTerms(searchTerms, bSkip)
{
	if(searchTerms != "")
	{
		var sInput=searchTerms;
		var sCW="";
		var nS=-1;
		var nSep=-1;
		for(var nChar=0;nChar<gsFtsBreakChars.length;nChar++){
			var nFound=sInput.indexOf(gsFtsBreakChars.charAt(nChar));
			if((nFound!=-1)&&((nS==-1)||(nFound<nS))){
				nS=nFound;
				nSep=nChar;
			}
		}
		if(nS==-1){
			sCW=sInput;
			sInput="";
		}
		else
		{
			sCW=sInput.substring(0,nS);
			sInput=sInput.substring(nS+1);
		}

		searchTerms=sInput;
		
		var bAdd = true;
		if((sCW=="or")||(sCW=="|")||(sCW=="OR"))
		{
			bSkip = false;
			bAdd = false;
		}
		else if((sCW=="and")||(sCW=="&")||(sCW=="AND"))
		{
			bSkip = false;
			bAdd = false;
		}
		else if((sCW=="not")||(sCW=="~")||(sCW=="NOT"))
		{
			bSkip = true;
			bAdd = false;
		}

		if(bAdd && !bSkip && sCW!="" && sCW!=" " && !IsStopWord(sCW,gaFtsStop)){
			gaSearchTerms[gaSearchTerms.length] = sCW;
			var stemWord = GetStem(sCW);
			if(stemWord != sCW)
				gaSearchTerms[gaSearchTerms.length] = stemWord;
		}
		findSearchTerms(searchTerms, bSkip);
	}
	
}

function GetStem(szWord)
{
	if(gaFtsStem==null||gaFtsStem.length==0)return szWord;
	if(IsNonAscii(szWord))             return szWord;
	var aStems=gaFtsStem;

	var nStemPos=0;
	var csStem="";
	for(var iStem=0;iStem<aStems.length;iStem++){

		if(aStems[iStem].length>=szWord.length-1)	continue;
		nStemPos=szWord.lastIndexOf(aStems[iStem]);
		if(nStemPos>0){
			var cssub=szWord.substring(nStemPos);
			if(cssub==aStems[iStem]){
				csStem=szWord;
				if(szWord.charAt(nStemPos-2)==szWord.charAt(nStemPos-1)){
					csStem=csStem.substring(0,nStemPos-1);
				}else{
					csStem=csStem.substring(0,nStemPos);
				}
				return csStem;
			}
		}
	}
	return szWord;
}

function IsStopWord(sCW,aFtsStopArray)
{
	var nStopArrayLen=aFtsStopArray.length;
	var nB=0;
	var nE=nStopArrayLen-1;
	var nM=0;
	var bFound=false;
	var sStopWord="";
	while(nB<=nE){
		nM=(nB+nE);
		nM>>=1;
		sStopWord=aFtsStopArray[nM];
		if(compare(sCW,sStopWord)>0){
			nB=(nB==nM)?nM+1:nM;
		}else{
			if(compare(sCW,sStopWord)<0){
				nE=(nE==nM)?nM-1:nM;
			}else{
				bFound=true;
				break;
			}
		}
	}
	return bFound;
}

/////// end highlight search rountines /////////////

function setButtonFont(sType,sFontName,sFontSize,sFontColor,sFontStyle,sFontWeight,sFontDecoration)
{
	var vFont=new whFont(sFontName,sFontSize,sFontColor,sFontStyle,sFontWeight,sFontDecoration);
	gsBtnStyle+=".whtbtn"+sType+"{"+getFontStyle(vFont)+"}";
}

function writeBtnStyle()
{
	if(gaButtons.length>0)
	{
		if(gsBtnStyle.length>0)
		{
			var sStyle="<style type='text/css'>";
			sStyle+=gsBtnStyle+"</style>";
			document.write(sStyle);
		}
	}
}

function button(sText,nWidth,nHeight)
{
	this.sText=sText;
	this.nWidth=nWidth;
	this.nHeight=nHeight;
	
	this.aImgs=new Array();
	var i=0;
	while(button.arguments.length>i+3)
	{
		this.aImgs[i]=button.arguments[3+i];
		i++;
	}
}


//recursively finds the parent project StartPage path if exists 
//also computes the child toc path in the parent toc recursively until 
//main proj

var xmlhttp=null;
var xmlDoc = null;
function processReqChange()
{
   // only if req shows "loaded"
    if (xmlhttp.readyState == 4) 
		xmlDoc = xmlhttp.responseXML;
}

function getPPStartPagePath(sPath)
{
	if(sPath.length != 0)
	{
		var sXmlFolderPath = _getPath(sPath);
		if(sXmlFolderPath.indexOf("/mergedProjects/") == -1 &&
			sXmlFolderPath.indexOf("\\mergedProjects\\") == -1)
			return sPath;
		
		var sdocPath = _getFullPath(sXmlFolderPath, "MasterData.xml");
		try
		{
			if(gbIE5) //Internet Explorer
			{
				xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
				xmlDoc.async=false;
  				xmlDoc.load(sdocPath);
			}
			else if(gbNav6) //Firefox, Mozilla, Opera etc.
			{
				var req=new XMLHttpRequest();
 		        req.open("GET", sdocPath, false);   
	            req.send(null); 
	            xmlDoc = req.responseXML;
			}
			else if(gbSafari3) //Safari
			{ 
				if(window.XMLHttpRequest)
					xmlhttp = new XMLHttpRequest();
				if(xmlhttp)
				{
					xmlhttp.onreadystatechange=processReqChange;
					xmlhttp.open("GET", sdocPath, false);
					xmlhttp.send("");
				}
			}
		}
		catch(e){
			gbBadUriError=true;
			return sPath;
		}

		if(xmlDoc == null) return sPath;			
		var root = xmlDoc.documentElement;
		if(root == null) return sPath;
		var masterProj = null;
		try
		{
			masterProj = xmlDoc.getElementsByTagName("syncinfo");	
			var childTocPosInParent = null;
			if(masterProj)
			{
				var startpage = xmlDoc.getElementsByTagName("startpage");	
				masterStartPageName = startpage[0].getAttribute("name");
				masterStartPageRelPath = startpage[0].getAttribute("url");
				var tocpos = xmlDoc.getElementsByTagName("tocpos");
				childTocPosInParent = tocpos[0].getAttribute("path");
						
			}
		}
		catch(e){return sPath;}
		if(childTocPosInParent)
		{
			childTocPosInParent = childTocPosInParent.replace(/\\n/g, "\n");
			gChildPathInMain = childTocPosInParent +  gChildPathInMain;
		}
		sXmlFolderPath = _getFullPath(sXmlFolderPath, masterStartPageRelPath+masterStartPageName);
		sXmlFolderPath = getPPStartPagePath(sXmlFolderPath);
		return sXmlFolderPath;
	}
}

//project info
function setRelStartPage(sPath)
{
	if(gsPPath.length==0)
	{
		gsPPath=_getFullPath(_getPath(document.location.href),_getPath(sPath));
		gsStartPage=_getFullPath(_getPath(document.location.href),sPath);
		try{
			gsStartPage = getPPStartPagePath(gsStartPage);
		}
		catch(e)
		{
			alert("Error reading masterData.xml");
		}
		gsRelCurPagePath=_getRelativeFileName(gsStartPage,document.location.href);
		for(var i=0; i< gaPaths.length; i++)
			gaPaths[i] = gChildPathInMain + gaPaths[i];
	}
}

function getImage(oImage,sType)
{
	var sImg="";
	if(oImage&&oImage.aImgs&&(oImage.aImgs.length>0))
	{
		sImg+="<img alt=\""+sType+"\" src=\""+oImage.aImgs[0]+"\"";
		if(oImage.nWidth>0)
			sImg+=" width="+oImage.nWidth;
		if(oImage.nHeight>0)
			sImg+=" height="+oImage.nHeight;
		sImg+=" border=0>";
	}
	return sImg;
}

function addTocInfo(sTocPath)
{
	gaPaths[gaPaths.length]=sTocPath;
}


var flex_nextLocation;
var flex_previousLocation;

function addAvenueInfo(sName,sPrev,sNext)
{
	gaAvenues[gaAvenues.length]=new avenueInfo(sName,sPrev,sNext);
	flex_previousLocation = sPrev;
	flex_nextLocation = sNext;
}

function addButton(sType,nStyle,sText,sHref,sOnClick,sOnMouseOver,sOnLoad,nWidth,nHeight,sImg1,sImg2,sImg3)
{
	var sButton="";
	var nBtn=gaButtons.length;
	if(sType=="prev")
	{
		if(canGo(false))
		{
			var sTitle="Previous Topic";
			goPrev=new button(sText,nWidth,nHeight,sImg1,sImg2,sImg3);
			sButton="<a title=\""+sTitle+"\" class=\"whtbtnprev\" href=\"javascript:void(0);\" onclick=\"goAvenue(false);return false;\">";
			if(nStyle==BTN_TEXT)
				sButton+=goPrev.sText;
			else
				sButton+=getImage(goPrev,sTitle);
			sButton+="</a>";
		}
	}
	else if(sType=="next")
	{
		if(canGo(true))
		{
			var sTitle="Next Topic";
			goNext=new button(sText,nWidth,nHeight,sImg1,sImg2,sImg3);
			sButton="<a title=\""+sTitle+"\" class=\"whtbtnnext\" href=\"javascript:void(0);\" onclick=\"goAvenue(true);return false;\">";
			if(nStyle==BTN_TEXT)
				sButton+=goNext.sText;
			else
				sButton+=getImage(goNext,sTitle);
			sButton+="</a>";
		}
	}
	else if(sType=="show")
	{
		if(isTopicOnly()&&(!gbOpera6||gbOpera7))
		{
			var sTitle="Show Navigation Component";
			goShow=new button(sText,nWidth,nHeight,sImg1,sImg2,sImg3);
			sButton="<a title=\""+sTitle+"\" class=\"whtbtnshow\" href=\"javascript:void(0);\" onclick=\"show();return false;\">";
			if(nStyle==BTN_TEXT)
				sButton+=goShow.sText;
			else
				sButton+=getImage(goShow,sTitle);
			sButton+="</a>";
		}
	}
	else if(sType=="hide")
	{
		if(!isTopicOnly()&&!gbOpera6)
		{
			var sTitle="Hide Navigation Component";
			goHide=new button(sText,nWidth,nHeight,sImg1,sImg2,sImg3);
			sButton="<a title=\""+sTitle+"\" class=\"whtbtnhide\" href=\"javascript:void(0);\" onclick=\"hide();return false;\">";
			if(nStyle==BTN_TEXT)
				sButton+=goHide.sText;
			else
				sButton+=getImage(goHide,sTitle);
			sButton+="</a>";
		}
	}
	else if(sType=="shownav")
	{
		if(isShowHideEnable())
		{
			var sTitle="Show Navigation Component";
			goShowNav=new button(sText,nWidth,nHeight,sImg1,sImg2,sImg3);
			sButton="<a title=\""+sTitle+"\" class=\"whtbtnshownav\" href=\"javascript:void(0);\" onclick=\"showHidePane(true);return false;\">";
			if(nStyle==BTN_TEXT)
				sButton+=goShowNav.sText;
			else
				sButton+=getImage(goShowNav,sTitle);
			sButton+="</a>";
		}
	}
	else if(sType=="hidenav")
	{
		if(isShowHideEnable())
		{
			var sTitle="Hide Navigation Component";
			goHideNav=new button(sText,nWidth,nHeight,sImg1,sImg2,sImg3);
			sButton="<a title=\""+sTitle+"\" class=\"whtbtnhidenav\" href=\"javascript:void(0);\" onclick=\"showHidePane(false);return false;\">";
			if(nStyle==BTN_TEXT)
				sButton+=goHideNav.sText;
			else
				sButton+=getImage(goHideNav,sTitle);
			sButton+="</a>";
		}
	}
	else if(sType=="synctoc")
	{
		if(gaPaths.length>0)
		{
			var sTitle="Sync TOC";
			goSync=new button(sText,nWidth,nHeight,sImg1,sImg2,sImg3);
			sButton="<a title=\""+sTitle+"\" class=\"whtbtnsynctoc\" href=\"javascript:void(0);\" onclick=\"syncWithShow();return false;\">";
			if(nStyle==BTN_TEXT)
				sButton+=goSync.sText;
			else
				sButton+=getImage(goSync,sTitle);
			sButton+="</a>";
		}
	}
	else if(sType=="websearch")
	{
		if(gsSearchFormHref.length>0)
		{
			var sTitle="WebSearch";
			goWebSearch=new button(sText,nWidth,nHeight,sImg1,sImg2,sImg3);
			sButton="<a title=\""+sTitle+"\" class=\"whtbtnwebsearch\" href=\""+gsSearchFormHref+"\">";
			if(nStyle==BTN_TEXT)
				sButton+=goWebSearch.sText;
			else
				sButton+=getImage(goWebSearch,sTitle);
			sButton+="</a>";
		}
	}
	else if(sType=="searchform")
	{
		gaButtons[nBtn]="NeedSearchForm";
		gaTypes[nBtn]=sType;
	}
	if(sButton.length!=0)
	{
		if(nStyle==BTN_TEXT)
			sButton+="&nbsp;";
		gaButtons[nBtn]="<td>"+sButton+"</td>";
		gaTypes[nBtn]=sType;
	}
}

function isSyncEnabled()
{
	if(!gbCheckSync)
	{
		var oMsg=new whMessage(WH_MSG_ISSYNCSSUPPORT,this,1,null);

⌨️ 快捷键说明

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