Xunshirine
Xunshirine

Reputation: 181

How to add Toolbar Button for Firefox Australis

I used below code to add toolbar buttons automatically in navigation toolbar below Firefox Australis.

var buttonId =  "toolbarbutton-toolbarbutton";
var navBar = document.getElementById("nav-bar");
var currentSet = navBar.currentSet;

var curSet = currentSet.split(",");
if (curSet.indexOf(buttonId) == -1)
{
    navBar.insertItem(buttonId);
    navBar.setAttribute("currentset", navBar.currentSet);
    document.persist("nav-bar", "currentset");

    try
    {
        top.BrowserToolboxCustomizeDone(true);
    }
    catch (e)
    {

    }
}

Because user interface and modules changed for Australis, the code needs to be updated. How can I add Toolbar Button for Australis proper way?

Upvotes: 3

Views: 516

Answers (1)

Wladimir Palant
Wladimir Palant

Reputation: 57691

You have to use the CustomizableUI module:

try
{
  Components.utils.import("resource:///modules/CustomizableUI.jsm");
  CustomizableUI.createWidget({
    id: "toolbarbutton-toolbarbutton",
    defaultArea: "nav-bar",
    removable: true,
    label: "My button",
    tooltiptext: "My tooltip text",
    onClick: function()
    {
      alert("Clicked");
    }
  });
}
catch (e)
{
  Components.utils.reportError(e);

  // No such module? Try the old approach.
  ...
}

Note that the widget no longer needs to be added for each browser window, it is enough to do it once. Unfortunately, the module documentation is practically non-existent right now, the code above has been deduced from module's source code. The documentation should improve soon however.

If it helps, Adblock Plus source code contains an emulation of the CustomizableUI API for older Firefox versions. This one is far from complete however, it is only meant to cover the needs of Adblock Plus.

Upvotes: 2

Related Questions