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

  1. // Copyright (c) 2000-2001 Quadralay Corporation.  All rights reserved.
  2. // 
  3.  
  4. function  SearchBlank_Object()
  5. {
  6. }
  7.  
  8. function  Search_Object()
  9. {
  10.   this.mSearchWords      = new SearchBlank_Object();
  11.   this.mNewSearchWords   = new Array();
  12.   this.mCurrentBookIndex = -1;
  13.   this.mResults          = new Array();
  14.  
  15.   this.fSearchBook            = Search_SearchBook;
  16.   this.fIncrementCurBookIndex = Search_IncrementCurBookIndex;
  17.   this.fAddResults            = Search_AddResults;
  18.   this.fSearchBody            = Search_SearchBody;
  19.   this.fSearchSubmitted       = Search_SearchSubmitted;
  20.   this.fPerformSearch         = Search_PerformSearch;
  21.   this.fGenerateStyles        = Search_GenerateStyles;
  22.   this.fDisplayResults        = Search_DisplayResults;
  23.   this.fDisplaySearchForm     = Search_DisplaySearchForm;
  24.   this.fJumpTo                = Search_JumpTo;
  25. }
  26.  
  27. function  Search_SearchBook(ParamSearchFunc)
  28. {
  29.   var  SearchWord;
  30.   var  Results = null;
  31.   var  MatchedWord = null;
  32.  
  33.  
  34.   for (SearchWord in this.mSearchWords)
  35.   {
  36.     Results = ParamSearchFunc(SearchWord);
  37.  
  38.     if (Results != null)
  39.     {
  40.       this.fAddResults(SearchWord, Results);
  41.  
  42.       if (this.mSearchWords[SearchWord] != null)
  43.       {
  44.         this.mSearchWords[SearchWord] = true;
  45.       }
  46.     }
  47.   }
  48. }
  49.  
  50. function  Search_IncrementCurBookIndex()
  51. {
  52.   // Increment CurrentBookIndex
  53.   //
  54.   if (this.mCurrentBookIndex != -1)
  55.   {
  56.     if (this.mCurrentBookIndex < WWHelpTopFrame.WWHelp.mBookList.length)
  57.     {
  58.       this.mCurrentBookIndex++;
  59.     }
  60.     else  // We're done!
  61.     {
  62.       this.mCurrentBookIndex = -1;
  63.     }
  64.   }
  65. }
  66.  
  67. function  Search_AddResults(ParamWord,
  68.                             ParamHREFs)
  69. {
  70.   // Make certain we've got a book selected
  71.   //
  72.   if ((this.mCurrentBookIndex >= 0) &&
  73.       (ParamHREFs != null) &&
  74.       (ParamHREFs.length > 0))
  75.   {
  76.     var  BookResults;
  77.     var  MaxIndex;
  78.     var  Index;
  79.  
  80.  
  81.     // Get books containing this word
  82.     //
  83.     BookResults = this.mResults[this.mCurrentBookIndex];
  84.     if (BookResults == null)
  85.     {
  86.       BookResults = new Array();
  87.       this.mResults[this.mCurrentBookIndex] = BookResults;
  88.  
  89.       // Add all entries from ParamHREFs
  90.       //
  91.       for (MaxIndex = ParamHREFs.length, Index = 0 ; Index < MaxIndex ; Index++)
  92.       {
  93.         BookResults.length++;
  94.         BookResults[BookResults.length - 1] = ParamHREFs[Index];
  95.       }
  96.     }
  97.     else  // Remove entries which don't appear in ParamHREFs
  98.     {
  99.       var  TestHREFs      = new Array();
  100.       var  NewBookResults = new Array();
  101.  
  102.  
  103.       // Put ParamHREFs into an associative array for easy checking
  104.       //
  105.       for (MaxIndex = ParamHREFs.length, Index = 0 ; Index < MaxIndex ; Index++)
  106.       {
  107.         TestHREFs.length++;
  108.         TestHREFs[ParamHREFs[Index]] = true;
  109.       }
  110.  
  111.       // Remove entries from BookResults that aren't in TestHREFs
  112.       //
  113.       for (MaxIndex = BookResults.length, Index = 0 ; Index < MaxIndex ; Index++)
  114.       {
  115.         if (TestHREFs[BookResults[Index]])
  116.         {
  117.           NewBookResults.length++;
  118.           NewBookResults[NewBookResults.length - 1] = BookResults[Index];
  119.         }
  120.       }
  121.  
  122.       // Update results entry
  123.       //
  124.       this.mResults[this.mCurrentBookIndex] = NewBookResults;
  125.     }
  126.   }
  127. }
  128.  
  129. function  Search_SearchBody()
  130. {
  131.   this.fPerformSearch();
  132.  
  133.   WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("<script language=\"JavaScript\" src=\"" + WWHelpTopFrame.WWHelp.mBaseURL + "wwhelp/js/scripts/search3s.js\"></script>");
  134. }
  135.  
  136. function  Search_SearchSubmitted()
  137. {
  138.   // Check for new search words
  139.   //
  140.   if (WWHelpTopFrame.WWHNavigation.WWHSync.document.forms[0] != null)
  141.   {
  142.     var  SearchString;
  143.  
  144.  
  145.     // Stuff new search words into mNewSearchWords array
  146.     //
  147.     SearchString = WWHelpTopFrame.WWHNavigation.WWHSync.document.forms[0].SearchWords.value;
  148.     if ((SearchString != null) &&
  149.         (SearchString.length > 0))
  150.     {
  151.       var  SearchStringArray;
  152.       var  MaxIndex;
  153.       var  Index;
  154.  
  155.  
  156.       // Copy over search words
  157.       //
  158.       SearchStringArray = SearchString.split(" ");
  159.       this.mNewSearchWords.length = 0;
  160.       for (MaxIndex = SearchStringArray.length, Index = 0 ; Index < MaxIndex ; Index++)
  161.       {
  162.         // Need to eliminate zero length words
  163.         //
  164.         if (SearchStringArray[Index].length > 0)
  165.         {
  166.           // Convert them to lowercase before adding them
  167.           //
  168.           this.mNewSearchWords.length++;
  169.           this.mNewSearchWords[this.mNewSearchWords.length - 1] = SearchStringArray[Index].toLowerCase();
  170.         }
  171.       }
  172.     }
  173.   }
  174.  
  175.   return true;
  176. }
  177.  
  178. function  Search_PerformSearch()
  179. {
  180.   if (this.mNewSearchWords.length > 0)
  181.   {
  182.     var  MaxIndex;
  183.     var  Index;
  184.     var  CurrentBook;
  185.     var  MaxCount;
  186.     var  Count;
  187.  
  188.  
  189.     // Reset search results
  190.     //
  191.     this.mResults = new Array();
  192.     this.mResults.length = WWHelpTopFrame.WWHelp.mBookList.length;
  193.  
  194.     // Reset search words
  195.     //
  196.     this.mSearchWords = new SearchBlank_Object();
  197.     for (MaxIndex = this.mNewSearchWords.length, Index = 0 ; Index < MaxIndex ; Index++)
  198.     {
  199.       this.mSearchWords[this.mNewSearchWords[Index]] = false;  // Indicates whether they have been found
  200.     }
  201.     this.mNewSearchWords.length = 0;
  202.  
  203.     // Search all books for matches
  204.     //
  205.  
  206.     // Reset this.mCurrentBookIndex to 0
  207.     //
  208.     this.mCurrentBookIndex = 0;
  209.     for (MaxIndex = WWHelpTopFrame.WWHelp.mBookList.length, Index = 0 ; Index < MaxIndex ; Index++)
  210.     {
  211.       CurrentBook = WWHelpTopFrame.WWHelp.mBookList[Index];
  212.  
  213.       for (MaxCount = CurrentBook.mSearchFileCount, Count = 0 ; Count < MaxCount ; Count++)
  214.       {
  215.         // Include search script
  216.         //
  217.         WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("<script language=\"JavaScript\" src=\"" + WWHelpTopFrame.WWHelp.mBaseURL + CurrentBook.mBookDir + "wwhdata/js/search" + Count + ".js\"></script>");
  218.  
  219.         // Search file
  220.         //
  221.         WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("<script language=\"JavaScript\" src=\"" + WWHelpTopFrame.WWHelp.mBaseURL + "wwhelp/js/scripts/search1s.js\"></script>");
  222.       }
  223.  
  224.       // Increment this.mCurrentBookIndex
  225.       //
  226.       WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("<script language=\"JavaScript\" src=\"" + WWHelpTopFrame.WWHelp.mBaseURL + "wwhelp/js/scripts/search2s.js\"></script>");
  227.     }
  228.   }
  229. }
  230.  
  231. function  Search_GenerateStyles()
  232. {
  233.   var  ChildLevel;
  234.  
  235.  
  236.   WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("<style type=\"text/css\">");
  237.   WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln(" <!--");
  238.   WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("  a { text-decoration: none ;");
  239.   WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("      color: " + WWHelpTopFrame.WWHelp.mMessages["Anchor Color"] + " }");
  240.   WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("  p { margin-top: 1pt ;");
  241.   WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("      margin-bottom: 1pt ;");
  242.   WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("      font-family: " + WWHelpTopFrame.WWHelp.mMessages["Font Family"] + " ;");
  243.   WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("      font-size: " + WWHelpTopFrame.WWHelp.mMessages["Font Size"] + " }");
  244.   for (ChildLevel = 1 ; ChildLevel < 2 ; ChildLevel++)
  245.   {
  246.     WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("  p.l" + ChildLevel + " { margin-left: " + (WWHelpTopFrame.WWHelp.mMessages["Search Indent"] * ChildLevel) + "pt }");
  247.   }
  248.   WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln(" -->");
  249.   WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("</style>");
  250. }
  251.  
  252. function  Search_DisplayResults()
  253. {
  254.   var  bSearchWordsExist;
  255.   var  SearchWord;
  256.  
  257.  
  258.   // Check to see if results exist
  259.   //
  260.   bSearchWordsExist = false;
  261.   for (SearchWord in this.mSearchWords)
  262.   {
  263.     bSearchWordsExist = true;
  264.   }
  265.  
  266.   // Display results or prompt user to enter search words
  267.   //
  268.   if (bSearchWordsExist == false)
  269.   {
  270.     WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("<h3>" + WWHelpTopFrame.WWHelp.mMessages["Search EnterSearch"] + "</h3>");
  271.   }
  272.   else
  273.   {
  274.     var  bInvalidResults;
  275.     var  MaxIndex;
  276.     var  Index;
  277.  
  278.  
  279.     bInvalidResults = false;
  280.     for (SearchWord in this.mSearchWords)
  281.     {
  282.       if (this.mSearchWords[SearchWord] != true)
  283.       {
  284.         bInvalidResults = true;
  285.       }
  286.     }
  287.  
  288.     // Check to see if entries exist for each book
  289.     //
  290.     if ( ! bInvalidResults)
  291.     {
  292.       bInvalidResults = true;
  293.       for (MaxIndex = this.mResults.length, Index = 0 ; Index < MaxIndex ; Index++)
  294.       {
  295.         if ((this.mResults[Index] != null) &&
  296.             (this.mResults[Index].length > 0))
  297.         {
  298.           bInvalidResults = false;
  299.         }
  300.       }
  301.     }
  302.  
  303.     if (bInvalidResults)
  304.     {
  305.       WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("<h3>" + WWHelpTopFrame.WWHelp.mMessages["Search NoMatch"] + "</h3>");
  306.     }
  307.     else
  308.     {
  309.       var  BookResults;
  310.       var  bNeedSpacer = false;
  311.       var  MaxHREFIndex;
  312.       var  HREFIndex;
  313.       var  Title;
  314.  
  315.  
  316.       for (MaxIndex = this.mResults.length, Index = 0 ; Index < MaxIndex ; Index++)
  317.       {
  318.         BookResults = this.mResults[Index];
  319.         if (BookResults != null)
  320.         {
  321.           // Put spacers between books
  322.           //
  323.           if (bNeedSpacer)
  324.           {
  325.             WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("<p> </p>");
  326.           }
  327.           else
  328.           {
  329.             bNeedSpacer = true;
  330.           }
  331.  
  332.           // Display book title
  333.           //
  334.           WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("<p><nobr><b>" + WWHelpTopFrame.WWHelp.mBookList[Index].mBookTitle + "</b></nobr></p>");
  335.  
  336.           for (MaxHREFIndex = BookResults.length, HREFIndex = 0 ; HREFIndex < MaxHREFIndex ; HREFIndex++)
  337.           {
  338.             // Translate HREF to file title
  339.             //
  340.             Title = WWHelpTopFrame.WWHelp.fHREFToTitle(Index, BookResults[HREFIndex]);
  341.             if (Title.length == 0)
  342.             {
  343.               Title = BookResults[HREFIndex];
  344.             }
  345.  
  346.             WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("<p class=l1><nobr><a href=\"javascript:WWHelpTopFrame.WWHelp.mSearch.fJumpTo(" + Index + ", '" + BookResults[HREFIndex] + "');\">" + Title + "</a></nobr></p>");
  347.           }
  348.         }
  349.       }
  350.     }
  351.   }
  352. }
  353.  
  354. function  Search_DisplaySearchForm()
  355. {
  356.   var  SearchWord;
  357.   var  SearchWordsString;
  358.  
  359.  
  360.   // Get search words
  361.   //
  362.   SearchWordsString = "";
  363.   for (SearchWord in this.mSearchWords)
  364.   {
  365.     if (SearchWordsString.length > 0)
  366.     {
  367.       SearchWordsString += " ";
  368.     }
  369.  
  370.     SearchWordsString += SearchWord;
  371.   }
  372.  
  373.   WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("<form onSubmit=\"WWHelpTopFrame.WWHelp.mSearch.fSearchSubmitted();\">");
  374.   WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("<nobr>");
  375.   WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("<input type=\"text\" name=\"SearchWords\" size=20 value=\"" + SearchWordsString + "\">");
  376.   WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("<input type=\"submit\" value=\"" + WWHelpTopFrame.WWHelp.mMessages["Search Search"] + "\">");
  377.   WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("</nobr>");
  378.   WWHelpTopFrame.WWHNavigation.WWHSync.document.writeln("</form>");
  379. }
  380.  
  381. function  Search_JumpTo(ParamBookIndex,
  382.                         ParamHREF)
  383. {
  384.   var  JumpToHREF = "";
  385.  
  386.  
  387.   JumpToHREF += WWHelpTopFrame.WWHelp.mBaseURL;
  388.   JumpToHREF += WWHelpTopFrame.WWHelp.mBookList[ParamBookIndex].mBookDir;
  389.   JumpToHREF += ParamHREF;
  390.  
  391.   WWHelpTopFrame.WWHDocument.location.href = JumpToHREF;
  392. }
  393.