home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2002 August / INTERNET94.ISO / pc / software / windows / mail / ft_gate_office / officewebhelp / bsscnbar.js < prev    next >
Encoding:
JavaScript  |  2000-09-27  |  15.3 KB  |  508 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. // RoboHELP« Navigator Bar for WebHelp
  3. // Copyright ⌐ 1999-2000 eHelp Corporation.  All rights reserved.
  4.  
  5. // Version= 4.30
  6.  
  7. // Warning:  Do not modify this file.  It is generated by RoboHELP« and changes will be overwritten.
  8.  
  9. // This file is used to support Navigator bar in WebHelp
  10. // The main functions are Sync toc. Show or Hide Navigator Panel. 
  11.  
  12. // call onBsscNavHide() from bsscright frame.
  13. // Hide the bsscleft frame(Nav). and show the current topic.
  14.  
  15. // call onBsscNavShow() from any frame except bsscright.
  16. // Show the bsscleft frame(Nav). and show the current topic in the bsscright frame. and sync toc.
  17.  
  18. // call onBsscNavSync() from bsscright frame.
  19. // there will be two situation.
  20. // 1. Nav is visible.  Just Sync the toc.( show the Contents panel and highlight the related topic).
  21. // 2. Nav is invisible. First Show the Nav panel. and then Sync the toc.
  22.  
  23.  
  24. // onBsscNavSync(strRelHomePage) strRelHomePage is the Relative Path of the First Page, from the current page's view.
  25. // other function will be called by onContent(). do not call them directly.
  26.  
  27. // onBsscNavSync is modified from onContents() in SyncFromTopic.js. add support DHTML sync. 
  28.  
  29. // BsscNavHasNavFrame() determine the Nav frame exists or not
  30.  
  31.  
  32. var gbDHTML = false;
  33.  
  34. var strAgent   = navigator.userAgent.toLowerCase();
  35. var strVersion = navigator.appVersion.toLowerCase();
  36.  
  37. var gnVerMajor = parseInt(strVersion);
  38. var gnVerMinor = parseFloat(strVersion);
  39.  
  40. var gbNS     = ((strAgent.indexOf("mozilla") != -1) && ((strAgent.indexOf('spoofer') == -1) && (strAgent.indexOf('compatible') == -1)));
  41. var gbIE     = (strAgent.indexOf("msie") != -1);
  42. var gbOpera  = (strAgent.indexOf("opera") != -1);
  43. var gbHotJava= (strVersion.indexOf("hotjava") != -1);
  44.  
  45. var gbWin16   = ((strVersion.indexOf("win16") != -1) || (strVersion.indexOf("windows 3.1") != -1));
  46. var gbWindows = ((strAgent.indexOf("win") != -1) || (strAgent.indexOf("16bit") != -1));
  47. var gbMac     = (strAgent.indexOf("mac") != -1);
  48. var gbWebTV   = (strAgent.indexOf("webtv") != -1);
  49. var gbSunOS   = (strAgent.indexOf("sunos") != -1);
  50.  
  51. var gbNS2         = ((gbNS) && (gnVerMajor == 2));
  52. var gbNS3         = ((gbNS) && (gnVerMajor == 3));
  53. var gbNS4         = ((gbNS) && (gnVerMajor >= 4));
  54. var gbIE4         = ((gbIE) && (gnVerMajor >= 4));
  55. var gbIE400          = (strAgent.indexOf("msie 4.0;") != -1);
  56. var gbIE3         = ((gbIE) && (gnVerMajor <= 3));
  57. var gbIE302before = ((gbIE3) && ((strAgent.indexOf("3.00") != -1)||(strAgent.indexOf("3.0a") != -1)||(strAgent.indexOf("3.0b")!=-1)||(strAgent.indexOf("3.01")!=-1))); 
  58.  
  59. var gbIE5      = ((gbIE4) && (strAgent.indexOf("msie 5") != -1));
  60.  
  61. var nViewFrameType = 2;  //1: DTHTML 2:Applet 3: HTML2 list
  62.  
  63. if (gbIE4 && gbDHTML) nViewFrameType = 1;
  64. if (gbIE4 && gbSunOS) nViewFrameType = 1;
  65.  
  66. if (gbWin16)          nViewFrameType = 3;
  67. if (gbIE3 && gbMac)   nViewFrameType = 3;
  68. if (gbNS2)            nViewFrameType = 3;
  69. if (gbNS3 && gbMac)   nViewFrameType = 3;
  70. if (gbOpera)          nViewFrameType = 3;
  71. if (gbHotJava)        nViewFrameType = 3;
  72. if (gbWebTV)          nViewFrameType = 3;
  73. if (gbIE302before)    nViewFrameType = 3;
  74.  
  75. if ((gbNS4) && (window.screen) && (window.screen.colorDepth == 4))
  76. {
  77.    nViewFrameType = 3;
  78. }
  79.  
  80. function BsscNavIsList() {
  81.     return (nViewFrameType == 3 || (gbIE4 && !gbIE5 && gbMac));
  82. }
  83.  
  84. var gbstrNavnAgent   = navigator.userAgent.toLowerCase();
  85.  
  86. var gbNavnNS    = false;
  87. var gbNavnIE    = false;
  88. gbNavnNS     = ((gbstrNavnAgent.indexOf("mozilla") != -1) && ((gbstrNavnAgent.indexOf('spoofer') == -1) && (gbstrNavnAgent.indexOf('compatible') == -1)));
  89. gbNavnIE        = (gbstrNavnAgent.indexOf("msie") != -1);
  90.  
  91. var gbstrAbsHomePageURL = "";
  92. var gbstrRelHomePageURL = "";
  93. var gbCurrentTopicURL   = "";
  94. var gHomePage = null;
  95.  
  96. function _bsscnBarEqualURL(strAbsHomePageURL, strCurrentURL)
  97. {
  98.     var strNormalstrAbsHomePageURL = strAbsHomePageURL.toLowerCase();
  99.     var strNormalstrCurrentURL = strCurrentURL.toLowerCase();
  100.  
  101.     strNormalstrAbsHomePageURL = _bsscnBarConvertToURLFormat(strNormalstrAbsHomePageURL);
  102.     strNormalstrCurrentURL = _bsscnBarConvertToURLFormat(strNormalstrCurrentURL);
  103.  
  104.     if (strNormalstrAbsHomePageURL == strNormalstrCurrentURL)
  105.         return true;
  106.     else 
  107.         return false;
  108. }
  109.  
  110. // change αßπ to %E0%E1%E3
  111. function _bsscnBarConvertToURLFormat(strURL)
  112. {
  113.     var strResURL = "";
  114.     var i = 0;
  115.     if (!gbNS4 && !gbIE4) return strURL;
  116.     for (i = 0; i < strURL.length; i ++)
  117.     {
  118.         var nCode = strURL.charCodeAt(i);
  119.         if (nCode > 127) {
  120.             strResURL += "%";
  121.             var strTemp = String.fromCharCode(HEXToCharCode(nCode/16), HEXToCharCode(nCode%16));
  122.             strResURL += strTemp
  123.         }
  124.         else 
  125.             strResURL += strURL.charAt(i);
  126.     }
  127.     if (strResURL.indexOf("file:/") == 0 && strResURL.indexOf("file:///") == -1) {
  128.         strResURL = strResURL.replace("file:/", "file:///");
  129.     }
  130.     return strResURL;
  131. }
  132.  
  133. function HEXToCharCode(n)
  134. {
  135.     if (n < 10) {
  136.         return '0'.charCodeAt(0) + n;
  137.     }
  138.     else if (n < 16) {
  139.         return 'A'.charCodeAt(0) + (n - 10);
  140.     }
  141.     else
  142.         return 0;
  143. }
  144.  
  145. function _bsscnBarGetStartPage(pwindow) {
  146.     var strAbsHomePageURL = _bsscnBarGetAbsHomePageURL();
  147.     var strCurrentURL = pwindow.document.URL;
  148.     strCurrentURL = _bsscnBarReplaceSlash(strCurrentURL);
  149.     var nEndPos  = strCurrentURL.indexOf('#');
  150.     if (nEndPos != -1) {
  151.         strCurrentURL = strCurrentURL.substring(0, nEndPos);
  152.     }
  153.     if (_bsscnBarEqualURL(strAbsHomePageURL, strCurrentURL)) {
  154.         return pwindow;
  155.     }
  156.     else {
  157.         if (pwindow.parent.frames.length != 0 && pwindow.parent != pwindow && pwindow.parent != null) 
  158.         {
  159.             gbCurrentTopicURL = strCurrentURL;
  160.             return _bsscnBarGetStartPage(pwindow.parent);
  161.         }
  162.         else 
  163.             if (typeof(pwindow.gbHomePage) != "undefined") 
  164.                 return pwindow;
  165.             else
  166.                 return null;
  167.  
  168.     }
  169. }
  170.  
  171. function _bsscnBarGetOutMostTopic(pwindow) {
  172.     var strAbsHomePageURL = _bsscnBarGetAbsHomePageURL();
  173.     var strCurrentURL = pwindow.document.URL;
  174.     strCurrentURL = _bsscnBarReplaceSlash(strCurrentURL);
  175.  
  176.     var strOutStartPage = pwindow.gbstrRelHomePageURL;
  177.     if (typeof(strOutStartPage) == "undefined") return null;
  178.  
  179.     var strOutAbsHomePageURL = _bsscnBarGetOutAbsHomePageURL(strCurrentURL, strOutStartPage);
  180.  
  181.     if (_bsscnBarEqualURL(strAbsHomePageURL, strOutAbsHomePageURL)) {
  182.         if (pwindow.parent.frames.length != 0 && pwindow.parent != pwindow && pwindow.parent != null) {
  183.             var pfind = _bsscnBarGetOutMostTopic(pwindow.parent);
  184.             if (pfind == null) {
  185.                 gbCurrentTopicURL = strCurrentURL;
  186.                 return pwindow;
  187.             }
  188.             else
  189.                 return pfind;
  190.         }
  191.         else  {
  192.             gbCurrentTopicURL = strCurrentURL;
  193.             return pwindow;
  194.         }
  195.     }
  196.     else
  197.         return null;
  198. }
  199.  
  200. function _bsscnBarGetOutAbsHomePageURL(strCurrentURL, strOutStartPage)
  201. {
  202.     var strRelHomePage = _bsscnBarReplaceSlash(strOutStartPage);
  203.     
  204.     strCurrentURL = _bsscnBarReplaceSlash(strCurrentURL);
  205.     
  206.     var strCurrentPath = _bsscnBarGetPath(strCurrentURL);
  207.     var strCurrentFile = _bsscnBarGetFileName(strCurrentURL);
  208.     
  209.     var strAbsHomePageURL = _bsscnBarGetAbsoluteHomePageURL(strRelHomePage, strCurrentPath);
  210.     
  211.     return strAbsHomePageURL;
  212. }
  213.  
  214. function BsscNavHasNavFrame()
  215. {
  216.     var bHomePage = false;
  217.     if (gHomePage == null)
  218.         gHomePage =     _bsscnBarGetStartPage(parent);    
  219.  
  220.     if (gHomePage != null)
  221.         bHomePage = true;
  222.     return bHomePage;
  223. }
  224.  
  225. // call onBsscNavHide() from bsscright frame.
  226. // Hide the bsscleft frame(Nav). and show the current topic.
  227. function onBsscNavHide()
  228. {
  229.     
  230.     if (BsscNavHasNavFrame()) {
  231.         var strCurrentURL = document.URL;
  232.         var OutTopic = _bsscnBarGetOutMostTopic(window);
  233.         if (OutTopic != null) {
  234.             if (gbCurrentTopicURL.length > 0) 
  235.                 strCurrentURL = gbCurrentTopicURL;
  236.         }
  237.         
  238.         if (strCurrentURL.toLowerCase().indexOf("file://") == 0) {
  239.             strCurrentURL = _bsscnBarReplaceSpecialChar(strCurrentURL);
  240.         }
  241.         gHomePage.document.location.replace(strCurrentURL);
  242.     }
  243. }
  244.  
  245. // call onBsscNavShow() from any frame except bsscright.
  246. // Show the bsscleft frame(Nav). and show the current topic in the bsscright frame. and sync toc.
  247. function onBsscNavShow()
  248. {
  249.     if (!BsscNavHasNavFrame()) {
  250.  
  251.         var strAbsHomePageURL = _bsscnBarGetAbsHomePageURL();
  252.         var strAbsHomePagePath = _bsscnBarGetPath(strAbsHomePageURL);
  253.  
  254.         strAbsHomePagePath = strAbsHomePagePath + "/";
  255.     
  256.         var strCurrentURL = document.URL;
  257.         strCurrentURL = _bsscnBarReplaceSlash(strCurrentURL);
  258.  
  259.         var OutTopic = _bsscnBarGetOutMostTopic(window);
  260.         if (OutTopic != null)
  261.             if (gbCurrentTopicURL.length > 0) 
  262.                 strCurrentURL = gbCurrentTopicURL;
  263.  
  264.         var startpos  = strCurrentURL.indexOf(strAbsHomePagePath);
  265.         if (startpos != -1) {
  266.             strRelativeURL = strCurrentURL.substring(startpos + strAbsHomePagePath.length, strCurrentURL.length);
  267.             if (strAbsHomePageURL.toLowerCase().indexOf("file://") == 0) 
  268.                 strAbsHomePageURL = _bsscnBarReplaceSpecialChar(strAbsHomePageURL);
  269.             if (OutTopic != null) {
  270.                 if (gbIE400) // ie 4.00 can not recognize the bookmark locally.
  271.                     OutTopic.location.replace(strAbsHomePageURL);
  272.                 else
  273.                     OutTopic.location.replace(strAbsHomePageURL+"#" + strRelativeURL);
  274.             }
  275.         }
  276.     }
  277. }
  278.  
  279. function _bsscnBarGetAbsHomePageURL()
  280. {
  281.     if ( gbstrAbsHomePageURL.length > 0) return gbstrAbsHomePageURL;
  282.  
  283.     var strRelHomePage = _bsscnBarReplaceSlash(gbstrRelHomePageURL);
  284.     
  285.     var strCurrentURL = document.URL;
  286.     strCurrentURL = _bsscnBarReplaceSlash(strCurrentURL);
  287.     
  288.     var strCurrentPath = _bsscnBarGetPath(strCurrentURL);
  289.     var strCurrentFile = _bsscnBarGetFileName(strCurrentURL);
  290.     
  291.     gbstrAbsHomePageURL = _bsscnBarGetAbsoluteHomePageURL(strRelHomePage, strCurrentPath);
  292.     
  293.     return gbstrAbsHomePageURL;
  294. }
  295.  
  296. function onBsscAutoSync()
  297. {
  298.     var strAbsHomePageURL = _bsscnBarGetAbsHomePageURL();
  299.     var strAbsHomePagePath = _bsscnBarGetPath(strAbsHomePageURL);
  300.  
  301.     strAbsHomePagePath = strAbsHomePagePath + "/";
  302.     
  303.     var strCurrentURL = document.URL;
  304.     strCurrentURL = _bsscnBarReplaceSlash(strCurrentURL);
  305.     
  306.     var startpos  = strCurrentURL.indexOf(strAbsHomePagePath);
  307.     
  308.     if (startpos != -1) {
  309.         strRelativeURL = strCurrentURL.substring(startpos + strAbsHomePagePath.length, strCurrentURL.length);
  310.         if (BsscNavHasNavFrame()) {
  311.             if(gbNavnIE) {// IE
  312.                 if (gHomePage.document.frames[0].document.applets.length > 0) {
  313.                     if (typeof(gHomePage.document.frames[0].document.applets["webhelp"]) != "undefined") {
  314.                         if (!gbIE4 || !gbWindows || gHomePage.document.frames[0].gbLoading != "unknown") 
  315.                             gHomePage.document.frames[0].document.applets["webhelp"].Command("AutoSync", strRelativeURL);
  316.                     }
  317.                 }
  318.                 else {
  319.                     // probably DHTML
  320.                     if (typeof(gHomePage.document.frames[0].document.frames["Tabs"]) != "undefined") {
  321.                         var tabFrame = gHomePage.document.frames[0].document.frames["Tabs"];
  322.                         _bsscnBarAutoSync(strRelativeURL);
  323.                     } 
  324.                     else { // it must be list
  325.                     }
  326.                 }
  327.             }
  328.             else { // Probably Netscape.
  329.                 if (gHomePage.frames[0].document.applets.length > 0) {
  330.                     if (typeof(gHomePage.frames[0].document.applets["webhelp"]) != "undefined") {
  331.                         gHomePage.frames[0].document.applets["webhelp"].Command("AutoSync", strRelativeURL);
  332.                     }
  333.                 }
  334.                 else {
  335.                     // probably DHTML
  336.                     if (typeof(gHomePage.document.frames[0].document.frames["Tabs"]) != "undefined") {
  337.                         _bsscnBarAutoSync(strRelativeURL);
  338.                     }
  339.                     else { // it must be list
  340.                     }
  341.                 }
  342.             }
  343.         }
  344.     }
  345. }
  346.  
  347. function onBsscNavSync()
  348. {
  349.     var strAbsHomePageURL = _bsscnBarGetAbsHomePageURL();
  350.     var strAbsHomePagePath = _bsscnBarGetPath(strAbsHomePageURL);
  351.  
  352.     strAbsHomePagePath = strAbsHomePagePath + "/";
  353.     
  354.     var strCurrentURL = document.URL;
  355.     strCurrentURL = _bsscnBarReplaceSlash(strCurrentURL);
  356.     
  357.     var startpos  = strCurrentURL.indexOf(strAbsHomePagePath);
  358.     
  359.     if (startpos != -1) {
  360.         strRelativeURL = strCurrentURL.substring(startpos + strAbsHomePagePath.length, strCurrentURL.length);
  361.         if (BsscNavHasNavFrame()) {
  362.             if(gbNavnIE) {// IE
  363.                 if (gHomePage.document.frames[0].document.applets.length > 0) {
  364.                     if (typeof(gHomePage.document.frames[0].document.applets["webhelp"]) != "undefined") {
  365.                         gHomePage.document.frames[0].document.applets["webhelp"].Command("SyncToc", strRelativeURL);
  366.                     }
  367.                 }
  368.                 else {
  369.                     // probably DHTML
  370.                     if (typeof(gHomePage.document.frames[0].document.frames["Tabs"]) != "undefined") {
  371.                         var tabFrame = gHomePage.document.frames[0].document.frames["Tabs"];
  372.                         _bsscnBarSelectTOC(strRelativeURL);
  373.                     } 
  374.                     else { // it must be list
  375.                     }
  376.                 }
  377.             }
  378.             else { // Probably Netscape.
  379.                 if (gHomePage.frames[0].document.applets.length > 0) {
  380.                     if (typeof(gHomePage.frames[0].document.applets["webhelp"]) != "undefined") {
  381.                         gHomePage.frames[0].document.applets["webhelp"].Command("SyncToc", strRelativeURL);
  382.                     }
  383.                 }
  384.                 else {
  385.                     // probably DHTML
  386.                     if (typeof(gHomePage.document.frames[0].document.frames["Tabs"]) != "undefined") {
  387.                         _bsscnBarSelectTOC(strRelativeURL);
  388.                     }
  389.                     else { // it must be list
  390.                     }
  391.                 }
  392.             }
  393.         }
  394.         else
  395.             //location.replace(strAbsHomePageURL+"#" + strRelativeURL);
  396.             onBsscNavShow();
  397.     }
  398. }
  399.  
  400.  
  401. // replace %20 to ' '
  402. function _bsscnBarReplaceSpecialChar(strURL)
  403. {    
  404.     var strReplacedURL = "";
  405.     for (i = 0; i < strURL.length; i ++ )
  406.     {
  407.         if (strURL.charAt(i) == '%') {
  408.             if (strURL.substring(i + 1, i + 3) == "20") {
  409.                 strReplacedURL = strReplacedURL + " ";
  410.                 i += 2;
  411.             }
  412.             else
  413.                 strReplacedURL = strReplacedURL + strURL.charAt(i);
  414.         }
  415.         else
  416.             strReplacedURL = strReplacedURL + strURL.charAt(i);
  417.     }
  418.     return strReplacedURL;
  419. }
  420.  
  421.  
  422. // replace \\ to /
  423. function _bsscnBarReplaceSlash(strURL)
  424. {    
  425.     var strReplacedURL = "";
  426.     for (i = 0; i < strURL.length; i ++ )
  427.     {
  428.         if (strURL.charAt(i) == '\\') 
  429.             strReplacedURL = strReplacedURL + "/"
  430.         else
  431.             strReplacedURL = strReplacedURL + strURL.charAt(i);
  432.     }
  433.     return strReplacedURL;
  434. }
  435.  
  436. // generate absolute URL for the first page.
  437. function _bsscnBarGetAbsoluteHomePageURL(strRelHomePage, strCurrentPath)
  438. {
  439.     if (strCurrentPath.charAt(strCurrentPath.length - 1) == '/') 
  440.         strCurrentPath = strCurrentPath.substring(0, strCurrentPath.length -1);
  441.     for (;;) {
  442.         upDirPos = strRelHomePage.indexOf("../")
  443.         if (upDirPos == 0) {
  444.             DirPos = strCurrentPath.lastIndexOf("/")
  445.             if (DirPos != -1) {
  446.             strCurrentPath = strCurrentPath.substring(0, DirPos)
  447.             }
  448.             strRelHomePage = strRelHomePage.substring(3, strRelHomePage.length);
  449.         }
  450.         if (upDirPos != 0) break;
  451.     }
  452.     return strCurrentPath + "/" + strRelHomePage;
  453. }
  454.  
  455. function _bsscnBarGetPath(strURL)
  456. {
  457.     pathpos = strURL.lastIndexOf("/");
  458.     if (pathpos > 0)
  459.         return strURL.substring(0, pathpos);
  460.     else 
  461.         return "";
  462. }
  463.  
  464. function _bsscnBarGetFileName(strURL)
  465. {
  466.     pathpos = strURL.lastIndexOf("/");
  467.     if (pathpos > 0)
  468.         return strURL.substring(pathpos + 1, strURL.length);
  469.     else
  470.         return strURL;
  471. }
  472.  
  473. function _bsscnBarGetTabFrame()
  474. {
  475.     if (gHomePage == null) return null;
  476.     if(gbNavnIE) {// IE
  477.         return gHomePage.document.frames[0];
  478.     }
  479.     else { // Netscape
  480.         return gHomePage.frames[0];
  481.     }
  482. }
  483.  
  484. function _bsscnBarAutoSync(strRelativeURL)
  485. {
  486.     var TabFrame = _bsscnBarGetTabFrame();
  487.     if ("function" == typeof(TabFrame.autosync))
  488.         TabFrame.autosync(strRelativeURL);
  489. }
  490.  
  491.  
  492.  
  493. function _bsscnBarSelectTOC(strRelativeURL)
  494. {
  495.     var TabFrame = _bsscnBarGetTabFrame();
  496.     if ("function" == typeof(TabFrame.syncToc))
  497.         TabFrame.syncToc(strRelativeURL);
  498. }
  499.  
  500.  
  501. function _bsscnBarOnError(message)
  502. {
  503.     if(-1 != message.indexOf("denied") 
  504.         || -1 != message.indexOf("Object required"))
  505.      return true;
  506. }
  507.  
  508. onerror = _bsscnBarOnError;