home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 January / Gamestar_80_2006-01_dvd.iso / Utility / 5-11_xp-2k_dd_ccc_wdm_enu_27345.exe / Data1.cab / _7C147B84CDB245CEB08835716A5C59FC < prev    next >
Text File  |  2003-09-15  |  6KB  |  186 lines

  1. // Copyright (c) 2000-2003 Quadralay Corporation.  All rights reserved.
  2. //
  3.  
  4. function  WWHHighlightWords_Object()
  5. {
  6.   this.mWords = null;
  7.  
  8.   this.fSetWordList = WWHHighlightWords_SetWordList;
  9.   this.fExec        = WWHHighlightWords_Exec;
  10. }
  11.  
  12. function  WWHHighlightWords_SetWordList(ParamWords)
  13. {
  14.   if (WWHFrame.WWHHelp.mSettings.mbHighlightingEnabled)
  15.   {
  16.     this.mWords = ParamWords;
  17.   }
  18.   else
  19.   {
  20.     this.mWords = null;
  21.   }
  22. }
  23.  
  24. function  WWHHighlightWords_Exec()
  25. {
  26.   var  WordList;
  27.   var  MaxIndex;
  28.   var  Index;
  29.   var  WordExpressions;
  30.   var  LongestWordExpression;
  31.   var  MaxExpressionIndex;
  32.   var  ExpressionIndex;
  33.   var  ExpressionHash = null;
  34.   var  ExpressionEntry;
  35.   var  Expression;
  36.   var  VarDocumentFrame;
  37.   var  LongestWordExpressionKey;
  38.   var  NewHighlightedWords = null;
  39.   var  HighlightedWords = null;
  40.   var  TextRange;
  41.   var  LastCharTextRange;
  42.   var  bMatchFound;
  43.   var  bFirstMatch;
  44.   var  NewHighlightedWordsKey;
  45.  
  46.  
  47.   if (this.mWords != null)
  48.   {
  49.     // Only works under IE on Windows
  50.     //
  51.     if ((WWHFrame.WWHBrowser.mBrowser == 2) &&  // Shorthand for IE
  52.         (WWHFrame.WWHBrowser.mPlatform == 1))   // Shorthand for Windows
  53.     {
  54.       ExpressionHash   = new WWHHighlightWords_ExpressionHash_Object();
  55.       HighlightedWords = new WWHHighlightWords_HighlightedWords_Object();
  56.       bFirstMatch = true;
  57.  
  58.       // Access search words
  59.       //
  60.       WordList = this.mWords.split(" ");
  61.       for (MaxIndex = WordList.length, Index = 0 ; Index < MaxIndex ; Index++)
  62.       {
  63.         if (WordList[Index].length > 0)
  64.         {
  65.           // Determine longest sub-expression between '*'
  66.           //
  67.           WordExpressions = WordList[Index].split("*");
  68.           LongestWordExpression = "";
  69.           for (MaxExpressionIndex = WordExpressions.length, ExpressionIndex = 0 ; ExpressionIndex < MaxExpressionIndex ; ExpressionIndex++)
  70.           {
  71.             if (WordExpressions[ExpressionIndex].length > LongestWordExpression.length)
  72.             {
  73.               LongestWordExpression = WordExpressions[ExpressionIndex];
  74.             }
  75.           }
  76.  
  77.           // Store search expression keyed by longest sub-expression
  78.           //
  79.           ExpressionEntry = ExpressionHash[LongestWordExpression + "~"];
  80.           if (typeof(ExpressionEntry) == "undefined")
  81.           {
  82.             ExpressionEntry = new WWHHighlightWords_ExpressionEntry_Object();
  83.             ExpressionHash[LongestWordExpression + "~"] = ExpressionEntry;
  84.           }
  85.           Expression = WWHStringUtilities_WordToRegExpWithSpacePattern(WordList[Index]);
  86.           ExpressionEntry.mExpressions[ExpressionEntry.mExpressions.length] = new RegExp(Expression, "i");
  87.         }
  88.       }
  89.  
  90.       // Search document based on longest sub-expressions
  91.       //
  92.       VarDocumentFrame = eval(WWHFrame.WWHHelp.fGetFrameReference("WWHDocumentFrame"));
  93.       for (LongestWordExpressionKey in ExpressionHash)
  94.       {
  95.         LongestWordExpression = LongestWordExpressionKey.substring(0, LongestWordExpressionKey.length - 1);
  96.         NewHighlightedWords = new WWHHighlightWords_HighlightedWords_Object();
  97.  
  98.         TextRange = VarDocumentFrame.document.body.createTextRange();
  99.         TextRange.collapse();
  100.         while (TextRange.findText(LongestWordExpression, 1))
  101.         {
  102.           TextRange.expand("word");
  103.           ExpressionEntry = ExpressionHash[LongestWordExpression + "~"];
  104.  
  105.           // Check word against search expression
  106.           //
  107.           bMatchFound = false;
  108.           MaxExpressionIndex = ExpressionEntry.mExpressions.length;
  109.           ExpressionIndex = 0;
  110.           while (( ! bMatchFound) &&
  111.                  (ExpressionIndex < MaxExpressionIndex))
  112.           {
  113.             if (ExpressionEntry.mExpressions[ExpressionIndex].test(TextRange.text))
  114.             {
  115.               // Highlight text if not processed already
  116.               //
  117.               if (typeof(HighlightedWords[TextRange.text + "~"]) == "undefined")
  118.               {
  119.                 // Record text highlighted for this expression
  120.                 //
  121.                 NewHighlightedWords[TextRange.text + "~"] = true;
  122.  
  123.                 // Try to trim off trailing whitespace or .s
  124.                 //
  125.                 LastCharTextRange = TextRange.duplicate();
  126.                 LastCharTextRange.moveStart("character", TextRange.text.length - 1);
  127.  
  128.                 if ((LastCharTextRange.text == " ") ||
  129.                     (LastCharTextRange.text == ",") ||
  130.                     (LastCharTextRange.text == "."))
  131.                 {
  132.                   // Prevent infinite loops if search is for "," or "."
  133.                   //
  134.                   if (LastCharTextRange.text != LongestWordExpression)
  135.                   {
  136.                     TextRange.moveEnd("character", -1);
  137.                   }
  138.                 }
  139.  
  140.                 TextRange.pasteHTML("<span style='background: " + WWHFrame.WWHHelp.mSettings.mHighlightingBackgroundColor + " ; color: " + WWHFrame.WWHHelp.mSettings.mHighlightingForegroundColor + "'>" + TextRange.htmlText + "</span>");
  141.  
  142.                 if (bFirstMatch)
  143.                 {
  144.                   TextRange.scrollIntoView();
  145.  
  146.                   bFirstMatch = false;
  147.                 }
  148.  
  149.                 bMatchFound = true;
  150.               }
  151.             }
  152.  
  153.             ExpressionIndex++;
  154.           }
  155.  
  156.           TextRange.collapse(false);
  157.         }
  158.  
  159.         // Add highlighted words to hash
  160.         //
  161.         for (NewHighlightedWordsKey in NewHighlightedWords)
  162.         {
  163.           HighlightedWords[NewHighlightedWordsKey] = true;
  164.         }
  165.       }
  166.     }
  167.   }
  168.  
  169.   // Highlight words only once
  170.   //
  171.   this.mWords = null;
  172. }
  173.  
  174. function  WWHHighlightWords_ExpressionHash_Object()
  175. {
  176. }
  177.  
  178. function  WWHHighlightWords_ExpressionEntry_Object()
  179. {
  180.   this.mExpressions = new Array();
  181. }
  182.  
  183. function  WWHHighlightWords_HighlightedWords_Object()
  184. {
  185. }
  186.