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

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