home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 November / Chip_2003-11_cd2.bin / ruzne / painter / PAINTE~2.cab / _B0265FC3D78F4B658086A49B40B2BC46 < prev    next >
Text File  |  2003-01-06  |  15KB  |  451 lines

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