home *** CD-ROM | disk | FTP | other *** search
/ PC World 2006 December / PCWorld_2006-12_cd.bin / komunikace / netscape / nsb-install-8-1-2.exe / chrome / browser.jar / content / browser / openLocation.js < prev    next >
Text File  |  2006-01-06  |  4KB  |  120 lines

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