home *** CD-ROM | disk | FTP | other *** search
/ Internet CD 2005 August / MICD_2005_08.iso / Multimedia / Twist / TwistEval.exe / Main / bsscnbar.js < prev    next >
Encoding:
JavaScript  |  2005-06-28  |  15.3 KB  |  509 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. // RoboHELP« Navigator Bar for WebHelp
  3. // Copyright ⌐ 1999-2001 eHelp Corporation.  All rights reserved.
  4.  
  5. // Version= 4.41
  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 gbNS6         = ((gbNS) && (gnVerMajor >= 5));
  55. var gbIE4         = ((gbIE) && (gnVerMajor >= 4));
  56. var gbIE400          = (strAgent.indexOf("msie 4.0;") != -1);
  57. var gbIE3         = ((gbIE) && (gnVerMajor <= 3));
  58. var gbIE302before = ((gbIE3) && ((strAgent.indexOf("3.00") != -1)||(strAgent.indexOf("3.0a") != -1)||(strAgent.indexOf("3.0b")!=-1)||(strAgent.indexOf("3.01")!=-1))); 
  59.  
  60. var gbIE5      = ((gbIE4) && (strAgent.indexOf("msie 5") != -1));
  61.  
  62. var nViewFrameType = 2;  //1: DTHTML 2:Applet 3: HTML2 list
  63.  
  64. if (gbIE4 && gbDHTML) nViewFrameType = 1;
  65. if (gbIE4 && gbSunOS) nViewFrameType = 1;
  66.  
  67. if (gbWin16)          nViewFrameType = 3;
  68. if (gbIE3 && gbMac)   nViewFrameType = 3;
  69. if (gbNS2)            nViewFrameType = 3;
  70. if (gbNS3 && gbMac)   nViewFrameType = 3;
  71. if (gbOpera)          nViewFrameType = 3;
  72. if (gbHotJava)        nViewFrameType = 3;
  73. if (gbWebTV)          nViewFrameType = 3;
  74. if (gbIE302before)    nViewFrameType = 3;
  75.  
  76. if ((gbNS4) && (window.screen) && (window.screen.colorDepth == 4))
  77. {
  78.    nViewFrameType = 3;
  79. }
  80.  
  81. function BsscNavIsList() {
  82.     return (nViewFrameType == 3 || (gbIE4 && !gbIE5 && gbMac));
  83. }
  84.  
  85. var gbstrNavnAgent   = navigator.userAgent.toLowerCase();
  86.  
  87. var gbNavnNS    = false;
  88. var gbNavnIE    = false;
  89. gbNavnNS     = ((gbstrNavnAgent.indexOf("mozilla") != -1) && ((gbstrNavnAgent.indexOf('spoofer') == -1) && (gbstrNavnAgent.indexOf('compatible') == -1)));
  90. gbNavnIE        = (gbstrNavnAgent.indexOf("msie") != -1);
  91.  
  92. var gbstrAbsHomePageURL = "";
  93. var gbstrRelHomePageURL = "";
  94. var gbCurrentTopicURL   = "";
  95. var gHomePage = null;
  96.  
  97. function _bsscnBarEqualURL(strAbsHomePageURL, strCurrentURL)
  98. {
  99.     var strNormalstrAbsHomePageURL = strAbsHomePageURL.toLowerCase();
  100.     var strNormalstrCurrentURL = strCurrentURL.toLowerCase();
  101.  
  102.     strNormalstrAbsHomePageURL = _bsscnBarConvertToURLFormat(strNormalstrAbsHomePageURL);
  103.     strNormalstrCurrentURL = _bsscnBarConvertToURLFormat(strNormalstrCurrentURL);
  104.  
  105.     if (strNormalstrAbsHomePageURL == strNormalstrCurrentURL)
  106.         return true;
  107.     else 
  108.         return false;
  109. }
  110.  
  111. // change αßπ to %E0%E1%E3
  112. function _bsscnBarConvertToURLFormat(strURL)
  113. {
  114.     var strResURL = "";
  115.     var i = 0;
  116.     if (!gbNS4 && !gbIE4) return strURL;
  117.     for (i = 0; i < strURL.length; i ++)
  118.     {
  119.         var nCode = strURL.charCodeAt(i);
  120.         if (nCode > 127) {
  121.             strResURL += "%";
  122.             var strTemp = String.fromCharCode(HEXToCharCode(nCode/16), HEXToCharCode(nCode%16));
  123.             strResURL += strTemp
  124.         }
  125.         else 
  126.             strResURL += strURL.charAt(i);
  127.     }
  128.     if (strResURL.indexOf("file:/") == 0 && strResURL.indexOf("file:///") == -1) {
  129.         strResURL = strResURL.replace("file:/", "file:///");
  130.     }
  131.     return strResURL;
  132. }
  133.  
  134. function HEXToCharCode(n)
  135. {
  136.     if (n < 10) {
  137.         return '0'.charCodeAt(0) + n;
  138.     }
  139.     else if (n < 16) {
  140.         return 'A'.charCodeAt(0) + (n - 10);
  141.     }
  142.     else
  143.         return 0;
  144. }
  145.  
  146. function _bsscnBarGetStartPage(pwindow) {
  147.     var strAbsHomePageURL = _bsscnBarGetAbsHomePageURL();
  148.     var strCurrentURL = pwindow.document.URL;
  149.     strCurrentURL = _bsscnBarReplaceSlash(strCurrentURL);
  150.     var nEndPos  = strCurrentURL.indexOf('#');
  151.     if (nEndPos != -1) {
  152.         strCurrentURL = strCurrentURL.substring(0, nEndPos);
  153.     }
  154.     if (_bsscnBarEqualURL(strAbsHomePageURL, strCurrentURL)) {
  155.         return pwindow;
  156.     }
  157.     else {
  158.         if (pwindow.parent.frames.length != 0 && pwindow.parent != pwindow && pwindow.parent != null) 
  159.         {
  160.             gbCurrentTopicURL = strCurrentURL;
  161.             return _bsscnBarGetStartPage(pwindow.parent);
  162.         }
  163.         else 
  164.             if (typeof(pwindow.gbHomePage) != "undefined") 
  165.                 return pwindow;
  166.             else
  167.                 return null;
  168.  
  169.     }
  170. }
  171.  
  172. function _bsscnBarGetOutMostTopic(pwindow) {
  173.     var strAbsHomePageURL = _bsscnBarGetAbsHomePageURL();
  174.     var strCurrentURL = pwindow.document.URL;
  175.     strCurrentURL = _bsscnBarReplaceSlash(strCurrentURL);
  176.  
  177.     var strOutStartPage = pwindow.gbstrRelHomePageURL;
  178.     if (typeof(strOutStartPage) == "undefined") return null;
  179.  
  180.     var strOutAbsHomePageURL = _bsscnBarGetOutAbsHomePageURL(strCurrentURL, strOutStartPage);
  181.  
  182.     if (_bsscnBarEqualURL(strAbsHomePageURL, strOutAbsHomePageURL)) {
  183.         if (pwindow.parent.frames.length != 0 && pwindow.parent != pwindow && pwindow.parent != null) {
  184.             var pfind = _bsscnBarGetOutMostTopic(pwindow.parent);
  185.             if (pfind == null) {
  186.                 gbCurrentTopicURL = strCurrentURL;
  187.                 return pwindow;
  188.             }
  189.             else
  190.                 return pfind;
  191.         }
  192.         else  {
  193.             gbCurrentTopicURL = strCurrentURL;
  194.             return pwindow;
  195.         }
  196.     }
  197.     else
  198.         return null;
  199. }
  200.  
  201. function _bsscnBarGetOutAbsHomePageURL(strCurrentURL, strOutStartPage)
  202. {
  203.     var strRelHomePage = _bsscnBarReplaceSlash(strOutStartPage);
  204.     
  205.     strCurrentURL = _bsscnBarReplaceSlash(strCurrentURL);
  206.     
  207.     var strCurrentPath = _bsscnBarGetPath(strCurrentURL);
  208.     var strCurrentFile = _bsscnBarGetFileName(strCurrentURL);
  209.     
  210.     var strAbsHomePageURL = _bsscnBarGetAbsoluteHomePageURL(strRelHomePage, strCurrentPath);
  211.     
  212.     return strAbsHomePageURL;
  213. }
  214.  
  215. function BsscNavHasNavFrame()
  216. {
  217.     var bHomePage = false;
  218.     if (gHomePage == null)
  219.         gHomePage =     _bsscnBarGetStartPage(parent);    
  220.  
  221.     if (gHomePage != null)
  222.         bHomePage = true;
  223.     return bHomePage;
  224. }
  225.  
  226. // call onBsscNavHide() from bsscright frame.
  227. // Hide the bsscleft frame(Nav). and show the current topic.
  228. function onBsscNavHide()
  229. {
  230.     
  231.     if (BsscNavHasNavFrame()) {
  232.         var strCurrentURL = document.URL;
  233.         var OutTopic = _bsscnBarGetOutMostTopic(window);
  234.         if (OutTopic != null) {
  235.             if (gbCurrentTopicURL.length > 0) 
  236.                 strCurrentURL = gbCurrentTopicURL;
  237.         }
  238.         
  239.         if (strCurrentURL.toLowerCase().indexOf("file://") == 0) {
  240.             strCurrentURL = _bsscnBarReplaceSpecialChar(strCurrentURL);
  241.         }
  242.         gHomePage.document.location = strCurrentURL;
  243.     }
  244. }
  245.  
  246. // call onBsscNavShow() from any frame except bsscright.
  247. // Show the bsscleft frame(Nav). and show the current topic in the bsscright frame. and sync toc.
  248. function onBsscNavShow()
  249. {
  250.     if (!BsscNavHasNavFrame()) {
  251.  
  252.         var strAbsHomePageURL = _bsscnBarGetAbsHomePageURL();
  253.         var strAbsHomePagePath = _bsscnBarGetPath(strAbsHomePageURL);
  254.  
  255.         strAbsHomePagePath = strAbsHomePagePath + "/";
  256.     
  257.         var strCurrentURL = document.URL;
  258.         strCurrentURL = _bsscnBarReplaceSlash(strCurrentURL);
  259.  
  260.         var OutTopic = _bsscnBarGetOutMostTopic(window);
  261.         if (OutTopic != null)
  262.             if (gbCurrentTopicURL.length > 0) 
  263.                 strCurrentURL = gbCurrentTopicURL;
  264.  
  265.         var startpos  = strCurrentURL.indexOf(strAbsHomePagePath);
  266.         if (startpos != -1) {
  267.             strRelativeURL = strCurrentURL.substring(startpos + strAbsHomePagePath.length, strCurrentURL.length);
  268.             if (strAbsHomePageURL.toLowerCase().indexOf("file://") == 0) 
  269.                 strAbsHomePageURL = _bsscnBarReplaceSpecialChar(strAbsHomePageURL);
  270.             if (OutTopic != null) {
  271.                 if (gbIE400) // ie 4.00 can not recognize the bookmark locally.
  272.                     OutTopic.location.replace(strAbsHomePageURL);
  273.                 else
  274.                     OutTopic.location = strAbsHomePageURL+"#" + strRelativeURL;
  275.             }
  276.         }
  277.     }
  278. }
  279.  
  280. function _bsscnBarGetAbsHomePageURL()
  281. {
  282.     if ( gbstrAbsHomePageURL.length > 0) return gbstrAbsHomePageURL;
  283.  
  284.     var strRelHomePage = _bsscnBarReplaceSlash(gbstrRelHomePageURL);
  285.     
  286.     var strCurrentURL = document.URL;
  287.     strCurrentURL = _bsscnBarReplaceSlash(strCurrentURL);
  288.     
  289.     var strCurrentPath = _bsscnBarGetPath(strCurrentURL);
  290.     var strCurrentFile = _bsscnBarGetFileName(strCurrentURL);
  291.     
  292.     gbstrAbsHomePageURL = _bsscnBarGetAbsoluteHomePageURL(strRelHomePage, strCurrentPath);
  293.     
  294.     return gbstrAbsHomePageURL;
  295. }
  296.  
  297. function onBsscAutoSync()
  298. {
  299.     var strAbsHomePageURL = _bsscnBarGetAbsHomePageURL();
  300.     var strAbsHomePagePath = _bsscnBarGetPath(strAbsHomePageURL);
  301.  
  302.     strAbsHomePagePath = strAbsHomePagePath + "/";
  303.     
  304.     var strCurrentURL = document.URL;
  305.     strCurrentURL = _bsscnBarReplaceSlash(strCurrentURL);
  306.     
  307.     var startpos  = strCurrentURL.indexOf(strAbsHomePagePath);
  308.     
  309.     if (startpos != -1) {
  310.         strRelativeURL = strCurrentURL.substring(startpos + strAbsHomePagePath.length, strCurrentURL.length);
  311.         if (BsscNavHasNavFrame()) {
  312.             if(gbNavnIE) {// IE
  313.                 if (gHomePage.document.frames[0].document.applets.length > 0) {
  314.                     if (typeof(gHomePage.document.frames[0].document.applets["webhelp"]) != "undefined") {
  315.                         if (!gbIE4 || !gbWindows || gHomePage.document.frames[0].gbLoading != "unknown") 
  316.                             gHomePage.document.frames[0].document.applets["webhelp"].Command("AutoSync", strRelativeURL);
  317.                     }
  318.                 }
  319.                 else {
  320.                     // probably DHTML
  321.                     if (typeof(gHomePage.document.frames[0].document.frames["Tabs"]) != "undefined") {
  322.                         var tabFrame = gHomePage.document.frames[0].document.frames["Tabs"];
  323.                         _bsscnBarAutoSync(strRelativeURL);
  324.                     } 
  325.                     else { // it must be list
  326.                     }
  327.                 }
  328.             }
  329.             else { // Probably Netscape.
  330.                 if (gHomePage.frames[0].document.applets.length > 0) {
  331.                     if (typeof(gHomePage.frames[0].document.applets["webhelp"]) != "undefined") {
  332.                         gHomePage.frames[0].document.applets["webhelp"].Command("AutoSync", strRelativeURL);
  333.                     }
  334.                 }
  335.                 else {
  336.                     // probably DHTML
  337.                     if (typeof(gHomePage.frames[0].frames["Tabs"]) != "undefined") {
  338.                         _bsscnBarAutoSync(strRelativeURL);
  339.                     }
  340.                     else { // it must be list
  341.                     }
  342.                 }
  343.             }
  344.         }
  345.     }
  346. }
  347.  
  348. function onBsscNavSync()
  349. {
  350.     var strAbsHomePageURL = _bsscnBarGetAbsHomePageURL();
  351.     var strAbsHomePagePath = _bsscnBarGetPath(strAbsHomePageURL);
  352.  
  353.     strAbsHomePagePath = strAbsHomePagePath + "/";
  354.     
  355.     var strCurrentURL = document.URL;
  356.     strCurrentURL = _bsscnBarReplaceSlash(strCurrentURL);
  357.     
  358.     var startpos  = strCurrentURL.indexOf(strAbsHomePagePath);
  359.     
  360.     if (startpos != -1) {
  361.         strRelativeURL = strCurrentURL.substring(startpos + strAbsHomePagePath.length, strCurrentURL.length);
  362.         if (BsscNavHasNavFrame()) {
  363.             if(gbNavnIE) {// IE
  364.                 if (gHomePage.document.frames[0].document.applets.length > 0) {
  365.                     if (typeof(gHomePage.document.frames[0].document.applets["webhelp"]) != "undefined") {
  366.                         gHomePage.document.frames[0].document.applets["webhelp"].Command("SyncToc", strRelativeURL);
  367.                     }
  368.                 }
  369.                 else {
  370.                     // probably DHTML
  371.                     if (typeof(gHomePage.document.frames[0].document.frames["Tabs"]) != "undefined") {
  372.                         var tabFrame = gHomePage.document.frames[0].document.frames["Tabs"];
  373.                         _bsscnBarSelectTOC(strRelativeURL);
  374.                     } 
  375.                     else { // it must be list
  376.                     }
  377.                 }
  378.             }
  379.             else { // Probably Netscape.
  380.                 if (gHomePage.frames[0].document.applets.length > 0) {
  381.                     if (typeof(gHomePage.frames[0].document.applets["webhelp"]) != "undefined") {
  382.                         gHomePage.frames[0].document.applets["webhelp"].Command("SyncToc", strRelativeURL);
  383.                     }
  384.                 }
  385.                 else {
  386.                     // probably DHTML
  387.                     if (typeof(gHomePage.frames[0].frames["Tabs"]) != "undefined") {
  388.                         _bsscnBarSelectTOC(strRelativeURL);
  389.                     }
  390.                     else { // it must be list
  391.                     }
  392.                 }
  393.             }
  394.         }
  395.         else
  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 (message != null && typeof(message) == "string")
  504.         if(-1 != message.indexOf("denied") 
  505.             || -1 != message.indexOf("Object required"))
  506.          return true;
  507. }
  508.  
  509. onerror = _bsscnBarOnError;