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

  1. function  Index_Object(ParamWWHelp)
  2. {
  3.   this.mWWHelp = ParamWWHelp;
  4.  
  5.   this.mIndicies       = new Array();
  6.   this.mJoinedIndicies = new Array();
  7.   this.mMaxLevel       = 0;
  8.   this.mJumpToArray    = null;
  9.  
  10.   this.fNewBook                 = Index_NewBook;
  11.   this.fJumpTo                  = Index_JumpTo;
  12.   this.fJumpToGenerateStyles    = Index_JumpToGenerateStyles;
  13.   this.fJumpToDisplaySelections = Index_JumpToDisplaySelections;
  14.   this.fSetDocumentDisplay      = Index_SetDocumentDisplay;
  15.   this.fGenerateStyles          = Index_GenerateStyles;
  16.   this.fDisplayIndex            = Index_DisplayIndex;
  17.   this.fJoinIndicies            = Index_JoinIndicies;
  18.   this.fDisplayJoinedIndicies   = Index_DisplayJoinedIndicies;
  19. }
  20.  
  21. function  IndexJumpTo_Object(ParamBookIndex,
  22.                              ParamLinkIndex)
  23. {
  24.   this.mBookIndex = ParamBookIndex;
  25.   this.mLinkIndex = ParamLinkIndex;
  26. }
  27.  
  28. function  IndexDisplayEntry_Object(ParamLevel,
  29.                                    ParamEntry,
  30.                                    ParamLinksString)
  31. {
  32.   this.mLevel       = ParamLevel;
  33.   this.mEntry       = ParamEntry;
  34.   this.mLinksString = ParamLinksString;
  35. }
  36.  
  37. function  Index_NewBook(ParamBook)
  38. {
  39.   var  NewIndex;
  40.  
  41.  
  42.   NewIndex = new Links_Object(ParamBook.mBookDir, ParamBook.mBookTitle);
  43.  
  44.   this.mIndicies.length++;
  45.   this.mIndicies[this.mIndicies.length - 1] = NewIndex;
  46.  
  47.   NewIndex.fLoadIndex(ParamBook.fAddIndexEntries);
  48.  
  49.   return NewIndex;
  50. }
  51.  
  52. function  Index_JumpTo(ParamJumpTo)
  53. {
  54.   var  BooksArray = ParamJumpTo.split("#");
  55.   var  MaxBookIndex;
  56.   var  BookIndex;
  57.   var  BookLinkArray;
  58.  
  59.  
  60.   // Build up list of all index links
  61.   //
  62.   this.mJumpToArray = new Array();
  63.   for (MaxBookIndex = BooksArray.length, BookIndex = 0 ; BookIndex < MaxBookIndex ; BookIndex++)
  64.   {
  65.     BookLinkArray = BooksArray[BookIndex].split("=");
  66.  
  67.     this.mJumpToArray.length++;
  68.     this.mJumpToArray[this.mJumpToArray.length - 1] = new IndexJumpTo_Object(BookLinkArray[0],   // Book Index
  69.                                                                              BookLinkArray[1]);  // Link Index
  70.   }
  71.  
  72.   // If index list exists, jump to single entry or display selection list
  73.   //
  74.   if (this.mJumpToArray.length > 0)
  75.   {
  76.     // Present selection dialog if necessary
  77.     //
  78.     if ((this.mJumpToArray.length == 1) &&
  79.         (this.mIndicies[this.mJumpToArray[0].mBookIndex].mLinks[this.mJumpToArray[0].mLinkIndex].mHREFs.length == 1))
  80.     {
  81.       // Just display the entry
  82.       //
  83.       this.fSetDocumentDisplay(this.mJumpToArray[0].mBookIndex, this.mJumpToArray[0].mLinkIndex, 0);
  84.     }
  85.     else
  86.     {
  87.       // Display selection list
  88.       //
  89.       WWHelpTopFrame.WWHDocument.location.href = this.mWWHelp.mBaseURL + "wwhelp/js/html/index.htm";
  90.     }
  91.   }
  92. }
  93.  
  94. function  Index_JumpToGenerateStyles()
  95. {
  96.   var  ChildLevel;
  97.  
  98.  
  99.   WWHelpTopFrame.WWHDocument.document.writeln("<style type=\"text/css\">");
  100.   WWHelpTopFrame.WWHDocument.document.writeln(" <!--");
  101.   WWHelpTopFrame.WWHDocument.document.writeln("  a { text-decoration: none ;");
  102.   WWHelpTopFrame.WWHDocument.document.writeln("      color: " + this.mWWHelp.mMessages["Anchor Color"] + " }");
  103.   WWHelpTopFrame.WWHDocument.document.writeln("  p { margin-top: 1pt ;");
  104.   WWHelpTopFrame.WWHDocument.document.writeln("      margin-bottom: 1pt ;");
  105.   WWHelpTopFrame.WWHDocument.document.writeln("      font-family: " + this.mWWHelp.mMessages["Font Family"] + " ;");
  106.   WWHelpTopFrame.WWHDocument.document.writeln("      font-size: " + this.mWWHelp.mMessages["Font Size"] + " }");
  107.   for (ChildLevel = 1 ; ChildLevel < 3 ; ChildLevel++)
  108.   {
  109.     WWHelpTopFrame.WWHDocument.document.writeln("  p.l" + ChildLevel + " { margin-left: " + (this.mWWHelp.mMessages["Index Indent"] * ChildLevel) + "pt }");
  110.   }
  111.   WWHelpTopFrame.WWHDocument.document.writeln(" -->");
  112.   WWHelpTopFrame.WWHDocument.document.writeln("</style>");
  113. }
  114.  
  115. function  Index_JumpToDisplaySelections()
  116. {
  117.   var  MaxJumpToIndex;
  118.   var  JumpToIndex;
  119.  
  120.  
  121.   WWHelpTopFrame.WWHDocument.document.writeln("<p><b>" + this.mIndicies[this.mJumpToArray[0].mBookIndex].mLinks[this.mJumpToArray[0].mLinkIndex].mKey + "</b></p>");
  122.  
  123.   for (MaxJumpToIndex = this.mJumpToArray.length, JumpToIndex = 0 ; JumpToIndex < MaxJumpToIndex ; JumpToIndex++)
  124.   {
  125.     var  JumpToEntry;
  126.     var  LinkEntry;
  127.     var  MaxHREFIndex;
  128.     var  HREFIndex;
  129.     var  CopyHREFs = new Array();
  130.  
  131.  
  132.     JumpToEntry = this.mJumpToArray[JumpToIndex];
  133.     LinkEntry = this.mIndicies[JumpToEntry.mBookIndex].mLinks[JumpToEntry.mLinkIndex];
  134.  
  135.     CopyHREFs.length = LinkEntry.mHREFs.length;
  136.     for (MaxHREFIndex = LinkEntry.mHREFs.length, HREFIndex = 0 ; HREFIndex < MaxHREFIndex ; HREFIndex++)
  137.     {
  138.       CopyHREFs[HREFIndex] = new String(LinkEntry.mHREFs[HREFIndex]);
  139.     }
  140.  
  141.     WWHelpTopFrame.WWHDocument.document.writeln("<p> </p>");
  142.     WWHelpTopFrame.WWHDocument.document.writeln("<p class=l1><nobr><b>" + this.mIndicies[JumpToEntry.mBookIndex].mBookTitle + "</b></nobr></p>");
  143.  
  144.     for (MaxHREFIndex = CopyHREFs.length, HREFIndex = 0 ; HREFIndex < MaxHREFIndex ; HREFIndex++)
  145.     {
  146.       if (CopyHREFs[HREFIndex] != null)
  147.       {
  148.         var  AltHREFIndex;
  149.         var  LinkHREF;
  150.         var  LinkHREFAnchorIndex;
  151.         var  LinkHREFTrimmed;
  152.         var  SomeHREFTrimmed;
  153.         var  LinkTitle;
  154.  
  155.  
  156.         // Find link without named anchors attached
  157.         //
  158.         LinkHREFTrimmed = this.mWWHelp.fTrimHREF(CopyHREFs[HREFIndex]);
  159.  
  160.         // Find link title
  161.         //
  162.         LinkTitle = this.mWWHelp.fHREFToTitle(JumpToEntry.mBookIndex, LinkHREFTrimmed);
  163.  
  164.         // If no match found, default to index word
  165.         //
  166.         if (LinkTitle.length <= 0)
  167.         {
  168.           LinkTitle = LinkHREFTrimmed;
  169.         }
  170.  
  171.         // Drop the link
  172.         //
  173.         WWHelpTopFrame.WWHDocument.document.write("<p class=l2><nobr><a href=\"javascript:WWHelpTopFrame.WWHelp.mIndex.fSetDocumentDisplay(" + JumpToEntry.mBookIndex + "," + JumpToEntry.mLinkIndex + "," + HREFIndex + ");\">" + LinkTitle + "</a>");
  174.  
  175.         // Look for links to the same document
  176.         //
  177.         for (AltHREFIndex = (HREFIndex + 1) ; AltHREFIndex < MaxHREFIndex ; AltHREFIndex++)
  178.         {
  179.           if (CopyHREFs[AltHREFIndex] != null)
  180.           {
  181.             // Find link without named anchors attached
  182.             //
  183.             SomeHREFTrimmed = this.mWWHelp.fTrimHREF(CopyHREFs[AltHREFIndex]);
  184.  
  185.             if (SomeHREFTrimmed == LinkHREFTrimmed)
  186.             {
  187.               // Found a link in the same document
  188.               //
  189.               WWHelpTopFrame.WWHDocument.document.write(", <a href=\"javascript:WWHelpTopFrame.WWHelp.mIndex.fSetDocumentDisplay(" + JumpToEntry.mBookIndex + "," + JumpToEntry.mLinkIndex + "," + AltHREFIndex + ");\">" + (AltHREFIndex - HREFIndex + 1) + "</a>");
  190.  
  191.               // Remove entry so it won't be added more than once
  192.               //
  193.               CopyHREFs[AltHREFIndex] = null;
  194.             }
  195.           }
  196.         }
  197.  
  198.         WWHelpTopFrame.WWHDocument.document.writeln("</nobr></p>");
  199.       }
  200.     }
  201.   }
  202. }
  203.  
  204. function  Index_SetDocumentDisplay(ParamBookIndex,
  205.                                    ParamLinkIndex,
  206.                                    ParamHREFIndex)
  207. {
  208.   var  NewHREF;
  209.  
  210.  
  211.   NewHREF = this.mWWHelp.mBaseURL + this.mIndicies[ParamBookIndex].mBookDir + this.mIndicies[ParamBookIndex].mLinks[ParamLinkIndex].mHREFs[ParamHREFIndex];
  212.  
  213.   WWHelpTopFrame.WWHDocument.location.href = NewHREF;
  214. }
  215.  
  216. function  Index_GenerateStyles()
  217. {
  218.   var  ChildLevel;
  219.  
  220.  
  221.   // Build up display list
  222.   //
  223.   if (this.mJoinedIndicies.length == 0)
  224.   {
  225.     this.fJoinIndicies();
  226.   }
  227.  
  228.   // Generate style section
  229.   //
  230.   WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("<style type=\"text/css\">");
  231.   WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln(" <!--");
  232.   WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("  a { text-decoration: none ;");
  233.   WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("      color: " + this.mWWHelp.mMessages["Anchor Color"] + " }");
  234.   WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("  p { margin-top: 1pt ;");
  235.   WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("      margin-bottom: 1pt ;");
  236.   WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("      font-family: " + this.mWWHelp.mMessages["Font Family"] + " ;");
  237.   WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("      font-size: " + this.mWWHelp.mMessages["Font Size"] + " }");
  238.   for (ChildLevel = 1 ; ChildLevel <= this.mMaxLevel ; ChildLevel++)
  239.   {
  240.     WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("  p.l" + ChildLevel + " { margin-left: " + (this.mWWHelp.mMessages["Index Indent"] * ChildLevel) + "pt }");
  241.   }
  242.   WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln(" -->");
  243.   WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("</style>");
  244. }
  245.  
  246. function  Index_DisplayIndex()
  247. {
  248.   this.fDisplayJoinedIndicies();
  249. }
  250.  
  251. function  Index_JoinIndicies()
  252. {
  253.   var  CurPosArray = new Array();
  254.   var  MaxIndex;
  255.   var  Index;
  256.   var  bMergeDone = true;
  257.   var  SmallestEntry;
  258.   var  LinksString;
  259.   var  CurrentLinkEntry;
  260.   var  BookSeparator;
  261.   var  DisplayLevel;
  262.   var  DisplayString;
  263.   var  SplitStrings;
  264.   var  NewDisplayEntry;
  265.  
  266.  
  267.   // Reset this.mMaxLevel
  268.   //
  269.   this.mMaxLevel = 0;
  270.  
  271.   this.mJoinedIndicies.length = 0;
  272.  
  273.   // Sort each index individually and
  274.   // initialize current position array for each index
  275.   //
  276.   CurPosArray.length = this.mIndicies.length;
  277.   MaxIndex = CurPosArray.length;
  278.   for (Index = 0 ; Index < MaxIndex ; Index++)
  279.   {
  280.     CurPosArray[Index] = 0;  // Current position in all indicies starts at 0
  281.  
  282.     if (this.mIndicies[Index].mLinks.length <= 0)
  283.     {
  284.       CurPosArray[Index] = -1;  // Indicates the end of index reached
  285.     }
  286.     else  // Entries to process exist
  287.     {
  288.       bMergeDone = false;
  289.  
  290.       // Sort the index
  291.       //
  292.       this.mIndicies[Index].fSortEntries();
  293.     }
  294.   }
  295.  
  296.   // Perform an n-way merge sort
  297.   //
  298.   while ( ! bMergeDone)
  299.   {
  300.     // Set initial value for SmallestEntry
  301.     // Need to do this before adding links together to avoid
  302.     // combined entry problems when we discover a smaller entry
  303.     // later on in the merge process.  This avoids the problem
  304.     // by finding the smallest entry first.
  305.     // MaxIndex still set to CurPosArray.length
  306.     //
  307.     bMergeDone = true;
  308.     SmallestEntry = null;
  309.     for (Index = 0 ; Index < MaxIndex ; Index++)
  310.     {
  311.       if (CurPosArray[Index] >= 0)  // Check for indicies that are done
  312.       {
  313.         CurrentLinkEntry = this.mIndicies[Index].mLinks[CurPosArray[Index]];
  314.  
  315.         if ((SmallestEntry == null) ||
  316.             (LinksEntry_SortFunction(CurrentLinkEntry, SmallestEntry) == -1))
  317.         {
  318.           bMergeDone = false;
  319.           SmallestEntry = CurrentLinkEntry;
  320.         }
  321.       }
  322.     }
  323.  
  324.     // Add links for the smallest entry
  325.     //
  326.     if (SmallestEntry != null)
  327.     {
  328.       // For all valid positions (not -1, > 0), find the smallest entry key
  329.       // MaxIndex still set to CurPosArray.length
  330.       //
  331.       LinksString = "";
  332.       for (Index = 0 ; Index < MaxIndex ; Index++)
  333.       {
  334.         // Only add links if current entry is equal to the smallest entry
  335.         //
  336.         while ((CurPosArray[Index] >= 0) &&  // Check for indicies that are done
  337.                (CurrentLinkEntry = this.mIndicies[Index].mLinks[CurPosArray[Index]]) &&  // Intentinal assignment
  338.                (LinksEntry_SortFunction(CurrentLinkEntry, SmallestEntry) == 0))
  339.         {
  340.           // Add links via numerical entries
  341.           //
  342.           HREFsArray = CurrentLinkEntry.mHREFs;
  343.  
  344.           if (HREFsArray.length > 0)  // Only add entries if there are links
  345.           {
  346.             if (LinksString.length > 0)
  347.             {
  348.               BookSeparator = "#";  // Add separator between book entries
  349.             }
  350.             else
  351.             {
  352.               BookSeparator = "";  // Add separator between book entries
  353.             }
  354.  
  355.             // Format is:
  356.             //
  357.             //  [Book Index]=[Link Index]#[Book Index]=[Link Index]
  358.             //
  359.             LinksString += BookSeparator + Index + "=" + CurPosArray[Index];
  360.           }
  361.  
  362.           // Increment position
  363.           //
  364.           CurPosArray[Index] += 1;
  365.  
  366.           // Test for reaching end of index
  367.           //
  368.           if (CurPosArray[Index] >= this.mIndicies[Index].mLinks.length)
  369.           {
  370.             CurPosArray[Index] = -1;  // Indicates the end of index reached
  371.           }
  372.         }
  373.       }
  374.  
  375.       // Display smallest entry and bump the position counter
  376.       //
  377.  
  378.       // Set display entry level and string
  379.       //
  380.       if (SmallestEntry.mKey.indexOf("\t") != -1)
  381.       {
  382.         SplitStrings  = SmallestEntry.mKey.split("\t");
  383.  
  384.         DisplayString = SplitStrings[SplitStrings.length - 1];
  385.         DisplayLevel  = SplitStrings.length;
  386.       }
  387.       else
  388.       {
  389.         DisplayString = SmallestEntry.mKey;
  390.         DisplayLevel  = 1;
  391.       }
  392.  
  393.       // Display index entry
  394.       //
  395.       NewDisplayEntry = new IndexDisplayEntry_Object(DisplayLevel, DisplayString, LinksString);
  396.  
  397.       this.mJoinedIndicies.length++;
  398.       this.mJoinedIndicies[this.mJoinedIndicies.length - 1] = NewDisplayEntry;
  399.  
  400.       // Update MaxLevel
  401.       //
  402.       if (DisplayLevel > this.mMaxLevel)
  403.       {
  404.         this.mMaxLevel = DisplayLevel;
  405.       }
  406.     }
  407.   }
  408. }
  409.  
  410. function  Index_DisplayJoinedIndicies()
  411. {
  412.   var  MaxIndex;
  413.   var  Index;
  414.   var  PrevCharSection = "";
  415.   var  CurCharSection;
  416.  
  417.  
  418.   for (MaxIndex = this.mJoinedIndicies.length, Index = 0 ; Index < MaxIndex ; Index++)
  419.   {
  420.     // Insert breaks between sections
  421.     //
  422.     if (this.mJoinedIndicies[Index].mLevel == 1)
  423.     {
  424.       CurCharSection = this.mJoinedIndicies[Index].mEntry.charAt(0).toUpperCase();
  425.       if (CurCharSection != PrevCharSection)
  426.       {
  427.         if (PrevCharSection.length > 0)
  428.         {
  429.           WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("<p> </p>");
  430.         }
  431.         WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("<p><b>" + CurCharSection.toUpperCase() + "</b></p>");
  432.  
  433.         PrevCharSection = CurCharSection;
  434.       }
  435.     }
  436.  
  437.     // Display index entry
  438.     //
  439.     if (this.mJoinedIndicies[Index].mLinksString.length == 0)  // Check for items with no entries
  440.     {
  441.       WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("<p class=l" + this.mJoinedIndicies[Index].mLevel + "><nobr>"  + this.mJoinedIndicies[Index].mEntry + "</nobr></p>");
  442.     }
  443.     else
  444.     {
  445.       WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("<p class=l" + this.mJoinedIndicies[Index].mLevel + "><nobr><a href=\"javascript:WWHelpTopFrame.WWHelp.mIndex.fJumpTo('" + this.mJoinedIndicies[Index].mLinksString + "');\">" + this.mJoinedIndicies[Index].mEntry + "</a></nobr></p>");
  446.     }
  447.   }
  448. }
  449.