home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 August / 08_02.iso / software / cb5 / files / Bryce5TrialVersion.exe / data1.cab / HelpFiles / wwhelp / js / scripts / wwhelpf.js < prev   
Encoding:
JavaScript  |  2001-07-16  |  10.3 KB  |  388 lines

  1. function  WWHelp_Object()
  2. {
  3.   var  Agent = "";
  4.   var  MajorVersion = 0;
  5.  
  6.  
  7.   // Determine browser
  8.   //
  9.   this.mBrowser = 0;  // Shorthand for Unknown
  10.  
  11.   Agent = navigator.userAgent.toLowerCase();
  12.   if ((Agent.indexOf("mozilla") != -1) &&
  13.       (Agent.indexOf("spoofer") == -1) &&
  14.       (Agent.indexOf("compatible") == -1))
  15.   {
  16.     MajorVersion = parseInt(navigator.appVersion)
  17.     if (MajorVersion >= 4)
  18.     {
  19.       this.mBrowser = 1;  // Shorthand for Netscape
  20.     }
  21.   }
  22.   else if (Agent.indexOf("msie") != -1)
  23.   {
  24.     MajorVersion = parseInt(navigator.appVersion)
  25.     if (MajorVersion >= 4)
  26.     {
  27.       this.mBrowser = 2;  // Shorthand for IE
  28.     }
  29.   }
  30.   else if (Agent.indexOf("icab") != -1)
  31.   {
  32.     this.mBrowser = 3;  // Shorthand for iCab
  33.   }
  34.  
  35.   // Determine platform
  36.   //
  37.   this.mPlatform = 0;  // Shorthand for Unknown
  38.  
  39.   if ((Agent.indexOf("win") != -1) ||
  40.       (Agent.indexOf("16bit") != -1))
  41.   {
  42.     this.mPlatform = 1;  // Shorthand for Windows
  43.   }
  44.   else if (Agent.indexOf("mac") != -1)
  45.   {
  46.     this.mPlatform = 2;  // Shorthand for Macintosh
  47.   }
  48.  
  49.   this.mbInitialized     = false;
  50.   this.mMessages         = new Array();
  51.   this.mBookDirList      = new Array();
  52.   this.mBookList         = new Array();
  53.   this.mBaseURL          = location.href.substring(0, location.href.lastIndexOf("/wwhelp/js/html/frames.htm")) + "/";
  54.   this.mCurrentBookIndex = -1;
  55.   this.mTabs             = new Tabs_Object(this);
  56.   this.mSync             = new Sync_Object(this);
  57.   this.mContents         = new Outline_Object(this);
  58.   this.mIndex            = new Index_Object(this);
  59.   this.mSearch           = new Search_Object(this);
  60.  
  61.   this.fAddBookDir            = WWHelp_AddBookDir;
  62.   this.fAddBook               = WWHelp_AddBook;
  63.   this.fIncrementCurBookIndex = WWHelp_IncrementCurBookIndex;
  64.   this.fTrimHREF              = WWHelp_TrimHREF;
  65.   this.fHREFToTitle           = WWHelp_HREFToTitle;
  66.   this.fParseHREF             = WWHelp_ParseHREF;
  67.   this.fSyncTOC               = WWHelp_SyncTOC;
  68.   this.fDataHTML              = WWHelp_DataHTML;
  69.   this.fDataHead              = WWHelp_DataHead;
  70.   this.fDataBody              = WWHelp_DataBody;
  71.  
  72.   // Load up messages
  73.   //
  74.   WWHelp_Messages(this.mMessages);
  75. }
  76.  
  77. function  WWHelp_AddBookDir(ParamBookDir)
  78. {
  79.   if ( ! this.mbInitialized)
  80.   {
  81.     if ((ParamBookDir != null) &&
  82.         (ParamBookDir.length > 0))
  83.     {
  84.       this.mBookDirList.length++;
  85.  
  86.       if (ParamBookDir == ".")
  87.       {
  88.         this.mBookDirList[this.mBookDirList.length - 1] = "";
  89.       }
  90.       else
  91.       {
  92.         this.mBookDirList[this.mBookDirList.length - 1] = escape(ParamBookDir) + "/";
  93.       }
  94.     }
  95.   }
  96. }
  97.  
  98. function  WWHelp_AddBook(ParamNewBook)
  99. {
  100.   var  NewBookTOCEntry;
  101.   var  NewBookIndexEntry;
  102.  
  103.  
  104.   this.mBookList.length++;
  105.   this.mBookList[this.mBookList.length - 1] = ParamNewBook;
  106.  
  107.   // Create TOC
  108.   //
  109.   if (this.mMessages["Tabs TOC"].length > 0)
  110.   {
  111.     NewBookTOCEntry = this.mContents.fNewBook(this.mBookList.length - 1, ParamNewBook.mBookTitle);
  112.     ParamNewBook.fAddTOCEntries(NewBookTOCEntry);
  113.   }
  114.  
  115.   // Add Index
  116.   //
  117.   if (this.mMessages["Tabs Index"].length > 0)
  118.   {
  119.     this.mIndex.fNewBook(ParamNewBook);
  120.   }
  121. }
  122.  
  123. function  WWHelp_IncrementCurBookIndex()
  124. {
  125.   // Increment CurrentBookIndex
  126.   //
  127.   if (this.mCurrentBookIndex != -1)
  128.   {
  129.     if (this.mCurrentBookIndex < this.mBookDirList.length)
  130.     {
  131.       this.mCurrentBookIndex++;
  132.     }
  133.     else  // We're done!
  134.     {
  135.       this.mCurrentBookIndex = -1;
  136.     }
  137.   }
  138. }
  139.  
  140. function  WWHelp_TrimHREF(ParamHREF)
  141. {
  142.   var  PoundIndex;
  143.   var  TrimmedHREF;
  144.  
  145.  
  146.   // Remove named anchor entries from link
  147.   //
  148.   PoundIndex = ParamHREF.lastIndexOf("#");
  149.   if (PoundIndex > 0)
  150.   {
  151.     TrimmedHREF = ParamHREF.substring(0, PoundIndex);
  152.   }
  153.   else
  154.   {
  155.     TrimmedHREF = ParamHREF;
  156.   }
  157.  
  158.   return TrimmedHREF;
  159. }
  160.  
  161. function  WWHelp_HREFToTitle(ParamBookIndex,
  162.                              ParamHREF)
  163. {
  164.   var  Title;
  165.   var  MaxIndex;
  166.   var  Index;
  167.  
  168.  
  169.   Title = "";
  170.   MaxIndex = this.mBookList.length;
  171.   Index = 0;
  172.   while ((Title.length == 0) &&
  173.          (Index < MaxIndex))
  174.   {
  175.     Title = this.mBookList[Index].fHREFToTitle(ParamHREF);
  176.  
  177.     Index++;
  178.   }
  179.  
  180.   return Title;
  181. }
  182.  
  183. function  WWHelp_ParseHREF(ParamHREF)
  184. {
  185.   var  ResultArray = new Array("", "");
  186.  
  187.  
  188.   if ((this.mBaseURL.length > 0) &&
  189.       (ParamHREF.length > this.mBaseURL.length))  // Make certain this can match
  190.   {
  191.     var  Prefix;
  192.     var  Suffix;
  193.  
  194.  
  195.     Prefix = ParamHREF.substring(0, this.mBaseURL.length);
  196.     Suffix = ParamHREF.substring(this.mBaseURL.length, ParamHREF.length);
  197.  
  198.     // Confirm we're under the same hierarchy
  199.     //
  200.     if (Prefix == this.mBaseURL)
  201.     {
  202.       var  LongestMatchIndex;
  203.       var  MaxIndex;
  204.       var  Index;
  205.  
  206.  
  207.       // Fix for differences between URL escapes and JavaScript
  208.       //
  209.       Suffix = unescape(Suffix);
  210.       Suffix = escape(Suffix);
  211.  
  212.       // Find the book directory
  213.       //
  214.       LongestMatchIndex = -1;
  215.       for (MaxIndex = this.mBookDirList.length, Index = 0 ; Index < MaxIndex ; Index++)
  216.       {
  217.         if (Suffix.indexOf(this.mBookDirList[Index]) == 0)
  218.         {
  219.           if (LongestMatchIndex == -1)
  220.           {
  221.             LongestMatchIndex = Index;
  222.           }
  223.           else if (this.mBookDirList[Index].length > this.mBookDirList[LongestMatchIndex].length)
  224.           {
  225.             LongestMatchIndex = Index;
  226.           }
  227.         }
  228.       }
  229.  
  230.       // If LongestMatchIndex is valid, we found our book directory
  231.       //
  232.       if (LongestMatchIndex != -1)
  233.       {
  234.         var  Parts;
  235.  
  236.  
  237.         // Reset suffix to be just the file portion
  238.         //
  239.         if (this.mBookDirList[LongestMatchIndex].length > 0)
  240.         {
  241.           Suffix = Suffix.substring(this.mBookDirList[LongestMatchIndex].length, Suffix.length);
  242.         }
  243.  
  244.         // Fixup any escaped "#"s
  245.         //
  246.         Suffix = unescape(Suffix);
  247.         Parts = Suffix.split("#");
  248.         for (MaxIndex = Parts.length, Index = 0 ; Index < MaxIndex ; Index++)
  249.         {
  250.           Parts[Index] = escape(Parts[Index]);
  251.         }
  252.         Suffix = Parts.join("#");
  253.  
  254.         ResultArray[0] = this.mBookDirList[LongestMatchIndex];
  255.         ResultArray[1] = Suffix;
  256.       }
  257.     }
  258.   }
  259.  
  260.   return ResultArray;
  261. }
  262.  
  263. function  WWHelp_SyncTOC(ParamHREF)
  264. {
  265.   // Only sync if TOC is available
  266.   // and selected
  267.   //
  268.   if ((ParamHREF != null) &&
  269.       (this.mMessages["Tabs TOC"].length > 0))
  270.   {
  271.     var  ParsedHREF;
  272.     var  BookDir;
  273.     var  FileHREF;
  274.     var  MaxIndex;
  275.     var  Index;
  276.     var  BookID;
  277.  
  278.  
  279.     // Get BookDir and FileHREF
  280.     //
  281.     ParsedHREF = this.fParseHREF(ParamHREF);
  282.     BookDir  = ParsedHREF[0];
  283.     FileHREF = ParsedHREF[1];
  284.  
  285.     // Determine BookID
  286.     //
  287.     BookID = -1;
  288.     MaxIndex = this.mBookList.length;
  289.     Index = 0;
  290.     while ((BookID == -1) &&
  291.            (Index < MaxIndex))
  292.     {
  293.       if (this.mBookList[Index].mBookDir == BookDir)
  294.       {
  295.         BookID = Index;
  296.       }
  297.  
  298.       Index++;
  299.     }
  300.  
  301.     // Display the selection
  302.     //
  303.     if (BookID != -1)
  304.     {
  305.       var  bVisible = false;
  306.  
  307.  
  308.       if (this.mTabs.mCurrentTab == 0)  // Outline view
  309.       {
  310.         bVisible = true;
  311.       }
  312.  
  313.       this.mContents.fSync(BookID, FileHREF, bVisible);
  314.     }
  315.   }
  316. }
  317.  
  318. function  WWHelp_DataHTML()
  319. {
  320.   if ( ! this.mbInitialized)
  321.   {
  322.     WWHelpTopFrame.WWHNavigation.WWHData.document.open("text/html", "replace");
  323.     WWHelpTopFrame.WWHNavigation.WWHData.document.writeln("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\"");
  324.     WWHelpTopFrame.WWHNavigation.WWHData.document.writeln("            \"http://www.w3.org/TR/REC-html40/strict.dtd\">");
  325.     WWHelpTopFrame.WWHNavigation.WWHData.document.writeln("<html>");
  326.     WWHelpTopFrame.WWHNavigation.WWHData.document.writeln("<head>");
  327.     WWHelpTopFrame.WWHNavigation.WWHData.document.writeln("<title>Data</title>");
  328.  
  329.     this.fDataHead();
  330.  
  331.     WWHelpTopFrame.WWHNavigation.WWHData.document.writeln("</head>");
  332.  
  333.     WWHelpTopFrame.WWHNavigation.WWHData.document.writeln("<body>");
  334.  
  335.     this.fDataBody();
  336.  
  337.     WWHelpTopFrame.WWHNavigation.WWHData.document.writeln("</body>");
  338.     WWHelpTopFrame.WWHNavigation.WWHData.document.writeln("</html>");
  339.     WWHelpTopFrame.WWHNavigation.WWHData.document.close();
  340.   }
  341. }
  342.  
  343. function  WWHelp_DataHead()
  344. {
  345.   if ( ! this.mbInitialized)
  346.   {
  347.     WWHelpTopFrame.WWHNavigation.WWHData.document.writeln("<script language=\"JavaScript\" src=\"" + this.mBaseURL + "wwhelp/js/scripts/bookf.js\"></script>");
  348.   }
  349. }
  350.  
  351. function  WWHelp_DataBody()
  352. {
  353.   if ( ! this.mbInitialized)
  354.   {
  355.     var  MaxIndex;
  356.     var  Index;
  357.  
  358.  
  359.     this.mCurrentBookIndex = 0;
  360.     for (MaxIndex = this.mBookDirList.length, Index = 0 ; Index < MaxIndex ; Index++)
  361.     {
  362.       // Add entries for Book info
  363.       //
  364.       WWHelpTopFrame.WWHNavigation.WWHData.document.writeln("<script language=\"JavaScript\" src=\"" + this.mBaseURL + this.mBookDirList[Index] + "wwhdata/js/book.js\"></script>");
  365.       WWHelpTopFrame.WWHNavigation.WWHData.document.writeln("<script language=\"JavaScript\" src=\"" + this.mBaseURL + this.mBookDirList[Index] + "wwhdata/js/search.js\"></script>");
  366.       WWHelpTopFrame.WWHNavigation.WWHData.document.writeln("<script language=\"JavaScript\" src=\"" + this.mBaseURL + this.mBookDirList[Index] + "wwhdata/js/files.js\"></script>");
  367.       WWHelpTopFrame.WWHNavigation.WWHData.document.writeln("<script language=\"JavaScript\" src=\"" + this.mBaseURL + this.mBookDirList[Index] + "wwhdata/js/toc.js\"></script>");
  368.       WWHelpTopFrame.WWHNavigation.WWHData.document.writeln("<script language=\"JavaScript\" src=\"" + this.mBaseURL + this.mBookDirList[Index] + "wwhdata/js/index.js\"></script>");
  369.  
  370.       // Create new book
  371.       //
  372.       WWHelpTopFrame.WWHNavigation.WWHData.document.writeln("<script language=\"JavaScript\" src=\"" + this.mBaseURL + "wwhelp/js/scripts/data1s.js\"></script>");
  373.  
  374.       // Increment this.mCurrentBookIndex
  375.       //
  376.       WWHelpTopFrame.WWHNavigation.WWHData.document.writeln("<script language=\"JavaScript\" src=\"" + this.mBaseURL + "wwhelp/js/scripts/data2s.js\"></script>");
  377.     }
  378.  
  379.     // Set initialized flag
  380.     //
  381.     this.mbInitialized = true;
  382.  
  383.     // Update Tabs and Sync frames
  384.     //
  385.     WWHelpTopFrame.WWHNavigation.WWHData.document.writeln("<script language=\"JavaScript\" src=\"" + this.mBaseURL + "wwhelp/js/scripts/data3s.js\"></script>");
  386.   }
  387. }
  388.