home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 97 / CD-ROM 97 / CD-ROM 97.iso / internet / ghostzilla / ghsetup.exe / chrome / comm.jar / content / communicator / findUtils.js < prev    next >
Encoding:
JavaScript  |  2002-04-10  |  5.0 KB  |  115 lines

  1. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: NPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Netscape Public License
  6.  * Version 1.1 (the "License"); you may not use this file except in
  7.  * compliance with the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/NPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is mozilla.org code.
  16.  *
  17.  * The Initial Developer of the Original Code is 
  18.  * Netscape Communications Corporation.
  19.  * Portions created by the Initial Developer are Copyright (C) 1998
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *   Simon Fraser <sfraser@netscape.com>
  24.  *   Dean Tessman <dean_tessman@hotmail.com>
  25.  *
  26.  * Alternatively, the contents of this file may be used under the terms of
  27.  * either the GNU General Public License Version 2 or later (the "GPL"), or 
  28.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  29.  * in which case the provisions of the GPL or the LGPL are applicable instead
  30.  * of those above. If you wish to allow use of your version of this file only
  31.  * under the terms of either the GPL or the LGPL, and not to allow others to
  32.  * use your version of this file under the terms of the NPL, indicate your
  33.  * decision by deleting the provisions above and replace them with the notice
  34.  * and other provisions required by the GPL or the LGPL. If you do not delete
  35.  * the provisions above, a recipient may use your version of this file under
  36.  * the terms of any one of the NPL, the GPL or the LGPL.
  37.  *
  38.  * ***** END LICENSE BLOCK ***** */
  39.  
  40. var gPromptService;
  41. var gFindBundle;
  42.  
  43. // browser is the <browser> element
  44. // rootSearchWindow is the window to constrain the search to (normally window._content)
  45. // startSearchWindow is the frame to start searching (can be, and normally, rootSearchWindow)
  46. function findInPage(browser, rootSearchWindow, startSearchWindow)
  47. {
  48.   var findInst = browser.webBrowserFind;
  49.   // set up the find to search the focussedWindow, bounded by the content window.
  50.   var findInFrames = findInst.QueryInterface(Components.interfaces.nsIWebBrowserFindInFrames);
  51.   findInFrames.rootSearchFrame = rootSearchWindow;
  52.   findInFrames.currentSearchFrame = startSearchWindow;
  53.  
  54.   // always search in frames for now. We could add a checkbox to the dialog for this.
  55.   findInst.searchFrames = true;
  56.   
  57.   // is the dialog up already?
  58.   if ("findDialog" in window && window.findDialog)
  59.     window.findDialog.focus();
  60.   else
  61.     window.findDialog = window.openDialog("chrome://global/content/finddialog.xul", "_blank", "chrome,resizable=no,dependent=yes", findInst);
  62. }
  63.  
  64. function findAgainInPage(browser, rootSearchWindow, startSearchWindow)
  65. {
  66.   if ("findDialog" in window && window.findDialog)
  67.     window.findDialog.focus();
  68.   else
  69.   {
  70.     var findInst = browser.webBrowserFind;
  71.     // set up the find to search the focussedWindow, bounded by the content window.
  72.     var findInFrames = findInst.QueryInterface(Components.interfaces.nsIWebBrowserFindInFrames);
  73.     findInFrames.rootSearchFrame = rootSearchWindow;
  74.     findInFrames.currentSearchFrame = startSearchWindow;
  75.  
  76.     // always search in frames for now. We could add a checkbox to the dialog for this.
  77.     findInst.searchFrames = true;
  78.  
  79.     // get the find service, which stores global find state, and init the
  80.     // nsIWebBrowser find with it. We don't assume that there was a previous
  81.     // Find that set this up.
  82.     var findService = Components.classes["@mozilla.org/find/find_service;1"]
  83.                            .getService(Components.interfaces.nsIFindService);
  84.     findInst.searchString  = findService.searchString;
  85.     findInst.matchCase     = findService.matchCase;
  86.     findInst.wrapFind      = findService.wrapFind;
  87.     findInst.entireWord    = findService.entireWord;
  88.     findInst.findBackwards = findService.findBackwards;
  89.  
  90.     var found = false;
  91.     if (findInst.searchString.length == 0)
  92.       // no previous find text
  93.       return findInPage(browser, rootSearchWindow, startSearchWindow);
  94.  
  95.     found = findInst.findNext();
  96.     if (!found) {
  97.       if (!gPromptService)
  98.         gPromptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService()
  99.                                    .QueryInterface(Components.interfaces.nsIPromptService);                                     
  100.       if (!gFindBundle)
  101.         gFindBundle = document.getElementById("findBundle");
  102.           
  103.       gPromptService.alert(window, gFindBundle.getString("notFoundTitle"), gFindBundle.getString("notFoundWarning"));
  104.     }      
  105.   }
  106. }
  107.  
  108. function canFindAgainInPage()
  109. {
  110.     var findService = Components.classes["@mozilla.org/find/find_service;1"]
  111.                            .getService(Components.interfaces.nsIFindService);
  112.     return (findService.searchString.length > 0);
  113. }
  114.  
  115.