Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
michael@0 | 1 | # This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
michael@0 | 4 | |
michael@0 | 5 | # Set the default content pack to the Mozilla content pack. Use the |
michael@0 | 6 | # setHelpFileURI function to set this value. |
michael@0 | 7 | var helpFileURI; |
michael@0 | 8 | |
michael@0 | 9 | # openHelp - Opens up the Mozilla Help Viewer with the specified |
michael@0 | 10 | # topic and content pack. |
michael@0 | 11 | # see http://www.mozilla.org/projects/help-viewer/content_packs.html |
michael@0 | 12 | function openHelp(topic, contentPack) |
michael@0 | 13 | { |
michael@0 | 14 | # helpFileURI is the content pack to use in this function. If contentPack is defined, |
michael@0 | 15 | # use that and set the helpFileURI to that value so that it will be the default. |
michael@0 | 16 | helpFileURI = contentPack || helpFileURI; |
michael@0 | 17 | |
michael@0 | 18 | # Try to find previously opened help. |
michael@0 | 19 | var topWindow = locateHelpWindow(helpFileURI); |
michael@0 | 20 | |
michael@0 | 21 | if ( topWindow ) { |
michael@0 | 22 | # Open topic in existing window. |
michael@0 | 23 | topWindow.focus(); |
michael@0 | 24 | topWindow.displayTopic(topic); |
michael@0 | 25 | } else { |
michael@0 | 26 | # Open topic in new window. |
michael@0 | 27 | const params = Components.classes["@mozilla.org/embedcomp/dialogparam;1"] |
michael@0 | 28 | .createInstance(Components.interfaces.nsIDialogParamBlock); |
michael@0 | 29 | params.SetNumberStrings(2); |
michael@0 | 30 | params.SetString(0, helpFileURI); |
michael@0 | 31 | params.SetString(1, topic); |
michael@0 | 32 | const ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] |
michael@0 | 33 | .getService(Components.interfaces.nsIWindowWatcher); |
michael@0 | 34 | #ifdef XP_WIN |
michael@0 | 35 | #define HELP_ALWAYS_RAISED_TOGGLE |
michael@0 | 36 | #endif |
michael@0 | 37 | #ifdef HELP_ALWAYS_RAISED_TOGGLE |
michael@0 | 38 | ww.openWindow(null, "chrome://help/content/help.xul", "_blank", "chrome,all,alwaysRaised,dialog=no", params); |
michael@0 | 39 | #else |
michael@0 | 40 | ww.openWindow(null, "chrome://help/content/help.xul", "_blank", "chrome,all,dialog=no", params); |
michael@0 | 41 | #endif |
michael@0 | 42 | } |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | # setHelpFileURI - Sets the default content pack to use in the Help Viewer |
michael@0 | 46 | function setHelpFileURI(rdfURI) |
michael@0 | 47 | { |
michael@0 | 48 | helpFileURI = rdfURI; |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | # Locate existing help window for this content pack. |
michael@0 | 52 | function locateHelpWindow(contentPack) { |
michael@0 | 53 | const windowManagerInterface = Components |
michael@0 | 54 | .classes['@mozilla.org/appshell/window-mediator;1'].getService() |
michael@0 | 55 | .QueryInterface(Components.interfaces.nsIWindowMediator); |
michael@0 | 56 | const iterator = windowManagerInterface.getEnumerator("mozilla:help"); |
michael@0 | 57 | var topWindow = null; |
michael@0 | 58 | var aWindow; |
michael@0 | 59 | |
michael@0 | 60 | # Loop through help windows looking for one with selected content |
michael@0 | 61 | # pack. |
michael@0 | 62 | while (iterator.hasMoreElements()) { |
michael@0 | 63 | aWindow = iterator.getNext(); |
michael@0 | 64 | if (!aWindow.closed && aWindow.getHelpFileURI() == contentPack) { |
michael@0 | 65 | topWindow = aWindow; |
michael@0 | 66 | } |
michael@0 | 67 | } |
michael@0 | 68 | return topWindow; |
michael@0 | 69 | } |