home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / mozil06.zip / bin / chrome / toolkit.jar / content / global / finddialog.js < prev    next >
Text File  |  2001-02-14  |  5KB  |  143 lines

  1.         var finder; // Find component.
  2.         var data;   // Search context (passed as argument).
  3.         var dialog; // Quick access to document/form elements.
  4.  
  5.         function string2Bool( value )
  6.         {
  7.             return value != "false";
  8.         }
  9.  
  10.         function bool2String( value )
  11.         {
  12.             if ( value ) {
  13.                 return "true";
  14.             } else {
  15.                 return "false";
  16.             }
  17.         }
  18.  
  19.         function initDialog()
  20.         {
  21.             // Create dialog object and initialize.
  22.             dialog = new Object;
  23.             dialog.findKey         = document.getElementById("dialog.findKey");
  24.             dialog.caseSensitive   = document.getElementById("dialog.caseSensitive");
  25.             dialog.wrap            = document.getElementById("dialog.wrap");
  26.             dialog.searchBackwards = document.getElementById("dialog.searchBackwards");
  27.             dialog.find            = document.getElementById("ok");
  28.             dialog.cancel          = document.getElementById("cancel");
  29.             dialog.enabled         = false;
  30.         }
  31.  
  32.         function loadDialog()
  33.         {
  34.             // Set initial dialog field contents.
  35.             dialog.findKey.setAttribute( "value", data.searchString );
  36.  
  37.             if ( data.caseSensitive ) {
  38.                 dialog.caseSensitive.setAttribute( "checked", "" );
  39.             } else {
  40.                 dialog.caseSensitive.removeAttribute( "checked" );
  41.             }
  42.  
  43.             if ( data.wrapSearch ) {
  44.                 dialog.wrap.setAttribute( "checked", "" );
  45.             } else {
  46.                 dialog.wrap.removeAttribute( "checked" );
  47.             }
  48.  
  49.             if ( data.searchBackwards ) {
  50.                 dialog.searchBackwards.setAttribute( "checked", "" );
  51.             } else {
  52.                 dialog.searchBackwards.removeAttribute( "checked" );
  53.             }
  54.             
  55.             // disable the OK button if no text
  56.             if (dialog.findKey.getAttribute("value") == "") {
  57.                 dialog.find.setAttribute("disabled", "true");
  58.                }
  59.         dialog.findKey.focus();
  60.         }
  61.  
  62.         function loadData()
  63.         {
  64.             // Set data attributes per user input.
  65.             data.searchString = dialog.findKey.value;
  66.             data.caseSensitive = dialog.caseSensitive.checked;
  67.             data.wrapSearch = dialog.wrap.checked;
  68.             data.searchBackwards = dialog.searchBackwards.checked;
  69.         }
  70.  
  71.         function onLoad()
  72.         {
  73.             // Init dialog.
  74.             initDialog();
  75.  
  76.             // Get find component.
  77.             finder = Components.classes[ "@mozilla.org/appshell/component/find;1" ].getService();
  78.             finder = finder.QueryInterface( Components.interfaces.nsIFindComponent );
  79.             if ( !finder ) {
  80.                 alert( "Error accessing find component\n" );
  81.                 window.close();
  82.                 return;
  83.             }
  84.  
  85.             // change OK to find
  86.             dialog.find.setAttribute("value", document.getElementById("fBLT").getAttribute("value"));
  87.  
  88.             // setup the dialogOverlay.xul button handlers
  89.             doSetOKCancel(onOK, onCancel);
  90.  
  91.             // Save search context.
  92.             data = window.arguments[0];
  93.  
  94.             // Tell search context about this dialog.
  95.             data.findDialog = window;
  96.  
  97.             // Fill dialog.
  98.             loadDialog();
  99.  
  100.             // Give focus to search text field.
  101.             dialog.findKey.focus();
  102.         }
  103.  
  104.         function onUnload() {
  105.             // Disconnect context from this dialog.
  106.             data.findDialog = null;
  107.         }
  108.  
  109.         function onOK()
  110.         {
  111.             // Transfer dialog contents to data elements.
  112.             loadData();
  113.  
  114.             // Search.
  115.             finder.FindNext( data );
  116.  
  117.             // don't close the window
  118.             return false;
  119.         }
  120.  
  121.         function onCancel()
  122.         {
  123.             // Close the window.
  124.             return true;
  125.         }
  126.  
  127.         function onTyping()
  128.         {
  129.                 if ( dialog.enabled ) {
  130.                     // Disable OK if they delete all the text.
  131.                     if ( dialog.findKey.value == "" ) {
  132.                         dialog.enabled = false;
  133.                         dialog.find.setAttribute("disabled", "true");
  134.                     }
  135.                 } else {
  136.                     // Enable OK once the user types something.
  137.                     if ( dialog.findKey.value != "" ) {
  138.                         dialog.enabled = true;
  139.                         dialog.find.removeAttribute("disabled");
  140.                     }
  141.                 }
  142.         }
  143.