home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2005 October / Gamestar_77_2005-10_dvd.iso / Programy / nsb-install-8-0.exe / chrome / help.jar / content / browser / help / contextHelp.js < prev    next >
Encoding:
Text File  |  2005-07-29  |  5.5 KB  |  147 lines

  1. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  * The contents of this file are subject to the Netscape Public
  3.  * License Version 1.1 (the "License"); you may not use this file
  4.  * except in compliance with the License. You may obtain a copy of
  5.  * the License at http://www.mozilla.org/NPL/
  6.  * 
  7.  * Software distributed under the License is distributed on an "AS
  8.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9.  * implied. See the License for the specific language governing
  10.  * rights and limitations under the License.
  11.  * 
  12.  * The Original Code is Mozilla Communicator client code, released
  13.  * March 31, 1998.
  14.  * 
  15.  * The Initial Developer of the Original Code is Netscape
  16.  * Communications Corporation. Portions created by Netscape are
  17.  * Copyright (C) 1998-1999 Netscape Communications Corporation. All
  18.  * Rights Reserved.
  19.  *
  20.  * Contributor(s):
  21.  *   R.J. Keller <rlk@trfenv.com>
  22.  */
  23.  
  24. const MOZILLA_CONTENT_PACK = "chrome://help/locale/mozillahelp.rdf";
  25. //Set the default content pack to the Mozilla content pack. Use the
  26. //setHelpFileURI function to set this value.
  27. var helpFileURI = MOZILLA_CONTENT_PACK;
  28.  
  29. // openHelp - Opens up the Mozilla Help Viewer with the specified
  30. //    topic and content pack.
  31. // see http://www.mozilla.org/projects/help-viewer/content_packs.html
  32. function openHelp(topic, contentPack)
  33. {
  34.     if (topic == "new_web_cert")
  35.     {
  36.         return;
  37.     }
  38.     // dump ("Calling openHelp with topic of " + topic + " \t");
  39.     // showStack();
  40.     
  41.     // MERC: SL - AIM help is in own window STEVO - So does ICQ :)
  42. //   if (topic != "im" && topic != "icq") {
  43.       var prefService = Components.classes["@mozilla.org/preferences-service;1"]
  44.                               .getService(Components.interfaces.nsIPrefBranch);
  45.       if (prefService.getPrefType("browser.help.url")) {
  46.  
  47.          var helpURL = prefService.getCharPref("browser.help.url");
  48.          
  49.          if (topic == "im") {
  50.             var aimHelpUrl = prefService.getPrefType("aim.help.url");
  51.             if (aimHelpUrl && aimHelpUrl.length > 6)
  52.                helpURL = prefService.getCharPref("aim.help.url");
  53.             else 
  54.                helpURL = "http://browser.netscape.com/ns8/help/im_help.jsp";
  55.          }     
  56.  
  57.          if (topic == "icq") {
  58.             var icqHelpUrl = prefService.getPrefType("icq.help.url");
  59.             if (icqHelpUrl && icqHelpUrl.length > 6)            
  60.                helpURL = prefService.getCharPref("icq.help.url");
  61.          }                         
  62.                     
  63.             try {       
  64.               var newTab = gBrowser.addTabAt(helpURL);
  65.               if (!prefService.getBoolPref("browser.tabs.loadInBackground"))
  66.                gBrowser.selectedTab = newTab;
  67.               return;
  68.             } catch (ex) {
  69.                         // This could be because gBrowser does not exist
  70.               }
  71.  
  72.               // this may be called from a dialog box...
  73.               try {
  74.                 var newTab = opener.window.gBrowser.addTabAt(helpURL);
  75.                 if (!prefService.getBoolPref("browser.tabs.loadInBackground"))
  76.                     opener.window.gBrowser.selectedTab = newTab;
  77.                 return;
  78.                     } catch (ex) {
  79.                         // opener.window is probably not right
  80.                     }             
  81.      
  82.                     // Probably called from sidebar
  83.                     try {              
  84.                 // We need to find the top window (gBrowser does not exist)                
  85.                       var browser = top.document.getElementById('content');                   
  86.               var newTab = browser.addTabAt(helpURL);
  87.               if (!prefService.getBoolPref("browser.tabs.loadInBackground"))
  88.                browser.selectedTab = newTab;
  89.             return;
  90.               } catch (ex) {
  91.                   // Ok so top.document does not exist! I give up!
  92.                   return;
  93.               }
  94.               
  95.       }
  96. //   }
  97.   //cp is the content pack to use in this function. If the contentPack
  98.   //parameter was set, we will use that content pack. If not, we will
  99.   //use the default content pack set by setHelpFileURI().
  100.   var cp = contentPack || helpFileURI;
  101.  
  102.   // Try to find previously opened help.
  103.   var topWindow = locateHelpWindow(cp);
  104.  
  105.   if ( topWindow ) {
  106.     // Open topic in existing window.
  107.     topWindow.focus();
  108.     topWindow.displayTopic(topic);
  109.   } else {
  110.     // Open topic in new window.
  111.     const params = Components.classes["@mozilla.org/embedcomp/dialogparam;1"]
  112.                              .createInstance(Components.interfaces.nsIDialogParamBlock);
  113.     params.SetNumberStrings(2);
  114.     params.SetString(0, cp);
  115.     params.SetString(1, topic);
  116.     const ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
  117.                          .getService(Components.interfaces.nsIWindowWatcher);
  118.     dump('ABOUT TO OPEN HELP WINDOW... !\n');
  119.     ww.openWindow(null, "chrome://help/content/help.xul", "_blank", "chrome,all,alwaysRaised,dialog=no", params);
  120.   }
  121. }
  122.  
  123. //setHelpFileURI - Sets the default content pack to use in the Help Viewer
  124. function setHelpFileURI(rdfURI) {
  125.   helpFileURI = rdfURI; 
  126. }
  127.  
  128. // Locate mozilla:help window (if any) opened for this help file uri.
  129. function locateHelpWindow(helpFileURI) {
  130.   const windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1']
  131.                                   .getService(Components.interfaces.nsIWindowMediator);
  132.   var iterator = windowManager.getEnumerator("mozilla:help");
  133.   var topWindow = null;
  134.   var currentWindow;
  135.  
  136.   // Loop through the help windows looking for one with the
  137.   // current Help Content Pack loaded.
  138.   while (iterator.hasMoreElements()) {
  139.     currentWindow = iterator.getNext();
  140.     if (currentWindow.getHelpFileURI() == helpFileURI) {
  141.       topWindow = currentWindow;
  142.       break;  
  143.     }  
  144.   }
  145.   return topWindow;
  146. }
  147.