whihost.js
上传用户:aonuowh
上传日期:2021-05-23
资源大小:35390k
文件大小:11k
源码类别:

SNMP编程

开发平台:

C/C++

  1. var gsDefaultTarget="bsscright";
  2. var gsBgColor="#ffffff";
  3. var gsBgImage="";
  4. var goIdxFont=null;
  5. var goIdxEmptyFont=null;
  6. var goIdxHoverFont=null;
  7. var gsIdxMargin="0pt";
  8. var gsIdxIndent="8pt";
  9. var gsIdxActiveBgColor="#cccccc";
  10. var gsCK = null;
  11. var gsBCK = null;
  12. var gbCR = false;
  13. var gbBCR = false;
  14. var gbWhIHost=true;
  15. function myEvent()
  16. {
  17. this.pageX = 0;
  18. this.pageY = 0;
  19. }
  20. var _event=new myEvent();
  21. function setBackgroundcolor(sBgColor)
  22. {
  23. gsBgColor=sBgColor;
  24. }
  25. function setBackground(sBgImage)
  26. {
  27. gsBgImage=sBgImage;
  28. }
  29. function setFont(sType,sFontName,sFontSize,sFontColor,sFontStyle,sFontWeight,sFontDecoration)
  30. {
  31. var vFont=new whFont(sFontName,sFontSize,sFontColor,sFontStyle,sFontWeight,sFontDecoration);
  32. if(sType=="Normal")
  33. goIdxFont=vFont;
  34. else if(sType=="Empty")
  35. goIdxEmptyFont=vFont;
  36. else if(sType=="Hover")
  37. goIdxHoverFont=vFont;
  38. }
  39. function setActiveBgColor(sBgColor)
  40. {
  41. gsIdxActiveBgColor=sBgColor;
  42. }
  43. function setMargin(sMargin)
  44. {
  45. gsIdxMargin=sMargin;
  46. }
  47. function setIndent(sIndent)
  48. {
  49. gsIdxIndent=sIndent;
  50. }
  51. function writeOneItem(oHTML,bDown,aDataCon,aCurIdxSet,nLength,aPos,nLevel)
  52. {
  53. var sHTML="";
  54. var nIdxSet=aCurIdxSet[0];
  55. var nIIdx=aPos[nIdxSet];
  56. var sKOriName=getItemName(aDataCon,nIdxSet,nIIdx);
  57. var sKName=_textToHtml(sKOriName);
  58. var nIdxIndent=parseInt(gsIdxIndent);
  59. var sTopics="";
  60. if(nLevel==1){
  61. if(getItemType(aDataCon,nIdxSet,nIIdx)==1)
  62. {
  63. sHTML+="<H6><nobr>";
  64. sHTML+="<b>"+sKName+"</b></nobr></H6>";
  65. }
  66. else{
  67. for(var i=0;i<nLength;i++)
  68. sTopics+=getIdxTopics(aDataCon,aCurIdxSet[i],aPos[aCurIdxSet[i]]);
  69. sHTML+="<p style="margin-left:"+gsIdxIndent+""><nobr>";
  70. sHTML+="<a alt="" + sKName + "" href="javascript:void(0);" onfocus="clearHighLight();" onclick="PopupMenu_Invoke(event,'"+getTargetName(aDataCon,nIdxSet,nIIdx)+"'";
  71. if(sTopics.length>0)
  72. sHTML+=sTopics+");return false;">"+sKName+"</a></nobr></p>";
  73. else
  74. sHTML+=");return false;" style=""+getFontStyle(goIdxEmptyFont)+"">"+sKName+"</a></nobr></p>";
  75. }
  76. }
  77. else if(nLevel>=2){
  78. var nIndent=nIdxIndent*nLevel;
  79. for(var i=0;i<nLength;i++)
  80. sTopics+=getIdxTopics(aDataCon,aCurIdxSet[i],aPos[aCurIdxSet[i]]);
  81. if (nLevel==2)
  82. sHTML+="<h6 class="firstsub" style="margin-left:"+nIndent+"pt"><nobr>";
  83. else
  84. sHTML+="<h6 style="margin-left:"+nIndent+"pt"><nobr>";
  85. sHTML+="<a alt="" + sKName + "" href="javascript:void(0);" onfocus="clearHighLight();" onclick="PopupMenu_Invoke(event,'"+getTargetName(aDataCon,nIdxSet,nIIdx)+"'";
  86. if(sTopics.length>0)
  87. sHTML+=sTopics+");return false;">"+sKName+"</a></nobr></h6>";
  88. else
  89. sHTML+=");return false;" style=""+getFontStyle(goIdxEmptyFont)+"">"+sKName+"</a></nobr></h6>";
  90. }
  91. oHTML.addHTML(sHTML,nLength,bDown,(nLevel==1),sKOriName);
  92. }
  93. function getTargetName(aDataCon,nIdxSet,nIIdx)
  94. {
  95. if(nIdxSet<aDataCon.length&&aDataCon[nIdxSet].aKs.length>nIIdx)
  96. if(aDataCon[nIdxSet].aKs[nIIdx].sTarget)
  97. return aDataCon[nIdxSet].aKs[nIIdx].sTarget;
  98. return gsDefaultTarget;
  99. }
  100. function mergeItems(oHTML,bDown,aDataCon,aCurIdxSet,nLength,aPos,nLevel)
  101. {
  102. var oLocalHTML=new indexHTMLPart();
  103. writeOneItem(oLocalHTML,bDown,aDataCon,aCurIdxSet,nLength,aPos,nLevel);
  104. var aLocalPos=new Array();
  105. var aMaxPos=new Array();
  106. for(var i=0;i<aPos.length;i++)
  107. {
  108. aLocalPos[i]=aPos[i];
  109. aMaxPos[i]=-1;
  110. }
  111. for(i=0;i<nLength;i++)
  112. {
  113. var nNKOff=getNKOff(aDataCon,aCurIdxSet[i],aLocalPos[aCurIdxSet[i]]);
  114. aLocalPos[aCurIdxSet[i]]++;
  115. if(nNKOff>0)
  116. aMaxPos[aCurIdxSet[i]]=aLocalPos[aCurIdxSet[i]]+nNKOff;
  117. }
  118. var oSubHTML=new indexHTMLPart();
  119. writeItems(oSubHTML,aDataCon,aLocalPos,null,aMaxPos,true,nLevel+1);
  120. oLocalHTML.addSubHTML(oSubHTML,true);
  121. oHTML.appendHTML(oLocalHTML,bDown);
  122. }
  123. function adjustPosition(bDown,aDataCon,aCurIdxSet,nLength,aPos)
  124. {
  125. if(bDown)
  126. {
  127. for(var i=0;i<nLength;i++)
  128. {
  129. var nNKOff=getNKOff(aDataCon,aCurIdxSet[i],aPos[aCurIdxSet[i]]);
  130. aPos[aCurIdxSet[i]]+=(1+nNKOff);
  131. }
  132. }
  133. else{
  134. for(var i=0;i<nLength;i++)
  135. {
  136. var nPKOff=getPKOff(aDataCon,aCurIdxSet[i],aPos[aCurIdxSet[i]]);
  137. aPos[aCurIdxSet[i]]-=(1+nPKOff);
  138. }
  139. }
  140. }
  141. function getItemName(aDataCon,nIdxSet,nIIdx)
  142. {
  143. if(nIdxSet<aDataCon.length&&aDataCon[nIdxSet].aKs.length>nIIdx)
  144. return aDataCon[nIdxSet].aKs[nIIdx].sName;
  145. else
  146. return null;
  147. }
  148. function getItemType(aDataCon,nIdxSet,nIIdx)
  149. {
  150. if(nIdxSet<aDataCon.length&&aDataCon[nIdxSet].aKs.length>nIIdx)
  151. return aDataCon[nIdxSet].aKs[nIIdx].nType;
  152. else
  153. return 0;
  154. }
  155. function getNKOff(aDataCon,nIdxSet,nIIdx)
  156. {
  157. if(nIdxSet<aDataCon.length&&aDataCon[nIdxSet].aKs.length>nIIdx)
  158. return aDataCon[nIdxSet].aKs[nIIdx].nNKOff;
  159. else
  160. return null;
  161. }
  162. function getPKOff(aDataCon,nIdxSet,nIIdx)
  163. {
  164. if(nIdxSet<aDataCon.length&&aDataCon[nIdxSet].aKs.length>nIIdx)
  165. return aDataCon[nIdxSet].aKs[nIIdx].nPKOff;
  166. else
  167. return null;
  168. }
  169. function window_OnLoad()
  170. {
  171. if(gsBgImage&&gsBgImage.length>0)
  172. {
  173. document.body.background=gsBgImage;
  174. }
  175. if(gsBgColor&&gsBgColor.length>0)
  176. {
  177. document.body.bgColor=gsBgColor;
  178. }
  179. document.body.insertAdjacentHTML("beforeEnd",writeLoadingDiv());
  180. loadIdx();
  181. var oMsg=new whMessage(WH_MSG_SHOWIDX,this,1,null)
  182. SendMessage(oMsg);
  183. }
  184. function loadIdx()
  185. {
  186. if(!gbReady)
  187. {
  188. var oResMsg=new whMessage(WH_MSG_GETPROJINFO,this,1,null);
  189. if(SendMessage(oResMsg)&&oResMsg.oParam)
  190. {
  191. gbReady=true;
  192. var oProj=oResMsg.oParam;
  193. var aProj=oProj.aProj;
  194. gbXML=oProj.bXML;
  195. if(aProj.length>0)
  196. {
  197. var sLangId=aProj[0].sLangId;
  198. for(var i=0;i<aProj.length;i++)
  199. {
  200. if(aProj[i].sIdx!=null&&aProj[i].sIdx!=""&&aProj[i].sLangId==sLangId)
  201. {
  202. addProjInfo(aProj[i].sPPath,aProj[i].sDPath,aProj[i].sIdx);
  203. }
  204. }
  205. }
  206. writeDataIFrame();
  207. enEvt();
  208. }
  209. }
  210. }
  211. function getIdxTopics(aDataCon,nIdxSet,nIIdx)
  212. {
  213. var sTopics="";
  214. if(nIdxSet<aDataCon.length&&aDataCon[nIdxSet].aKs.length>nIIdx)
  215. {
  216. if(aDataCon[nIdxSet].aKs[nIIdx].aTopics)
  217. {
  218. var nLen=aDataCon[nIdxSet].aKs[nIIdx].aTopics.length;
  219. var nProj=aDataCon[nIdxSet].nProjId;
  220. var sPath=gaData[nProj].sPPath;
  221. for(var i=0;i<nLen;i++)
  222. {
  223. var sURL=aDataCon[nIdxSet].aKs[nIIdx].aTopics[i].sURL;
  224. var sFullPath=_getFullPath(sPath,sURL);
  225. sTopics+=",'"+excapeSingleQuot(_textToHtml(aDataCon[nIdxSet].aKs[nIIdx].aTopics[i].sName))+"','"+_textToHtml_nonbsp(sFullPath)+"'";
  226. }
  227. }
  228. }
  229. return sTopics;
  230. }
  231. function excapeSingleQuot(str)
  232. {
  233. if(str==null) return null;
  234. var sRes=str;
  235. var re=new RegExp("'","g");
  236. sRes=sRes.replace(re,"\'");
  237. return sRes;
  238. }
  239. function findCKInDom()
  240. {
  241. if(gsCK!=null)
  242. {
  243. var sK=gsCK;
  244. var oP=getElementsByTag(document,"P");
  245. if(!oP) return false;
  246. var len=oP.length;
  247. var nB=0;
  248. var nE=len-1;
  249. var nM=0;
  250. var sItem="";
  251. var bF=false;
  252. while(nB<nE){
  253. nM=(nB+nE+1)>>1;
  254. sItem=getInnerText(oP[nM]);
  255. if(compare(sItem,sK)==0)
  256. {
  257. bF=true;
  258. break;
  259. }
  260. else if(compare(sItem,sK)>0)
  261. nE=nM-1;
  262. else if(compare(sItem,sK)<0)
  263. nB=nM;
  264. }
  265. if(!bF)
  266. {
  267. if(nB==nE) nM=nB;
  268. if(nM+1<len)
  269. {
  270. sItem=getInnerText(oP[nM+1]);
  271. if(compare(sItem,sK)<=0) nM++;
  272. }
  273. if(nM+1<len)
  274. {
  275. sItem=getInnerText(oP[nM+1]);
  276. if(compare(sItem.substring(0,sK.length),sK)==0) nM++;
  277. }
  278. }
  279. var oMatch=oP[nM];
  280. if(oMatch)
  281. {
  282. window.scrollTo(0,oMatch.offsetTop);
  283. var tempColl=getElementsByTag(oMatch,"A");
  284. if(tempColl&&tempColl.length>0){
  285. var nbTag=getElementsByTag(oMatch,"NOBR");
  286. if(nbTag&&nbTag.length>0)
  287. HighLightElement(nbTag[0], gsIdxActiveBgColor, "transparent");
  288. if (gbCR)
  289. {
  290. if (gbIE4)
  291. tempColl(0).click();
  292. else
  293. {
  294. var strCommand = tempColl[0].getAttribute("onClick");
  295. var nstrCommand = strCommand.indexOf(";");
  296. strCommand = strCommand.substring(0, nstrCommand);
  297. strCommand = strCommand.replace("event", "_event");
  298. window._event.pageX = oMatch.offsetLeft ;
  299. window._event.pageY = oMatch.offsetTop + 20;
  300. window.setTimeout(strCommand, 100);
  301. }
  302. }
  303. }
  304. }
  305. gsCK=gsBCK;
  306. gbCR=gbBCR;
  307. if(gsBCK!=null)
  308. {
  309. gsBCK=null;
  310. gbBCR=false;
  311. findCK();
  312. return false;
  313. }
  314. }
  315. return true;
  316. }
  317. function clearHighLight()
  318. {
  319. resetHighLight(gsBgColor);
  320. }
  321. function IndexWriteClassStyle()
  322. {
  323. var sStyle="";
  324. sStyle+="<STYLE TYPE='text/css'>";
  325. if (gsBgImage)
  326. sStyle+="body {border-top:"+gsBgColor+" 1px solid;}n";
  327. else
  328. sStyle+="body {border-top:black 1px solid;}n";
  329. if(gbIE4&&gbMac&&!gbIE5)
  330. {
  331. var nMargin=parseInt(gsIdxMargin);
  332. nMargin-=10;
  333. sStyle+="P {"+getFontStyle(goIdxFont)+"margin-top:"+gsIdxMargin+";margin-bottom:"+gsIdxMargin+";}n";
  334. sStyle+="H6 {"+getFontStyle(goIdxFont)+"margin-top:"+gsIdxMargin+";margin-bottom:"+gsIdxMargin+";}n";
  335. sStyle+="H6.firstsub {"+getFontStyle(goIdxFont)+"margin-top:"+nMargin+"pt;margin-bottom:"+gsIdxMargin+";}n";
  336. }
  337. else
  338. {
  339. sStyle+="P {"+getFontStyle(goIdxFont)+"margin-top:"+gsIdxMargin+";margin-bottom:"+gsIdxMargin+";}n";
  340. sStyle+="H6 {"+getFontStyle(goIdxFont)+"margin-top:"+gsIdxMargin+";margin-bottom:"+gsIdxMargin+";}n";
  341. }
  342. sStyle+="DIV {margin-top:"+gsIdxMargin+";margin-bottom:"+gsIdxMargin+";}n";
  343. sStyle+="A:link {"+getFontStyle(goIdxFont)+"}n";
  344. sStyle+="A:visited {"+getFontStyle(goIdxFont)+"}n";
  345. sStyle+="A:active {background-color:"+gsIdxActiveBgColor+";}n";
  346. sStyle+="A:hover {"+getFontStyle(goIdxHoverFont)+"}n";
  347. sStyle+="</STYLE>";
  348. document.write(sStyle);
  349. return;
  350. }
  351. function window_Unload()
  352. {
  353. UnRegisterListener2(this,WH_MSG_PROJECTREADY);
  354. UnRegisterListener2(this,WH_MSG_SEARCHINDEXKEY);
  355. }
  356. function onSendMessage(oMsg)
  357. {
  358. if(oMsg)
  359. {
  360. var nMsgId=oMsg.nMessageId;
  361. if(nMsgId==WH_MSG_SEARCHINDEXKEY)
  362. {
  363. if(oMsg.oParam && oMsg.oParam.sInput)
  364. {
  365. if(gsCK==null)
  366. {
  367. gsCK=oMsg.oParam.sInput;
  368. gbCR = oMsg.oParam.bCR;
  369. findCK();
  370. }
  371. else
  372. {
  373. gsBCK=oMsg.oParam.sInput;
  374. gbBCR = oMsg.oParam.bCR;
  375. }
  376. }
  377. }
  378. else if(nMsgId==WH_MSG_PROJECTREADY)
  379. {
  380. loadIdx();
  381. }
  382. }
  383. return true;
  384. }
  385. if(window.gbWhVer&&window.gbWhLang&&window.gbWhMsg&&window.gbWhUtil&&window.gbWhHost&&window.gbWhProxy)
  386. {
  387. RegisterListener2(this,WH_MSG_PROJECTREADY);
  388. RegisterListener2(this,WH_MSG_SEARCHINDEXKEY);
  389. goIdxFont=new whFont("Verdana","8pt","#000000","normal","normal","none");
  390. goIdxEmptyFont=new whFont("Verdana","8pt","#666666","normal","normal","none");
  391. goIdxHoverFont=new whFont("Verdana","8pt","#007f00","normal","normal","underline");
  392. window.onload=window_OnLoad;
  393. window.onbeforeunload=window_BUnload;
  394. window.onunload=window_Unload;
  395. gbWhIHost=true;
  396. }
  397. else
  398. document.location.reload();