toolkit/components/help/content/contextHelp.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/help/content/contextHelp.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,69 @@
     1.4 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.5 +# License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.7 +
     1.8 +# Set the default content pack to the Mozilla content pack. Use the
     1.9 +# setHelpFileURI function to set this value.
    1.10 +var helpFileURI;
    1.11 +
    1.12 +# openHelp - Opens up the Mozilla Help Viewer with the specified
    1.13 +#    topic and content pack.
    1.14 +# see http://www.mozilla.org/projects/help-viewer/content_packs.html
    1.15 +function openHelp(topic, contentPack)
    1.16 +{
    1.17 +# helpFileURI is the content pack to use in this function. If contentPack is defined,
    1.18 +# use that and set the helpFileURI to that value so that it will be the default.
    1.19 +  helpFileURI = contentPack || helpFileURI;
    1.20 +
    1.21 +# Try to find previously opened help.
    1.22 +  var topWindow = locateHelpWindow(helpFileURI);
    1.23 +
    1.24 +  if ( topWindow ) {
    1.25 +# Open topic in existing window.
    1.26 +    topWindow.focus();
    1.27 +    topWindow.displayTopic(topic);
    1.28 +  } else {
    1.29 +# Open topic in new window.
    1.30 +    const params = Components.classes["@mozilla.org/embedcomp/dialogparam;1"]
    1.31 +                             .createInstance(Components.interfaces.nsIDialogParamBlock);
    1.32 +    params.SetNumberStrings(2);
    1.33 +    params.SetString(0, helpFileURI);
    1.34 +    params.SetString(1, topic);
    1.35 +    const ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
    1.36 +                         .getService(Components.interfaces.nsIWindowWatcher);
    1.37 +#ifdef XP_WIN
    1.38 +#define HELP_ALWAYS_RAISED_TOGGLE
    1.39 +#endif
    1.40 +#ifdef HELP_ALWAYS_RAISED_TOGGLE
    1.41 +    ww.openWindow(null, "chrome://help/content/help.xul", "_blank", "chrome,all,alwaysRaised,dialog=no", params);
    1.42 +#else
    1.43 +    ww.openWindow(null, "chrome://help/content/help.xul", "_blank", "chrome,all,dialog=no", params);
    1.44 +#endif
    1.45 +  }
    1.46 +}
    1.47 +
    1.48 +# setHelpFileURI - Sets the default content pack to use in the Help Viewer
    1.49 +function setHelpFileURI(rdfURI)
    1.50 +{
    1.51 +  helpFileURI = rdfURI;
    1.52 +}
    1.53 +
    1.54 +# Locate existing help window for this content pack.
    1.55 +function locateHelpWindow(contentPack) {
    1.56 +    const windowManagerInterface = Components
    1.57 +        .classes['@mozilla.org/appshell/window-mediator;1'].getService()
    1.58 +        .QueryInterface(Components.interfaces.nsIWindowMediator);
    1.59 +    const iterator = windowManagerInterface.getEnumerator("mozilla:help");
    1.60 +    var topWindow = null;
    1.61 +    var aWindow;
    1.62 +
    1.63 +# Loop through help windows looking for one with selected content
    1.64 +# pack.
    1.65 +    while (iterator.hasMoreElements()) {
    1.66 +        aWindow = iterator.getNext();
    1.67 +        if (!aWindow.closed && aWindow.getHelpFileURI() == contentPack) {
    1.68 +            topWindow = aWindow;
    1.69 +        }
    1.70 +    }
    1.71 +    return topWindow;
    1.72 +}

mercurial