home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 May / CHIPCD200305.iso / super / altn / md_en.exe / WHPHOST.JS < prev    next >
Encoding:
JavaScript  |  2003-04-14  |  12.0 KB  |  580 lines

  1. //    WebHelp 5.10.003
  2. var gaProj=new Array();
  3. var gnChecked=0;
  4. var gsProjName="";
  5. var gbReady=false;
  6. var goMan=null;
  7. var gbXML=false;
  8. var gsFirstPane="";
  9. var gServerEnabled=false;
  10. var gsPath="";
  11. var gbWhPHost=false;
  12. var goDiv = null;
  13. var gsHTML = "";
  14.  
  15. if (navigator.currentNavPen)
  16.     gsFirstPane = navigator.currentNavPen;
  17.  
  18.  
  19. function delayLoad()
  20. {
  21.     if (goDiv&&gsHTML)
  22.     {
  23.         goDiv.innerHTML=gsHTML;
  24.         goDiv=null;
  25.         gsHTML="";
  26.     }
  27. }
  28.  
  29. function whCom(sName,sComFile)
  30. {
  31.     this.msName=sName;
  32.     this.msDivId=sName+"Div";
  33.     this.msIFrameId=sName+"IFrame";
  34.     this.msComFile=sComFile;
  35.     this.mbloaded=false;
  36.     this.mbShow=false;
  37.     this.show=function(bShow)
  38.     {
  39.         if(this.mbShow!=bShow)
  40.         {
  41.             if(bShow&&!this.mbloaded)
  42.             {
  43.                 this.load();
  44.             }
  45.  
  46.             var oDiv=getElement(this.msDivId);
  47.             if(oDiv)
  48.             {
  49.                 if(gbIE55||(gbIE5&&gbMac))
  50.                 {
  51.                     var oIframe=getElement(this.msIFrameId);
  52.                     if(oIframe)
  53.                     {
  54.                         if(bShow)
  55.                         {
  56.                             oDiv.style.zIndex=3;
  57.                             if(oIframe!=null)
  58.                             {
  59.                                 oIframe.style.zIndex=3;
  60.                                 if (!gbIE55)
  61.                                     oIframe.style.visibility="visible";
  62.                             }
  63.                         }
  64.                         else
  65.                         {
  66.                             oDiv.style.zIndex=2;
  67.                             if(oIframe!=null)
  68.                             {
  69.                                 oIframe.style.zIndex=2;
  70.                                 if (!gbIE55)
  71.                                     oIframe.style.visibility="hidden";
  72.                             }
  73.                         }
  74.                     }
  75.                 }
  76.                 if (!gbIE55)
  77.                     oDiv.style.visibility=(bShow==true)?'visible':'hidden';
  78.                 this.mbShow=bShow;
  79.             }
  80.  
  81.         }
  82.     }
  83.     this.load=function()
  84.     {
  85.         if(!this.mbloaded)
  86.         {
  87.             if(this.msComFile.length>0){
  88.                 var strFile= _getFullPath(getPath(), this.msComFile);
  89.                 var oDiv=getElement(this.msDivId);
  90.                 if(oDiv){
  91.                     if(gbIE4){
  92.                         var nIFrameHeight=oDiv.style.pixelHeight;
  93.                         var nIFrameWidth=oDiv.style.pixelWidth;
  94.                         var sHTML="<IFRAME ID="+this.msIFrameId+" title=\"" + this.msName + "\" SRC=\""+strFile+"\" BORDER=0 FRAMEBORDER=no STYLE=\"width:";
  95.                         if(gbMac){
  96.                             sHTML+=nIFrameWidth+"px;height:"+nIFrameHeight+"px;\"></IFRAME>";
  97.                         }else{
  98.                             sHTML+="100%; height:100%;\"></IFRAME>";
  99.                         }
  100.                         oDiv.innerHTML=sHTML;
  101.                     }else if(gbNav6){
  102.                         gsHTML="<IFRAME ID="+this.msIFrameId+" title=\"" + this.msName + "\" SRC=\""+strFile+"\" BORDER=0 FRAMEBORDER=no STYLE=\"width:100%;border:0;height:";
  103.                         gsHTML+="100%;\"></IFRAME>";
  104.                         goDiv = oDiv;
  105.                         setTimeout("delayLoad()", 100);
  106.                     }
  107.                     this.mbloaded=true;
  108.                 }
  109.             }
  110.         }
  111.     }
  112.     this.unload=function()
  113.     {
  114.         var oDiv=getElement(this.msDivId);
  115.         if(oDiv)
  116.             oDiv.innerHTML="";
  117.     }
  118.     this.getDivHTML=function()
  119.     {
  120.         var sHTML="";
  121.         if(gbMac&&gbIE4)
  122.             sHTML+="<DIV ID="+this.msDivId+" ALIGN=left STYLE=\"position:absolute;z-index:1;left:0;top:0;width:100%;height:100%;margin:0;padding:0;border:0;\">";
  123.         else
  124.             if (gbIE5)
  125.                 sHTML+="<DIV ID="+this.msDivId+" ALIGN=left STYLE=\"position:absolute;z-index:1;left:0;top:0;width:100%;height:100%;\">";
  126.             else
  127.                 sHTML+="<DIV ID="+this.msDivId+" ALIGN=left STYLE=\"position:absolute;z-index:1;left:0;top:0;width:100%;height:100%;visibility:hidden\">";
  128.         sHTML+="</DIV>";
  129.         return sHTML;
  130.     }
  131. }  
  132.  
  133. function whComMan()
  134. {
  135.     this.sName="";
  136.     this.maCom=new Array();
  137.     this.addCom=function(sName,sComFile)
  138.     {
  139.         var owhCom=new whCom(sName,sComFile);
  140.         this.maCom[this.maCom.length]=owhCom;
  141.     }
  142.     this.init=function()
  143.     {
  144.         var sHTML="";
  145.         for(var i=0;i<this.maCom.length;i++)
  146.         {
  147.             sHTML+=this.maCom[i].getDivHTML();
  148.         }
  149.         document.body.insertAdjacentHTML("beforeEnd",sHTML);
  150.  
  151.     }
  152.     this.showById=function(nId)
  153.     {
  154.         for(var s=0;s<this.maCom.length;s++)
  155.         {
  156.             if(s!==nId)
  157.                 this.maCom[s].show(false);
  158.         }
  159.         this.maCom[nId].show(true);
  160.     }
  161.     this.show=function(sName)
  162.     {
  163.         navigator.currentNavPen = sName;
  164.         var bFound=false;
  165.         for(var i=0;i<this.maCom.length;i++)
  166.         {
  167.             if(sName==this.maCom[i].msName)
  168.             {
  169.                 bFound=true;
  170.                 break;
  171.             }
  172.         }
  173.         if(bFound)
  174.         {
  175.             this.showById(i);
  176.             this.sName=sName;
  177.         }
  178.     }
  179.     this.unload=function()
  180.     {
  181.         for(var i=0;i<this.maCom.length;i++)
  182.         {
  183.             this.maCom[i].unload();
  184.         }        
  185.     }
  186.     this.getCurrent=function()
  187.     {
  188.         return this.sName;
  189.     }
  190. }
  191.  
  192. function getPath()
  193. {
  194.     if(gsPath=="")
  195.     {
  196.         gsPath=location.href;
  197.         gsPath=_replaceSlash(gsPath);
  198.         var nPosFile=gsPath.lastIndexOf("/");
  199.         gsPath=gsPath.substring(0,nPosFile+1);
  200.     }
  201.     return gsPath;
  202. }
  203.  
  204. goMan=new whComMan();
  205. function addPane(sName,sFileName)
  206. {
  207.     var oParam=new Object();
  208.     oParam.sName=sName;
  209.     var oMsg=new whMessage(WH_MSG_GETPANE, this, 1, oParam);
  210.     if (SendMessage(oMsg))
  211.     {
  212.         if (oMsg.oParam.bEnable)
  213.             goMan.addCom(sName,sFileName);
  214.     }
  215.     else
  216.         goMan.addCom(sName,sFileName);    
  217. }
  218.  
  219. function setShowPane(sName, bForce)
  220. {
  221.     if ((gsFirstPane == "") || bForce)
  222.     {
  223.         var oMsg=new whMessage(WH_MSG_GETDEFPANE, this, 1, null);
  224.         if (SendMessage(oMsg))
  225.         {
  226.             if (oMsg.oParam)
  227.                 gsFirstPane = oMsg.oParam;
  228.             else
  229.                 gsFirstPane=sName;
  230.         }
  231.         else
  232.             gsFirstPane=sName;
  233.     }
  234. }
  235.  
  236. function window_OnLoad()
  237. {
  238.     var oMsg=new whMessage(WH_MSG_GETCMD,this,1,null);
  239.     var bHidePane=false;
  240.     if (SendMessage(oMsg))
  241.     {
  242.         if(oMsg.oParam>0)
  243.         {
  244.             if(oMsg.oParam==1)
  245.                 gsFirstPane="toc";
  246.             else if(oMsg.oParam==2)
  247.                 gsFirstPane="idx";
  248.             else if(oMsg.oParam==3)
  249.                 gsFirstPane="fts";
  250.             else if(oMsg.oParam==4)
  251.                 gsFirstPane="glo";
  252.         }
  253.         else if(oMsg.oParam==0)
  254.         {
  255.             bHidePane=true;
  256.         }
  257.     }
  258.     goMan.init();
  259.     if(gsProjName!="")            
  260.         loadData2(gsProjName);    
  261.     if (bHidePane)
  262.     {
  263.         gsFirstPane="";
  264.         var oMsg1=new whMessage(WH_MSG_HIDEPANE, this, 1, null)
  265.         SendMessage(oMsg1);
  266.     }
  267.     else
  268.     {
  269.         if(gsFirstPane!="")
  270.             goMan.show(gsFirstPane);
  271.         else
  272.             goMan.showById(0);
  273.     }
  274. }
  275.  
  276. function setServerEnabled()
  277. {
  278.     gServerEnabled = true;
  279. }
  280.  
  281. function loadData2(strFile)
  282. {
  283.     if(gbXML)
  284.         loadDataXML(strFile);
  285.     else
  286.         loadData(strFile);
  287. }
  288.  
  289. function addProject(bPreferXML,sXMLName,sHTMLName)
  290. {
  291.     var bLoadXML=bPreferXML;
  292.     if(!gbIE4&&!gbNav6)
  293.         return;
  294.     if(gbIE4&&!gbIE5)
  295.         bLoadXML=false;
  296.     if (gbIE5&&!gbMac)
  297.         bLoadXML=true;
  298.     if(gbIE55||gbNav6)
  299.         bLoadXML=true;
  300.     if(bLoadXML)
  301.         addProjectXML(sXMLName);
  302.     else
  303.         addProjectHTML(sHTMLName);
  304. }
  305.  
  306. function addProjectHTML(sName)
  307. {
  308.     gbXML=false;
  309.     gsProjName=sName;
  310. }
  311.  
  312. function addProjectXML(sName)
  313. {
  314.     gbXML=true;
  315.     gsProjName=sName;
  316. }
  317.  
  318. function window_MyBunload()
  319. {
  320.     goMan.unload();
  321.     window_BUnload();
  322. }
  323.  
  324. function putDataXML(xmlDoc,sdocPath)
  325. {
  326.     if(xmlDoc!=null)
  327.     {
  328.         var projectNode=xmlDoc.getElementsByTagName("project")[0];
  329.         if(projectNode)
  330.         {
  331.             var aRProj=new Array();
  332.             aRProj[0]=new Object();
  333.             aRProj[0].sPPath=_getPath(sdocPath);
  334.             var sLangId=projectNode.getAttribute("langid");
  335.             if(sLangId)
  336.             {
  337.                 aRProj[0].sLangId=sLangId;
  338.             }
  339.             var sDPath=projectNode.getAttribute("datapath");
  340.             if(sDPath)
  341.             {
  342.                 if(sDPath.lastIndexOf("/")!=sDPath.length-1)
  343.                     sDPath+="/";
  344.                 aRProj[0].sDPath=sDPath;
  345.             }
  346.             else
  347.                 aRProj[0].sDPath="";
  348.             aRProj[0].sToc=projectNode.getAttribute("toc");
  349.             aRProj[0].sIdx=projectNode.getAttribute("index");
  350.             aRProj[0].sFts=projectNode.getAttribute("fts");
  351.             aRProj[0].sGlo=projectNode.getAttribute("glossary");
  352.             var RmtProject=projectNode.getElementsByTagName("remote");
  353.             var nCount=1;
  354.             for (var i=0;i<RmtProject.length;i++)
  355.             {
  356.                 var sURL=RmtProject[i].getAttribute("url");
  357.                 if(sURL)
  358.                 {
  359.                     if(sURL.lastIndexOf("/")!=sURL.length-1)
  360.                         sURL+="/";
  361.                     aRProj[nCount]=new Object();
  362.                     aRProj[nCount++].sPPath=_getFullPath(aRProj[0].sPPath,sURL);
  363.                 }
  364.             }
  365.             putProjectInfo(aRProj);
  366.         }
  367.         else
  368.         {
  369.             // on Netscape 6.0 under some situation the xml file cannot be loaded.
  370.             // so we use pure html instead.
  371.             if (gnChecked == 0)
  372.                 setTimeout("redirectToList();",100);
  373.             else
  374.             {
  375.                 gnChecked++;
  376.                 checkRemoteProject();
  377.             }
  378.         }
  379.     }
  380. }
  381.  
  382. function onLoadXMLError()
  383. {
  384.     gnChecked++;
  385.     checkRemoteProject();
  386. }
  387.  
  388. function redirectToList()
  389. {
  390.     if(gbReDirectThis)
  391.         document.location=gsNavReDirect;
  392.     else
  393.         parent.document.location=gsNavReDirect;
  394. }
  395.  
  396. function putProjectInfo(aRProj)
  397. {
  398.     if(gnChecked==0||isSamePath(gaProj[gnChecked].sPPath,aRProj[0].sPPath))
  399.     {
  400.         if(gnChecked!=0)
  401.         {
  402.             if(aRProj[0].sLangId!=gaProj[0].sLangId)
  403.                 alert("The merged Help system "+aRProj[0].sPPath+" is using a different language from the master Help system, which will cause the index and full-text search functionality to be disabled in the merged Help system.");
  404.         }
  405.         gaProj[gnChecked]=aRProj[0];
  406.         for(var i=1;i<aRProj.length;i++)
  407.         {
  408.             var bFound=false;
  409.             for(var j=0;j<gaProj.length;j++)
  410.             {
  411.                 if(isSamePath(gaProj[j].sPPath,aRProj[i].sPPath))
  412.                 {
  413.                     bFound=true;
  414.                     break;
  415.                 }
  416.             }
  417.             if(!bFound)
  418.             {
  419.                 gaProj[gaProj.length]=aRProj[i];
  420.             }
  421.         }
  422.         gnChecked++;
  423.         checkRemoteProject();
  424.     }
  425.     else
  426.         alert("Could not load correctly, please click Refresh.");
  427. }
  428.  
  429. function isSamePath(sPath1,sPath2)
  430. {
  431.     return (sPath1.toLowerCase()==sPath2.toLowerCase());
  432. }
  433.  
  434. function checkRemoteProject()
  435. {
  436.     if(gaProj.length!=gnChecked)
  437.     {
  438.         setTimeout("cancelProj("+gnChecked+");",10000);
  439.         loadData2(gaProj[gnChecked].sPPath+gsProjName);
  440.     }
  441.     else{
  442.         var oMsg=new whMessage(WH_MSG_PROJECTREADY,this,1,null);
  443.         gbReady=true;
  444.         SendMessage(oMsg);
  445.     }
  446. }
  447.  
  448. function cancelProj(i)
  449. {
  450.     if(i==gnChecked)
  451.     {
  452.         gnChecked++;
  453.         checkRemoteProject();
  454.     }    
  455. }
  456.  
  457. function window_resize()
  458. {
  459.     for(var i=0;i<goMan.maCom.length;i++)
  460.     {
  461.         var oFrame=getElement(goMan.maCom[i].msIFrameId);
  462.         if(oFrame)
  463.         {
  464.             oFrame.style.height=document.body.clientHeight;
  465.             oFrame.style.width=document.body.clientWidth;
  466.         }
  467.     }
  468.     window_resize2();
  469. }
  470.  
  471. function window_resize2()
  472. {
  473.     if(document.body)
  474.     {
  475.         if(document.body.clientWidth > 1 && document.body.clientHeight>1)
  476.         {
  477.             var oMsg = new whMessage(WH_MSG_RESIZEPANE, this, 1, null);
  478.             SendMessage(oMsg);
  479.         }
  480.     }
  481. }
  482.  
  483. function window_unload()
  484. {
  485.     UnRegisterListener2(this,WH_MSG_GETPROJINFO);
  486.     UnRegisterListener2(this,WH_MSG_SHOWTOC);
  487.     UnRegisterListener2(this,WH_MSG_SHOWIDX);
  488.     UnRegisterListener2(this,WH_MSG_SHOWFTS);
  489.     UnRegisterListener2(this,WH_MSG_SHOWGLO);
  490.     UnRegisterListener2(this,WH_MSG_GETPANEINFO);
  491. }
  492.  
  493. function onSendMessage(oMsg)
  494. {
  495.     if(oMsg)
  496.     {
  497.         var nMsgId=oMsg.nMessageId;
  498.         if(nMsgId==WH_MSG_GETPROJINFO)
  499.         {
  500.             if(gbReady)
  501.             {
  502.                 var oProj=new Object();
  503.                 oProj.aProj=gaProj;
  504.                 oProj.bXML=gbXML;
  505.                 oMsg.oParam=oProj;
  506.             }
  507.             else
  508.                 return false;
  509.         }
  510.         else if(nMsgId==WH_MSG_SHOWTOC)
  511.         {
  512.             if(goMan)
  513.                 goMan.show("toc");
  514.             var onMsg=new whMessage(WH_MSG_PANEINFO, this, 1, "toc");
  515.             SendMessage(onMsg);
  516.             onMsg = new whMessage(WH_MSG_SHOWPANE, this, 1, null);
  517.             SendMessage(onMsg);
  518.         }
  519.         else if(nMsgId==WH_MSG_SHOWIDX)
  520.         {
  521.             if(goMan)
  522.                 goMan.show("idx");
  523.             var onMsg=new whMessage(WH_MSG_PANEINFO, this, 1, "idx");
  524.             SendMessage(onMsg);
  525.             onMsg = new whMessage(WH_MSG_SHOWPANE, this, 1, null);
  526.             SendMessage(onMsg);
  527.         }
  528.         else if(nMsgId==WH_MSG_SHOWFTS)
  529.         {
  530.             if(goMan)
  531.                 goMan.show("fts");
  532.             var onMsg=new whMessage(WH_MSG_PANEINFO, this, 1, "fts");
  533.             SendMessage(onMsg);
  534.             onMsg = new whMessage(WH_MSG_SHOWPANE, this, 1, null);
  535.             SendMessage(onMsg);
  536.         }
  537.         else if(nMsgId==WH_MSG_SHOWGLO)
  538.         {
  539.             if(goMan)
  540.                 goMan.show("glo");
  541.             var onMsg=new whMessage(WH_MSG_PANEINFO, this, 1, "glo");
  542.             SendMessage(onMsg);
  543.             onMsg = new whMessage(WH_MSG_SHOWPANE, this, 1, null);
  544.             SendMessage(onMsg);
  545.         }
  546.         else if(nMsgId==WH_MSG_GETPANEINFO)
  547.         {
  548.             oMsg.oParam=goMan.getCurrent();
  549.             return false;
  550.         }
  551.     }
  552.     return true;
  553. }
  554.  
  555. if(window.gbWhUtil&&window.gbWhMsg&&window.gbWhVer&&window.gbWhProxy)
  556. {
  557.     RegisterListener2(this,WH_MSG_GETPROJINFO);
  558.     RegisterListener2(this,WH_MSG_SHOWTOC);
  559.     RegisterListener2(this,WH_MSG_SHOWIDX);
  560.     RegisterListener2(this,WH_MSG_SHOWFTS);
  561.     RegisterListener2(this,WH_MSG_SHOWGLO);
  562.     RegisterListener2(this,WH_MSG_GETPANEINFO);
  563.  
  564.     if((gbMac&&gbIE4)||(gbSunOS&&gbIE5))
  565.     {
  566.         window.onresize=window_resize;
  567.     }
  568.     else if(gbIE4)
  569.     {
  570.         window.onresize=window_resize2;
  571.     }
  572.     window.onload=window_OnLoad;
  573.     window.onbeforeunload=window_MyBunload;
  574.     window.onunload=window_unload;
  575.     gbWhPHost=true;
  576. }
  577. else
  578.     document.location.reload();
  579.  
  580.