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

  1. var gsPPath = "";
  2. var gaPaths = new Array();
  3. var gaAvenues = new Array();
  4.  
  5. var goFrame = null;
  6. var gsStartPage = "";
  7. var gsRelCurPagePath = "";
  8. var gsSearchFormHref  = "";
  9. var gnTopicOnly = -1;
  10. var gnOutmostTopic = -1;
  11.  
  12. var BTN_TEXT=1;
  13. var BTN_IMG=2;
  14.  
  15. var goSync = null;
  16.  
  17. var goShow = null;
  18. var goHide = null;
  19.  
  20. var goPrev = null;
  21. var goNext = null;
  22. var gnForm = 0;
  23. var goShowNav = null;
  24. var goHideNav = null;
  25.  
  26. var goWebSearch = null;
  27.  
  28. var gsBtnStyle = "";
  29. var gaButtons = new Array();
  30. var gaTypes = new Array();
  31. var whtopic_foldUnload = null;
  32. var gbWhTopic=false;
  33. var gbCheckSync=false;
  34. var gbSyncEnabled=false;
  35.  
  36. function setButtonFont(sType, sFontName,sFontSize,sFontColor,sFontStyle,sFontWeight,sFontDecoration)
  37. {
  38.     var vFont=new whFont(sFontName,sFontSize,sFontColor,sFontStyle,sFontWeight,sFontDecoration);
  39.     gsBtnStyle += ".whtbtn" + sType + "{"+getFontStyle(vFont) + "}";
  40. }
  41.  
  42. function writeBtnStyle()
  43. {
  44.     if (gaButtons.length > 0)
  45.     {
  46.         if (gsBtnStyle.length > 0)
  47.         {
  48.             var sStyle = "<style type='text/css'>";
  49.             sStyle+= gsBtnStyle + "</style>";
  50.             document.write(sStyle);
  51.         }
  52.     }
  53. }
  54.  
  55. function button(sText, nWidth, nHeight)
  56. {
  57.     this.sText = sText;
  58.     this.nWidth = nWidth;
  59.     this.nHeight = nHeight;
  60.     
  61.     this.aImgs = new Array();
  62.     var i = 0;
  63.     while (button.arguments.length > i + 3)
  64.     {
  65.         this.aImgs[i] = button.arguments[3 + i];
  66.         i ++;
  67.     }
  68. }
  69.  
  70. // project info
  71. function setRelStartPage(sPath)
  72. {
  73.     if (gsPPath.length == 0)
  74.     {
  75.         gsPPath = _getFullPath(_getPath(document.location.href),  _getPath(sPath));
  76.         gsStartPage = _getFullPath(_getPath(document.location.href), sPath);
  77.         gsRelCurPagePath = _getRelativeFileName(gsStartPage, document.location.href);
  78.     }
  79. }
  80.  
  81. function getImage(oImage, sType)
  82. {
  83.     var sImg="";
  84.     if (oImage && oImage.aImgs && (oImage.aImgs.length > 0))
  85.     {
  86.         sImg+="<img alt=\""+ sType + "\" src=\"" + oImage.aImgs[0] + "\"";
  87.         if (oImage.nWidth > 0)
  88.             sImg+=" width=" + oImage.nWidth;
  89.         if (oImage.nHeight > 0)
  90.             sImg+=" height=" + oImage.nHeight;
  91.         sImg+=" border=no>";
  92.     }
  93.     return sImg;
  94. }
  95.  
  96. function addTocInfo(sTocPath)
  97. {
  98.     gaPaths[gaPaths.length] = sTocPath;
  99. }
  100.  
  101. function addAvenueInfo(sName, sPrev, sNext)
  102. {
  103.     gaAvenues[gaAvenues.length] = new avenueInfo(sName, sPrev, sNext);    
  104. }
  105.  
  106. function addButton(sType, nStyle, sText, sHref, sOnClick, sOnMouseOver, sOnLoad, nWidth, nHeight, sImg1, sImg2, sImg3)
  107. {
  108.     var sButton = "";
  109.     var nBtn=gaButtons.length;
  110.     if (sType == "prev")
  111.     {
  112.         if (canGo(false))
  113.         {
  114.             var sTitle = "Vorheriges Thema";
  115.             goPrev = new button(sText, nWidth, nHeight, sImg1, sImg2, sImg3);
  116.             sButton = "<a title=\"" + sTitle + "\" class=\"whtbtnprev\" href=\"javascript:void(0);\" onclick=\"goAvenue(false);return false;\">";
  117.             if (nStyle == BTN_TEXT)
  118.                 sButton += goPrev.sText;
  119.             else
  120.                 sButton += getImage(goPrev, sTitle);
  121.             sButton += "</a>";
  122.         }
  123.     }
  124.     else if (sType == "next")
  125.     {
  126.         if (canGo(true))
  127.         {
  128.             var sTitle = "NΣchstes Thema";
  129.             goNext = new button(sText, nWidth, nHeight, sImg1, sImg2, sImg3);
  130.             sButton = "<a title=\"" + sTitle + "\" class=\"whtbtnnext\" href=\"javascript:void(0);\" onclick=\"goAvenue(true);return false;\">";
  131.             if (nStyle == BTN_TEXT)
  132.                 sButton += goNext.sText;
  133.             else
  134.                 sButton += getImage(goNext, sTitle);
  135.             sButton += "</a>";
  136.         }
  137.     }
  138.     else if (sType == "show")
  139.     {
  140.         if (isTopicOnly())
  141.         {
  142.             var sTitle = "Navigationskomponente anzeigen";
  143.             goShow = new button(sText, nWidth, nHeight, sImg1, sImg2, sImg3);
  144.             sButton = "<a title=\"" + sTitle + "\" class=\"whtbtnshow\" href=\"javascript:void(0);\" onclick=\"show();return false;\">";
  145.             if (nStyle == BTN_TEXT)
  146.                 sButton += goShow.sText;
  147.             else
  148.                 sButton += getImage(goShow, sTitle);
  149.             sButton += "</a>";
  150.         }
  151.     }
  152.     else if (sType == "hide")
  153.     {
  154.         if (!isTopicOnly())
  155.         {
  156.             var sTitle = "Navigationskomponente verdecken";
  157.             goHide = new button(sText, nWidth, nHeight, sImg1, sImg2, sImg3);
  158.             sButton = "<a title=\"" + sTitle + "\" class=\"whtbtnhide\" href=\"javascript:void(0);\" onclick=\"hide();return false;\">";
  159.             if (nStyle == BTN_TEXT)
  160.                 sButton += goHide.sText;
  161.             else
  162.                 sButton += getImage(goHide, sTitle);
  163.             sButton += "</a>";
  164.         }
  165.     }
  166.     else if (sType == "shownav")
  167.     {
  168.         
  169.         if (isShowHideEnable())
  170.         {
  171.             var sTitle = "Navigationskomponente anzeigen";
  172.             goShowNav = new button(sText, nWidth, nHeight, sImg1, sImg2, sImg3);
  173.             sButton = "<a title=\"" + sTitle + "\" class=\"whtbtnshownav\" href=\"javascript:void(0);\" onclick=\"showHidePane(true);return false;\">";
  174.             if (nStyle == BTN_TEXT)
  175.                 sButton += goShowNav.sText;
  176.             else
  177.                 sButton += getImage(goShowNav, sTitle);
  178.             sButton += "</a>";
  179.         }
  180.     }
  181.     else if (sType == "hidenav")
  182.     {
  183.         if (isShowHideEnable())
  184.         {
  185.             var sTitle = "Navigationskomponente verdecken";
  186.             goHideNav = new button(sText, nWidth, nHeight, sImg1, sImg2, sImg3);
  187.             sButton = "<a title=\"" + sTitle + "\" class=\"whtbtnhidenav\" href=\"javascript:void(0);\" onclick=\"showHidePane(false);return false;\">";
  188.             if (nStyle == BTN_TEXT)
  189.                 sButton += goHideNav.sText;
  190.             else
  191.                 sButton += getImage(goHideNav, sTitle);
  192.             sButton += "</a>";
  193.         }
  194.     }
  195.     else if (sType == "synctoc")
  196.     {
  197.         if (gaPaths.length > 0)
  198.         {
  199.             var sTitle = "Inhaltsangabe synchronisieren";
  200.             goSync = new button(sText, nWidth, nHeight, sImg1, sImg2, sImg3);
  201.             sButton = "<a title=\""+ sTitle + "\" class=\"whtbtnsynctoc\" href=\"javascript:void(0);\" onclick=\"syncWithShow();return false;\">";
  202.             if (nStyle == BTN_TEXT)
  203.                 sButton += goSync.sText;
  204.             else
  205.                 sButton += getImage(goSync, sTitle);
  206.             sButton += "</a>";
  207.         }
  208.     }
  209.     else if (sType == "websearch")
  210.     {
  211.         if (gsSearchFormHref.length > 0)
  212.         {
  213.             var sTitle = "WebSearch";
  214.             goWebSearch = new button(sText, nWidth, nHeight, sImg1, sImg2, sImg3);
  215.             sButton = "<a title=\""+ sTitle + "\" class=\"whtbtnwebsearch\" href=\"" + gsSearchFormHref + "\">";
  216.             if (nStyle == BTN_TEXT)
  217.                 sButton += goWebSearch.sText;
  218.             else
  219.                 sButton += getImage(goWebSearch, sTitle);
  220.             sButton += "</a>";
  221.         }
  222.     }
  223.     else if (sType == "searchform")
  224.     {
  225.         gaButtons[nBtn] = "NeedSearchForm";
  226.         gaTypes[nBtn] = sType;
  227.     }
  228.     if (sButton.length != 0)
  229.     {
  230.         if (nStyle == BTN_TEXT)
  231.             sButton += " ";
  232.         gaButtons[nBtn] = "<td>" + sButton + "</td>";
  233.         gaTypes[nBtn] = sType;
  234.     }
  235. }
  236.  
  237. function isSyncEnabled()
  238. {
  239.     if (!gbCheckSync)
  240.     {
  241.         var oMsg=new whMessage(WH_MSG_ISSYNCSSUPPORT,this,1,null);
  242.         if(SendMessage(oMsg))
  243.         {
  244.             gbSyncEnabled=oMsg.oParam;
  245.         }
  246.         gbCheckSync=true;
  247.     }
  248.     return gbSyncEnabled;
  249. }
  250.  
  251. function isInPopup()
  252. {
  253.     return (window.name.indexOf("BSSCPopup") != -1);
  254. }
  255.  
  256. function getIntopicBar(sAlign)
  257. {
  258.     var sHTML = "";
  259.     if (gaButtons.length > 0)
  260.     {
  261.         sHTML += "<div align="+ sAlign + ">";
  262.  
  263.         sHTML += "<table cellpadding=\"2\" cellspacing=\"0\" border=\"0\"><tr>";
  264.         for (var i = 0; i < gaButtons.length; i++)
  265.         {
  266.             if (gaTypes[i]!="synctoc" || isSyncEnabled())
  267.             {
  268.                 if (gaButtons[i] == "NeedSearchForm")
  269.                     sHTML += getSearchFormHTML();
  270.                 else
  271.                     sHTML += gaButtons[i];
  272.             }
  273.         }
  274.         sHTML += "</tr></table>";
  275.  
  276.         sHTML += "</div>";
  277.     }
  278.     return sHTML;
  279. }
  280.  
  281.  
  282. function writeIntopicBar(nAligns)
  283. {
  284.     if (isInPopup()) return;
  285.     if (gaButtons.length > 0)
  286.     {
  287.         var sHTML = "";
  288.         if (nAligns != 0)
  289.         {
  290.             sHTML += "<table width=100%><tr>"
  291.             if (nAligns & 1)
  292.                 sHTML += "<td width=33%>" + getIntopicBar("left") + "</td>";
  293.             if (nAligns & 2)
  294.                 sHTML += "<td width=34%>" + getIntopicBar("center") + "</td>";
  295.             if (nAligns & 4)
  296.                 sHTML += "<td width=33%>" + getIntopicBar("right") + "</td>";
  297.             sHTML += "</tr></table>";
  298.             document.write(sHTML);
  299.         }
  300.     }
  301. }
  302.  
  303. function sendAveInfoOut()
  304. {
  305.     if (!isInPopup())
  306.         setTimeout("sendAveInfo();", 100);
  307. }
  308.  
  309. function sendAveInfo()
  310. {
  311.     var oMsg = new whMessage(WH_MSG_AVENUEINFO, this, 1, gaAvenues);
  312.     SendMessage(oMsg);
  313. }
  314.  
  315.  
  316. function onNext()
  317. {
  318.     var oMsg = new whMessage(WH_MSG_NEXT, this, 1, null);
  319.     SendMessage(oMsg);
  320. }
  321.  
  322. function onPrev()
  323. {
  324.     var oMsg = new whMessage(WH_MSG_PREV, this, 1, null);
  325.     SendMessage(oMsg);
  326. }
  327.  
  328. function createSyncInfo()
  329. {
  330.     var oParam = new Object();
  331.     if (gsPPath.length == 0)
  332.         gsPPath = _getPath(document.location.href);
  333.     oParam.sPPath = gsPPath;
  334.     oParam.sTPath = document.location.href;
  335.     oParam.aPaths = gaPaths;
  336.     return oParam;
  337. }
  338.  
  339. function syncWithShow()
  340. {
  341.     if (isTopicOnly())
  342.         show();
  343.     else 
  344.     {
  345.         sync();
  346.         showTocPane();
  347.     }
  348. }
  349.  
  350. function showTocPane()
  351. {
  352.     var oMsg = new whMessage(WH_MSG_SHOWTOC, this, 1, null);
  353.     SendMessage(oMsg);
  354. }
  355.  
  356. function sendSyncInfo()
  357. {
  358.     if (!isInPopup())
  359.     {
  360.         var oParam = null;
  361.         if (gaPaths.length > 0)
  362.         {
  363.             oParam = createSyncInfo();
  364.         }
  365.         var oMsg = new whMessage(WH_MSG_SYNCINFO, this, 1, oParam);
  366.         SendMessage(oMsg);
  367.     }
  368. }
  369.  
  370. function sendInvalidSyncInfo()
  371. {
  372.     if (!isInPopup())
  373.     {
  374.         var oMsg = new whMessage(WH_MSG_SYNCINFO, this, 1, null);
  375.         SendMessage(oMsg);
  376.     }
  377. }
  378.  
  379. function enableWebSearch(bEnable)
  380. {
  381.     if (!isInPopup())
  382.     {
  383.         var oMsg = new whMessage(WH_MSG_ENABLEWEBSEARCH, this, 1, bEnable);
  384.         SendMessage(oMsg);
  385.     }
  386. }
  387.  
  388. function autoSync(nSync)
  389. {
  390.     if (nSync == 0) return;
  391.     if (isInPopup()) return;
  392.     if (isOutMostTopic())
  393.         sync();
  394. }
  395.  
  396. function isOutMostTopic()
  397. {
  398.     if (gnOutmostTopic == -1)
  399.     {
  400.         var oMessage = new whMessage(WH_MSG_ISINFRAMESET, this, 1 , null);
  401.         if (SendMessage(oMessage))
  402.             gnOutmostTopic = 0;
  403.         else
  404.             gnOutmostTopic = 1;
  405.     }
  406.     return (gnOutmostTopic == 1);
  407. }
  408.  
  409. function sync()
  410. {
  411.     if (gaPaths.length > 0)
  412.     {
  413.         var oParam = createSyncInfo();
  414.         var oMessage = new whMessage(WH_MSG_SYNCTOC, this, 1, oParam);
  415.         SendMessage(oMessage);
  416.     }
  417. }
  418.  
  419.  
  420. function avenueInfo(sName, sPrev, sNext)
  421. {
  422.     this.sName = sName;
  423.     this.sPrev = sPrev;
  424.     this.sNext = sNext;
  425. }
  426.  
  427. function getCurrentAvenue()
  428. {
  429.     var oParam = new Object();
  430.     oParam.sAvenue = null;
  431.     var oMessage = new whMessage(WH_MSG_GETCURRENTAVENUE, this, 1, oParam);
  432.     SendMessage(oMessage);
  433.     return oParam.sAvenue;
  434. }
  435.  
  436. function unRegisterListener()
  437. {
  438.     sendInvalidSyncInfo();
  439.     enableWebSearch(false);
  440.     if (whtopic_foldUnload)
  441.         whtopic_foldUnload();
  442. }
  443.  
  444. function onSendMessage(oMsg)
  445. {
  446.     var nMsgId = oMsg.nMessageId;
  447.     if (nMsgId == WH_MSG_GETAVIAVENUES)
  448.     {
  449.         oMsg.oParam.aAvenues = gaAvenues;
  450.         return false;
  451.     }
  452.     else if (nMsgId == WH_MSG_GETTOCPATHS)
  453.     {
  454.         if (isOutMostTopic())
  455.         {
  456.             oMsg.oParam.oTocInfo = createSyncInfo();
  457.             return false;        
  458.         }
  459.         else
  460.             return true;
  461.     }
  462.     else if (nMsgId == WH_MSG_NEXT)
  463.     {
  464.         goAvenue(true);
  465.     }
  466.     else if (nMsgId == WH_MSG_PREV)
  467.     {
  468.         goAvenue(false);
  469.     }
  470.     else if (nMsgId == WH_MSG_WEBSEARCH)
  471.     {
  472.         websearch();
  473.     }
  474.     return true;
  475. }
  476.  
  477. function goAvenue(bNext)
  478. {
  479.     var sTopic = null;
  480.     var sAvenue = getCurrentAvenue();
  481.     var nAvenue = -1;
  482.     if (sAvenue != null && sAvenue != "")
  483.     {
  484.         for (var i = 0; i < gaAvenues.length ; i ++)
  485.         {
  486.             if (gaAvenues[i].sName == sAvenue)
  487.             {
  488.                 nAvenue = i;
  489.                 break;
  490.             }
  491.         }
  492.         if (nAvenue != -1)
  493.         {
  494.             if (bNext)
  495.                 sTopic = gaAvenues[nAvenue].sNext;
  496.             else
  497.                 sTopic = gaAvenues[nAvenue].sPrev;
  498.         }
  499.     }
  500.     else
  501.     { 
  502.         for (var i = 0; i < gaAvenues.length ; i ++)
  503.         {
  504.             if (gaAvenues[i].sNext != null && gaAvenues[i].sNext.length > 0 && bNext)
  505.             {
  506.                 sTopic = gaAvenues[i].sNext;
  507.                 break;
  508.             }
  509.             else if (gaAvenues[i].sPrev != null && gaAvenues[i].sPrev.length > 0 && !bNext)
  510.             {
  511.                 sTopic = gaAvenues[i].sPrev;
  512.                 break;
  513.             }
  514.         }
  515.     }
  516.     
  517.     if (sTopic != null && sTopic != "")
  518.     {
  519.         if (gsPPath != null && gsPPath != "")
  520.         {
  521.             sFullTopicPath = _getFullPath(gsPPath, sTopic);
  522.             document.location = sFullTopicPath;
  523.         }
  524.     }
  525. }
  526.  
  527. function canGo(bNext)
  528. {
  529.     for (var i = 0; i < gaAvenues.length ; i ++)
  530.     {
  531.         if ((gaAvenues[i].sNext != null && gaAvenues[i].sNext.length > 0 && bNext) ||
  532.             (gaAvenues[i].sPrev != null && gaAvenues[i].sPrev.length > 0 && !bNext))
  533.             return true;
  534.     }
  535.     return false;
  536. }
  537.  
  538. function show()
  539. {
  540.     if (gsStartPage != "")
  541.         window.location =  gsStartPage + "#" + gsRelCurPagePath;
  542. }
  543.  
  544. function hide()
  545. {
  546.     if (goFrame != null)
  547.     {
  548.         goFrame.location = window.location;
  549.     }
  550. }
  551.  
  552. function isTopicOnly()
  553. {
  554.     if (gnTopicOnly == -1)
  555.     {
  556.         var oParam = new Object();
  557.         oParam.oFrame = null;
  558.         var oMsg = new whMessage(WH_MSG_GETSTARTFRAME, this, 1, oParam);
  559.         if (SendMessage(oMsg))
  560.         {
  561.             goFrame = oParam.oFrame;
  562.             gnTopicOnly = 0;
  563.         }
  564.         else
  565.             gnTopicOnly = 1;
  566.     }
  567.     if (gnTopicOnly == 1)
  568.         return true;
  569.     else
  570.         return false;
  571. }
  572.  
  573. function websearch()
  574. {
  575.     if (gbNav4)
  576.     {
  577.         if (document.ehelpform)
  578.             document.ehelpform.submit();
  579.     }
  580.     else
  581.     {
  582.         if (window.ehelpform)
  583.             window.ehelpform.submit();
  584.     }
  585. }
  586.  
  587. function addSearchFormHref(sHref)
  588. {
  589.     gsSearchFormHref = sHref;
  590.     enableWebSearch(true);
  591. }
  592.  
  593. function searchB(nForm)
  594. {
  595.     var sValue = eval("document.searchForm" + nForm + ".searchString.value");
  596.     var oMsg = new whMessage(WH_MSG_SEARCHTHIS, this, 1, sValue);
  597.     SendMessage(oMsg);
  598. }
  599.  
  600. function getSearchFormHTML()
  601. {
  602.     var sHTML = "";
  603.     gnForm ++;
  604.     var sFormName = "searchForm" + gnForm;
  605.     var sButton = "<form name=\"" + sFormName + "\" method=\"POST\" action=\"javascript:searchB("+ gnForm + ")\">"
  606.     sButton += "<input type=\"text\" name=\"searchString\" value=\"- Full Text search -\" size=\"20\"/>";
  607.     if ("" == "text")
  608.     {
  609.         sButton+="<a class=\"searchbtn\" href=\"javascript:void(0);\" onclick=\"" + sFormName + ".submit(); return false;\"></a>";
  610.     }
  611.     else if ("" == "image")
  612.     {
  613.         sButton+="<a class=\"searchbtn\" href=\"javascript:void(0);\" onclick=\"" + sFormName + ".submit(); return false;\">"
  614.         sButton+="<img src=\"\" border=0></a>";
  615.     }
  616.     sButton += "</form>";
  617.     sHTML ="<td align=\"center\">" + sButton + "</td>";
  618.     return sHTML;
  619. }
  620.  
  621. function showHidePane(bShow)
  622. {
  623.     var oMsg=null;
  624.     if (bShow)
  625.         oMsg=new whMessage(WH_MSG_SHOWPANE, this, 1, null);
  626.     else
  627.          oMsg=new whMessage(WH_MSG_HIDEPANE, this, 1, null);
  628.     SendMessage(oMsg);
  629. }
  630.  
  631. function isShowHideEnable()
  632. {
  633.     if (gbIE4)
  634.         return true;
  635.     else
  636.         return false;
  637. }
  638.  
  639. if(window.gbWhUtil&&window.gbWhMsg&&window.gbWhVer&&window.gbWhProxy)
  640. {
  641.     RegisterListener("bsscright", WH_MSG_GETAVIAVENUES);
  642.     RegisterListener("bsscright", WH_MSG_GETTOCPATHS);
  643.     RegisterListener("bsscright", WH_MSG_NEXT);
  644.     RegisterListener("bsscright", WH_MSG_PREV);
  645.     RegisterListener("bsscright", WH_MSG_WEBSEARCH);
  646.     if (gbMac && gbIE4)
  647.     {
  648.         if (typeof(window.onunload) != "unknown")
  649.             whtopic_foldUnload = window.onunload;
  650.     }
  651.     else
  652.     {
  653.         if (window.onunload)
  654.             whtopic_foldUnload = window.onunload;
  655.     }
  656.     window.onunload = unRegisterListener;
  657.     setButtonFont("show","","10pt","","","","");
  658.  
  659.     gbWhTopic=true;
  660. }
  661. else
  662.     document.location.reload();