michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: # Set the default content pack to the Mozilla content pack. Use the michael@0: # setHelpFileURI function to set this value. michael@0: var helpFileURI; michael@0: michael@0: # openHelp - Opens up the Mozilla Help Viewer with the specified michael@0: # topic and content pack. michael@0: # see http://www.mozilla.org/projects/help-viewer/content_packs.html michael@0: function openHelp(topic, contentPack) michael@0: { michael@0: # helpFileURI is the content pack to use in this function. If contentPack is defined, michael@0: # use that and set the helpFileURI to that value so that it will be the default. michael@0: helpFileURI = contentPack || helpFileURI; michael@0: michael@0: # Try to find previously opened help. michael@0: var topWindow = locateHelpWindow(helpFileURI); michael@0: michael@0: if ( topWindow ) { michael@0: # Open topic in existing window. michael@0: topWindow.focus(); michael@0: topWindow.displayTopic(topic); michael@0: } else { michael@0: # Open topic in new window. michael@0: const params = Components.classes["@mozilla.org/embedcomp/dialogparam;1"] michael@0: .createInstance(Components.interfaces.nsIDialogParamBlock); michael@0: params.SetNumberStrings(2); michael@0: params.SetString(0, helpFileURI); michael@0: params.SetString(1, topic); michael@0: const ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] michael@0: .getService(Components.interfaces.nsIWindowWatcher); michael@0: #ifdef XP_WIN michael@0: #define HELP_ALWAYS_RAISED_TOGGLE michael@0: #endif michael@0: #ifdef HELP_ALWAYS_RAISED_TOGGLE michael@0: ww.openWindow(null, "chrome://help/content/help.xul", "_blank", "chrome,all,alwaysRaised,dialog=no", params); michael@0: #else michael@0: ww.openWindow(null, "chrome://help/content/help.xul", "_blank", "chrome,all,dialog=no", params); michael@0: #endif michael@0: } michael@0: } michael@0: michael@0: # setHelpFileURI - Sets the default content pack to use in the Help Viewer michael@0: function setHelpFileURI(rdfURI) michael@0: { michael@0: helpFileURI = rdfURI; michael@0: } michael@0: michael@0: # Locate existing help window for this content pack. michael@0: function locateHelpWindow(contentPack) { michael@0: const windowManagerInterface = Components michael@0: .classes['@mozilla.org/appshell/window-mediator;1'].getService() michael@0: .QueryInterface(Components.interfaces.nsIWindowMediator); michael@0: const iterator = windowManagerInterface.getEnumerator("mozilla:help"); michael@0: var topWindow = null; michael@0: var aWindow; michael@0: michael@0: # Loop through help windows looking for one with selected content michael@0: # pack. michael@0: while (iterator.hasMoreElements()) { michael@0: aWindow = iterator.getNext(); michael@0: if (!aWindow.closed && aWindow.getHelpFileURI() == contentPack) { michael@0: topWindow = aWindow; michael@0: } michael@0: } michael@0: return topWindow; michael@0: }