home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 October / CHIP1002.ISO / exe / COMPUGUI.exe / whphost.js < prev    next >
Encoding:
Text File  |  2002-04-23  |  11.0 KB  |  527 lines

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