home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 January / 01_02.iso / software / netscape62win / browser.xpi / bin / chrome / toolkit.jar / content / global / finddialog.js < prev    next >
Encoding:
JavaScript  |  2001-09-30  |  4.4 KB  |  138 lines

  1. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public
  4.  * License Version 1.1 (the "License"); you may not use this file
  5.  * except in compliance with the License. You may obtain a copy of
  6.  * the License at http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the License is distributed on an "AS
  9.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10.  * implied. See the License for the specific language governing
  11.  * rights and limitations under the License.
  12.  *
  13.  * The Original Code is Mozilla Communicator client code, released March
  14.  * 31, 1998.
  15.  *
  16.  * The Initial Developer of the Original Code is Netscape Communications
  17.  * Corporation. Portions created by Netscape are
  18.  * Copyright (C) 1998 Netscape Communications Corporation. All
  19.  * Rights Reserved.
  20.  *
  21.  * Contributor(s): Alec Flett       <alecf@netscape.com>
  22.  *                 Bill Law         <law@netscape.com>
  23.  *                 Blake Ross       <blakeross@telocity.com>
  24.  *                 Matt Fisher      <matt@netscape.com>
  25.  *                 Simon Fraser     <sfraser@netscape.com>
  26.  *                 Stuart Parmenter <pavlov@netscape.com>
  27.  */
  28.  
  29. var dialog;     // Quick access to document/form elements.
  30. var gFindInst;   // nsIWebBrowserFind that we're going to use
  31.  
  32. function initDialogObject()
  33. {
  34.   // Create dialog object and initialize.
  35.   dialog = new Object;
  36.   dialog.findKey         = document.getElementById("dialog.findKey");
  37.   dialog.caseSensitive   = document.getElementById("dialog.caseSensitive");
  38.   dialog.wrap            = document.getElementById("dialog.wrap");
  39.   dialog.searchBackwards = document.getElementById("dialog.searchBackwards");
  40.   dialog.find            = document.getElementById("ok");
  41.   dialog.bundle          = null;
  42.  
  43.   // Move dialog to center, if it not been shown before
  44.   var windowElement = document.getElementById("findDialog");
  45.   if (!windowElement.hasAttribute("screenX") || !windowElement.hasAttribute("screenY"))
  46.   {
  47.     sizeToContent();
  48.     moveToAlertPosition();
  49.   }
  50. }
  51.  
  52. function fillDialog()
  53. {
  54.   // get the find service, which stores global find state
  55.   var findService = Components.classes["@mozilla.org/find/find_service;1"]
  56.                          .getService(Components.interfaces.nsIFindService);
  57.   
  58.   // Set initial dialog field contents.
  59.   dialog.findKey.value           = findService.searchString;
  60.   dialog.caseSensitive.checked   = findService.matchCase;
  61.   dialog.wrap.checked            = findService.wrapFind;
  62.   dialog.searchBackwards.checked = findService.findBackwards;
  63. }
  64.  
  65. function saveFindData()
  66. {
  67.   // get the find service, which stores global find state
  68.   var findService = Components.classes["@mozilla.org/find/find_service;1"]
  69.                          .getService(Components.interfaces.nsIFindService);
  70.  
  71.   // Set data attributes per user input.
  72.   findService.searchString  = dialog.findKey.value;
  73.   findService.matchCase     = dialog.caseSensitive.checked;
  74.   findService.wrapFind      = dialog.wrap.checked;
  75.   findService.findBackwards = dialog.searchBackwards.checked;
  76. }
  77.  
  78. function onLoad()
  79. {
  80.   initDialogObject();
  81.  
  82.   // Change "OK" to "Find".
  83.   dialog.find.label = document.getElementById("fBLT").getAttribute("label");
  84.  
  85.   // Setup the dialogOverlay.xul button handlers.
  86.   doSetOKCancel(onOK, onCancel);
  87.  
  88.   // get the find instance
  89.   gFindInst = window.arguments[0];
  90.  
  91.   fillDialog();
  92.   doEnabling();
  93.  
  94.   if (dialog.findKey.value)
  95.     dialog.findKey.select();
  96.   dialog.findKey.focus();
  97. }
  98.  
  99. function onUnload()
  100. {
  101.     window.opener.findDialog = 0;
  102. }
  103.  
  104. function onOK()
  105. {
  106.   // Transfer dialog contents to the find service.
  107.   saveFindData();
  108.  
  109.   // set up the find instance
  110.   gFindInst.searchString  = dialog.findKey.value;
  111.   gFindInst.matchCase     = dialog.caseSensitive.checked;
  112.   gFindInst.wrapFind      = dialog.wrap.checked;
  113.   gFindInst.findBackwards = dialog.searchBackwards.checked;
  114.   
  115.   // Search.
  116.   var result = gFindInst.findNext();
  117.  
  118.   if (!result)
  119.   {
  120.     if (!dialog.bundle)
  121.       dialog.bundle = document.getElementById("findBundle");
  122.     window.alert(dialog.bundle.getString("notFoundWarning"));
  123.     dialog.findKey.select();
  124.     dialog.findKey.focus();
  125.   }
  126. }
  127.  
  128. function onCancel()
  129. {
  130.   // Close the window.
  131.   return true;
  132. }
  133.  
  134. function doEnabling()
  135. {
  136.   dialog.find.disabled = !dialog.findKey.value;
  137. }
  138.