home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / firefox-3.0.14 / chrome / browser.jar / content / browser / openLocation.js < prev    next >
Encoding:
JavaScript  |  2007-06-14  |  3.7 KB  |  119 lines

  1. //@line 41 "/build/buildd/firefox-3.0-3.0.14+build2+nobinonly/build-tree/mozilla/browser/base/content/openLocation.js"
  2.  
  3. var browser;
  4. var dialog = {};
  5. var pref = null;
  6. try {
  7.   pref = Components.classes["@mozilla.org/preferences-service;1"]
  8.                    .getService(Components.interfaces.nsIPrefBranch);
  9. } catch (ex) {
  10.   // not critical, remain silent
  11. }
  12.  
  13. function onLoad()
  14. {
  15.   dialog.input         = document.getElementById("dialog.input");
  16.   dialog.open          = document.documentElement.getButton("accept");
  17.   dialog.openWhereList = document.getElementById("openWhereList");
  18.   dialog.openTopWindow = document.getElementById("currentWindow");
  19.   dialog.bundle        = document.getElementById("openLocationBundle");
  20.  
  21.   if ("arguments" in window && window.arguments.length >= 1)
  22.     browser = window.arguments[0];
  23.    
  24.   dialog.openWhereList.selectedItem = dialog.openTopWindow;
  25.  
  26.   if (pref) {
  27.     try {
  28.       var useAutoFill = pref.getBoolPref("browser.urlbar.autoFill");
  29.       if (useAutoFill)
  30.         dialog.input.setAttribute("completedefaultindex", "true");
  31.     } catch (ex) {}
  32.  
  33.     try {
  34.       var value = pref.getIntPref("general.open_location.last_window_choice");
  35.       var element = dialog.openWhereList.getElementsByAttribute("value", value)[0];
  36.       if (element)
  37.         dialog.openWhereList.selectedItem = element;
  38.       dialog.input.value = pref.getComplexValue("general.open_location.last_url",
  39.                                                 Components.interfaces.nsISupportsString).data;
  40.     }
  41.     catch(ex) {
  42.     }
  43.     if (dialog.input.value)
  44.       dialog.input.select(); // XXX should probably be done automatically
  45.   }
  46.  
  47.   doEnabling();
  48. }
  49.  
  50. function doEnabling()
  51. {
  52.     dialog.open.disabled = !dialog.input.value;
  53. }
  54.  
  55. function open()
  56. {
  57.   var url;
  58.   var postData = {};
  59.   if (browser)
  60.     url = browser.getShortcutOrURI(dialog.input.value, postData);
  61.   else
  62.     url = dialog.input.value;
  63.  
  64.   try {
  65.     // Whichever target we use for the load, we allow third-party services to
  66.     // fixup the URI
  67.     switch (dialog.openWhereList.value) {
  68.       case "0":
  69.         browser.loadURI(url, null, postData.value, true);
  70.         break;
  71.       case "1":
  72.         window.opener.delayedOpenWindow(getBrowserURL(), "all,dialog=no",
  73.                                         url, postData.value, null, null, true);
  74.         break;
  75.       case "3":
  76.         browser.delayedOpenTab(url, null, null, postData.value, true);
  77.         break;
  78.     }
  79.   }
  80.   catch(exception) {
  81.   }
  82.  
  83.   if (pref) {
  84.     var str = Components.classes["@mozilla.org/supports-string;1"]
  85.                         .createInstance(Components.interfaces.nsISupportsString);
  86.     str.data = dialog.input.value;
  87.     pref.setComplexValue("general.open_location.last_url",
  88.                          Components.interfaces.nsISupportsString, str);
  89.     pref.setIntPref("general.open_location.last_window_choice", dialog.openWhereList.value);
  90.   }
  91.  
  92.   // Delay closing slightly to avoid timing bug on Linux.
  93.   window.close();
  94.   return false;
  95. }
  96.  
  97. function createInstance(contractid, iidName)
  98. {
  99.   var iid = Components.interfaces[iidName];
  100.   return Components.classes[contractid].createInstance(iid);
  101. }
  102.  
  103. const nsIFilePicker = Components.interfaces.nsIFilePicker;
  104. function onChooseFile()
  105. {
  106.   try {
  107.     var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
  108.     fp.init(window, dialog.bundle.getString("chooseFileDialogTitle"), nsIFilePicker.modeOpen);
  109.     fp.appendFilters(nsIFilePicker.filterHTML | nsIFilePicker.filterText |
  110.                      nsIFilePicker.filterAll | nsIFilePicker.filterImages | nsIFilePicker.filterXML);
  111.  
  112.     if (fp.show() == nsIFilePicker.returnOK && fp.fileURL.spec && fp.fileURL.spec.length > 0)
  113.       dialog.input.value = fp.fileURL.spec;
  114.   }
  115.   catch(ex) {
  116.   }
  117.   doEnabling();
  118. }
  119.