home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 February / PCWorld_2007-02_cd.bin / komunikace / netscape / nsb-install-8-1-2.exe / chrome / toolkit.jar / content / global / findUtils.js < prev    next >
Text File  |  2006-01-06  |  4KB  |  133 lines

  1. var gPromptService;
  2. var gFindBundle;
  3.  
  4. function nsFindInstData() {}
  5. nsFindInstData.prototype =
  6. {
  7.   // set the next three attributes on your object to override the defaults
  8.   browser : null,
  9.  
  10.   get rootSearchWindow() { return this._root || this.window.content; },
  11.   set rootSearchWindow(val) { this._root = val; },
  12.  
  13.   get currentSearchWindow() {
  14.     if (this._current)
  15.       return this._current;
  16.  
  17.     var focusedWindow = this.window.document.commandDispatcher.focusedWindow;
  18.     if (!focusedWindow || focusedWindow == this.window)
  19.       focusedWindow = this.window.content;
  20.  
  21.     return focusedWindow;
  22.   },
  23.   set currentSearchWindow(val) { this._current = val; },
  24.  
  25.   get webBrowserFind() { return this.browser.webBrowserFind; },
  26.  
  27.   init : function() {
  28.     var findInst = this.webBrowserFind;
  29.     // set up the find to search the focussedWindow, bounded by the content window.
  30.     var findInFrames = findInst.QueryInterface(Components.interfaces.nsIWebBrowserFindInFrames);
  31.     findInFrames.rootSearchFrame = this.rootSearchWindow;
  32.     findInFrames.currentSearchFrame = this.currentSearchWindow;
  33.  
  34.     // always search in frames for now. We could add a checkbox to the dialog for this.
  35.     findInst.searchFrames = true;
  36.   },
  37.  
  38.   window : window,
  39.   _root : null,
  40.   _current : null
  41. }
  42.  
  43. // browser is the <browser> element
  44. // rootSearchWindow is the window to constrain the search to (normally window._content)
  45. // currentSearchWindow is the frame to start searching (can be, and normally, rootSearchWindow)
  46. function findInPage(findInstData)
  47. {
  48.   // is the dialog up already?
  49.   if ("findDialog" in window && window.findDialog)
  50.     window.findDialog.focus();
  51.   else
  52.   {
  53.     findInstData.init();
  54.     window.findDialog = window.openDialog("chrome://global/content/finddialog.xul", "_blank", "chrome,resizable=no,dependent=yes", findInstData);
  55.   }
  56. }
  57.  
  58. function findAgainInPage(findInstData, reverse)
  59. {
  60.   if ("findDialog" in window && window.findDialog)
  61.     window.findDialog.focus();
  62.   else
  63.   {
  64.     // get the find service, which stores global find state, and init the
  65.     // nsIWebBrowser find with it. We don't assume that there was a previous
  66.     // Find that set this up.
  67.     var findService = Components.classes["@mozilla.org/find/find_service;1"]
  68.                            .getService(Components.interfaces.nsIFindService);
  69.  
  70.     var searchString = findService.searchString;
  71.     if (searchString.length == 0) {
  72.       // no previous find text
  73.       findInPage(findInstData);
  74.       return;
  75.     }
  76.  
  77.     findInstData.init();
  78.  
  79.      //JA check if HPDoc is active
  80.      var hpDoc;
  81.      try{
  82.  
  83. //         dump("\nJA this = "+this+"\n");
  84. //         dump("reverse = "+reverse+"\n");
  85. //         dump("JA findInstData.browser = "+findInstData.browser+"\n");
  86. //         dump("JA findInstData.browser.contentDocument = "+findInstData.browser.contentDocument+"\n\n");
  87.  
  88.          hpDoc = findInstData.browser.contentDocument.QueryInterface(Components.interfaces.nsIHTMLPluginDocument);
  89.      }catch(e){}
  90.  
  91.      var found;
  92.      if(hpDoc)
  93.      {
  94. //         dump("\n\n\nAttempting hpDoc.findNext()\n\n\n");
  95.         found = hpDoc.findNext();
  96.      }
  97.      else//default
  98.      {
  99.          var findInst = findInstData.webBrowserFind;
  100.          findInst.searchString  = searchString;
  101.          findInst.matchCase     = findService.matchCase;
  102.          findInst.wrapFind      = findService.wrapFind;
  103.          findInst.entireWord    = findService.entireWord;
  104.          findInst.findBackwards = findService.findBackwards ^ reverse;
  105.          found = findInst.findNext();
  106.          // Reset to normal value, otherwise setting can get changed in find dialog
  107.          findInst.findBackwards = findService.findBackwards;
  108.      }
  109.  
  110.  
  111.     if (!found) {
  112.       if (!gPromptService)
  113.         gPromptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService()
  114.                                    .QueryInterface(Components.interfaces.nsIPromptService);
  115.       if (!gFindBundle)
  116.         gFindBundle = document.getElementById("findBundle");
  117.  
  118.       gPromptService.alert(window, gFindBundle.getString("notFoundTitle"), gFindBundle.getString("notFoundWarning"));
  119.     }
  120.  
  121.     // Reset to normal value, otherwise setting can get changed in find dialog
  122.     findInst.findBackwards = findService.findBackwards;
  123.   }
  124. }
  125.  
  126. function canFindAgainInPage()
  127. {
  128.     var findService = Components.classes["@mozilla.org/find/find_service;1"]
  129.                            .getService(Components.interfaces.nsIFindService);
  130.     return (findService.searchString.length > 0);
  131. }
  132.  
  133.