home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 97 / CD-ROM 97 / CD-ROM 97.iso / internet / ghostzilla / ghsetup.exe / chrome / comm.jar / content / communicator / tasksOverlay.js < prev    next >
Encoding:
JavaScript  |  2002-04-10  |  6.6 KB  |  196 lines

  1. /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: NPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Netscape Public License
  6.  * Version 1.1 (the "License"); you may not use this file except in
  7.  * compliance with the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/NPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is mozilla.org code.
  16.  *
  17.  * The Initial Developer of the Original Code is 
  18.  * Netscape Communications Corporation.
  19.  * Portions created by the Initial Developer are Copyright (C) 1998
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *  Peter Annema <disttsc@bart.nl>
  24.  *
  25.  * Alternatively, the contents of this file may be used under the terms of
  26.  * either the GNU General Public License Version 2 or later (the "GPL"), or 
  27.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28.  * in which case the provisions of the GPL or the LGPL are applicable instead
  29.  * of those above. If you wish to allow use of your version of this file only
  30.  * under the terms of either the GPL or the LGPL, and not to allow others to
  31.  * use your version of this file under the terms of the NPL, indicate your
  32.  * decision by deleting the provisions above and replace them with the notice
  33.  * and other provisions required by the GPL or the LGPL. If you do not delete
  34.  * the provisions above, a recipient may use your version of this file under
  35.  * the terms of any one of the NPL, the GPL or the LGPL.
  36.  *
  37.  * ***** END LICENSE BLOCK ***** */
  38.  
  39. function toNavigator()
  40. {
  41.   if (!CycleWindow("navigator:browser"))
  42.     OpenBrowserWindow();
  43. }
  44.  
  45. function toDownloadManager()
  46. {
  47.   var dlmgr = Components.classes['@mozilla.org/download-manager;1'].getService();
  48.   dlmgr = dlmgr.QueryInterface(Components.interfaces.nsIDownloadManager);
  49.   dlmgr.open(window);
  50. }
  51.   
  52. function toJavaScriptConsole()
  53. {
  54.     toOpenWindowByType("global:console", "chrome://global/content/console.xul");
  55. }
  56.  
  57. function javaItemEnabling()
  58. {
  59.     var element = document.getElementById("java");
  60.     if (navigator.javaEnabled())
  61.       element.removeAttribute("disabled");
  62.     else
  63.       element.setAttribute("disabled", "true");
  64. }
  65.             
  66. function toJavaConsole()
  67. {
  68.     var jvmMgr = Components.classes['@mozilla.org/oji/jvm-mgr;1']
  69.                             .getService(Components.interfaces.nsIJVMManager)
  70.     jvmMgr.showJavaConsole();
  71. }
  72.  
  73. function toOpenWindowByType( inType, uri )
  74. {
  75.     var windowManager = Components.classes['@mozilla.org/rdf/datasource;1?name=window-mediator'].getService();
  76.  
  77.     var    windowManagerInterface = windowManager.QueryInterface( Components.interfaces.nsIWindowMediator);
  78.  
  79.     var topWindow = windowManagerInterface.getMostRecentWindow( inType );
  80.     
  81.     if ( topWindow )
  82.         topWindow.focus();
  83.     else
  84.         window.open(uri, "_blank", "chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar");
  85. }
  86.  
  87.  
  88. function OpenBrowserWindow()
  89. {
  90.   var charsetArg = new String();
  91.   var handler = Components.classes['@mozilla.org/commandlinehandler/general-startup;1?type=browser'];
  92.   handler = handler.getService();
  93.   handler = handler.QueryInterface(Components.interfaces.nsICmdLineHandler);
  94.   var startpage = handler.defaultArgs;
  95.   var url = handler.chromeUrlForTask;
  96.   var wintype = document.firstChild.getAttribute('windowtype');
  97.  
  98.   // if and only if the current window is a browser window and it has a document with a character
  99.   // set, then extract the current charset menu setting from the current document and use it to
  100.   // initialize the new browser window...
  101.   if (window && (wintype == "navigator:browser") && window._content && window._content.document)
  102.   {
  103.     var DocCharset = window._content.document.characterSet;
  104.     charsetArg = "charset="+DocCharset;
  105.  
  106.     //we should "inherit" the charset menu setting in a new window
  107.     window.openDialog(url, "_blank", "chrome,all,dialog=no", startpage, charsetArg);
  108.   }
  109.   else // forget about the charset information.
  110.   {
  111.     window.openDialog(url, "_blank", "chrome,all,dialog=no", startpage);
  112.   }
  113. }
  114.  
  115. function CycleWindow( aType )
  116. {
  117.   var windowManager = Components.classes['@mozilla.org/rdf/datasource;1?name=window-mediator'].getService();
  118.   var windowManagerInterface = windowManager.QueryInterface( Components.interfaces.nsIWindowMediator);
  119.  
  120.   var topWindowOfType = windowManagerInterface.getMostRecentWindow( aType );
  121.   var topWindow = windowManagerInterface.getMostRecentWindow( null );
  122.  
  123.   if ( topWindowOfType == null )
  124.     return null;
  125.  
  126.   if ( topWindowOfType != topWindow ) {
  127.     topWindowOfType.focus();
  128.     return topWindowOfType;
  129.   }
  130.  
  131.   var enumerator = windowManagerInterface.getEnumerator( aType );
  132.   var firstWindow = windowManagerInterface.convertISupportsToDOMWindow(enumerator.getNext());
  133.   var iWindow = firstWindow;
  134.   while (iWindow != topWindow && enumerator.hasMoreElements())
  135.     iWindow = windowManagerInterface.convertISupportsToDOMWindow(enumerator.getNext());
  136.  
  137.   if (enumerator.hasMoreElements()) {
  138.     iWindow = windowManagerInterface.convertISupportsToDOMWindow(enumerator.getNext());
  139.     iWindow.focus();
  140.     return iWindow;
  141.   }
  142.  
  143.   if (firstWindow == topWindow) // Only one window
  144.     return null;
  145.  
  146.   firstWindow.focus();
  147.   return firstWindow;
  148. }
  149.  
  150. function ShowWindowFromResource( node )
  151. {
  152.     var windowManager = Components.classes['@mozilla.org/rdf/datasource;1?name=window-mediator'].getService();
  153.     var    windowManagerInterface = windowManager.QueryInterface( Components.interfaces.nsIWindowMediator);
  154.     
  155.     var desiredWindow = null;
  156.     var url = node.getAttribute('id');
  157.     desiredWindow = windowManagerInterface.getWindowForResource( url );
  158.     if ( desiredWindow )
  159.     {
  160.         desiredWindow.focus();
  161.     }
  162. }
  163.  
  164. function OpenTaskURL( inURL )
  165. {
  166.     
  167.     window.open( inURL );
  168. }
  169.  
  170. function ShowUpdateFromResource( node )
  171. {
  172.     var url = node.getAttribute('url');
  173.         // hack until I get a new interface on xpiflash to do a 
  174.         // look up on the name/url pair.
  175.     OpenTaskURL( "http://www.mozilla.org/binaries.html");
  176. }
  177.  
  178. function checkFocusedWindow()
  179. {
  180.   var windowManager = Components.classes['@mozilla.org/rdf/datasource;1?name=window-mediator'].getService();
  181.   var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
  182.  
  183.   var sep = document.getElementById("sep-window-list");
  184.   // Using double parens to avoid warning
  185.   while ((sep = sep.nextSibling)) {
  186.     var url = sep.getAttribute('id');
  187.     var win = windowManagerInterface.getWindowForResource(url);
  188.     if (win == window) {
  189.       sep.setAttribute("checked", "true");
  190.       break;
  191.     }
  192.   }
  193. }
  194.  
  195.  
  196.