home *** CD-ROM | disk | FTP | other *** search
/ Thomson (Residential) / TGSTPv7203.iso / mac / Documentation / HTML / TG605_en / wwhelp / wwhimpl / common / scripts / highlt.js < prev    next >
Text File  |  2007-06-22  |  5KB  |  157 lines

  1. // Copyright (c) 2000-2001 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.   if (this.mWords != null)
  27.   {
  28.     // Only works under IE on Windows
  29.     //
  30.     if ((WWHFrame.WWHBrowserInfo.mBrowser == 2) &&  // Shorthand for IE
  31.         (WWHFrame.WWHBrowserInfo.mPlatform == 1))   // Shorthand for Windows
  32.     {
  33.       var  WordList;
  34.       var  MaxIndex;
  35.       var  Index;
  36.       var  WordExpressions;
  37.       var  LongestWordExpression;
  38.       var  MaxExpressionIndex;
  39.       var  ExpressionIndex;
  40.       var  ExpressionHash = new WWHHighlightWords_ExpressionHash_Object();
  41.       var  ExpressionEntry;
  42.       var  Expression;
  43.       var  NewHighlightedWords = null;
  44.       var  HighlightedWords = new WWHHighlightWords_HighlightedWords_Object();
  45.       var  TextRange;
  46.       var  bMatchFound;
  47.       var  bFirstMatch = true;
  48.  
  49.  
  50.       // Access search words
  51.       //
  52.       WordList = this.mWords.split(" ");
  53.       for (MaxIndex = WordList.length, Index = 0 ; Index < MaxIndex ; Index++)
  54.       {
  55.         if (WordList[Index].length > 0)
  56.         {
  57.           // Determine longest sub-expression between '*'
  58.           //
  59.           WordExpressions = WordList[Index].split("*");
  60.           LongestWordExpression = "";
  61.           for (MaxExpressionIndex = WordExpressions.length, ExpressionIndex = 0 ; ExpressionIndex < MaxExpressionIndex ; ExpressionIndex++)
  62.           {
  63.             if (WordExpressions[ExpressionIndex].length > LongestWordExpression.length)
  64.             {
  65.               LongestWordExpression = WordExpressions[ExpressionIndex];
  66.             }
  67.           }
  68.  
  69.           // Store search expression keyed by longest sub-expression
  70.           //
  71.           ExpressionEntry = ExpressionHash[LongestWordExpression];
  72.           if (typeof ExpressionEntry == "undefined")
  73.           {
  74.             ExpressionEntry = new WWHHighlightWords_ExpressionEntry_Object();
  75.             ExpressionHash[LongestWordExpression] = ExpressionEntry;
  76.           }
  77.           Expression = WWHStringUtilities_WordToRegExpWithSpacePattern(WordList[Index]);
  78.           ExpressionEntry.mExpressions[ExpressionEntry.mExpressions.length] = new RegExp(Expression, "i");
  79.         }
  80.       }
  81.  
  82.       // Search document based on longest sub-expressions
  83.       //
  84.       for (LongestWordExpression in ExpressionHash)
  85.       {
  86.         NewHighlightedWords = new Array();
  87.  
  88.         TextRange = WWHFrame.WWHContentFrame.WWHDocumentFrame.document.body.createTextRange();
  89.         TextRange.collapse();
  90.         while (TextRange.findText(LongestWordExpression, 1))
  91.         {
  92.           TextRange.expand("word");
  93.           ExpressionEntry = ExpressionHash[LongestWordExpression];
  94.  
  95.           // Check word against search expression
  96.           //
  97.           bMatchFound = false;
  98.           MaxExpressionIndex = ExpressionEntry.mExpressions.length;
  99.           ExpressionIndex = 0;
  100.           while (( ! bMatchFound) &&
  101.                  (ExpressionIndex < MaxExpressionIndex))
  102.           {
  103.             if (ExpressionEntry.mExpressions[ExpressionIndex].test(TextRange.htmlText))
  104.             {
  105.               // Highlight text if not processed already
  106.               //
  107.               if (typeof HighlightedWords[TextRange.htmlText] == "undefined")
  108.               {
  109.                 NewHighlightedWords[NewHighlightedWords.length] = TextRange.htmlText;
  110.  
  111.                 TextRange.pasteHTML("<span style='background: " + WWHFrame.WWHHelp.mSettings.mHighlightingBackgroundColor + " ; color: " + WWHFrame.WWHHelp.mSettings.mHighlightingForegroundColor + "'>" + TextRange.htmlText + "</span>");
  112.  
  113.                 if (bFirstMatch)
  114.                 {
  115.                   TextRange.scrollIntoView();
  116.  
  117.                   bFirstMatch = false;
  118.                 }
  119.  
  120.                 bMatchFound = true;
  121.               }
  122.             }
  123.  
  124.             ExpressionIndex++;
  125.           }
  126.  
  127.           TextRange.collapse(false);
  128.         }
  129.  
  130.         // Add highlighted words to hash
  131.         //
  132.         for (MaxIndex = NewHighlightedWords.length, Index = 0 ; Index < MaxIndex ; Index++)
  133.         {
  134.           HighlightedWords[NewHighlightedWords[Index]] = true;
  135.         }
  136.       }
  137.     }
  138.   }
  139.  
  140.   // Highlight words only once
  141.   //
  142.   this.mWords = null;
  143. }
  144.  
  145. function  WWHHighlightWords_ExpressionHash_Object()
  146. {
  147. }
  148.  
  149. function  WWHHighlightWords_ExpressionEntry_Object()
  150. {
  151.   this.mExpressions = new Array();
  152. }
  153.  
  154. function  WWHHighlightWords_HighlightedWords_Object()
  155. {
  156. }
  157.