Search code examples
firefoxfirefox-addonfirefox-addon-sdk

Show a panel anchored to Erik-vold's toolbarbutton, programmatically


Here is what I want to do:

var mainPanel = require("panel").Panel({
    width: '200',
    height: '500',
    contentURL: gatewayURL,
    contentScriptWhen: "start",
    contentScriptFile: [
        self.data.url("messagelistener.js")
    ]
});

var button = toolbar.ToolbarButton({
    'id': 'com.user043.myOneButton',
    'image': require("self").data.url("image-24.ico"),
    'label': "Test",
    'panel': mainPanel
});

tabs.on('ready', function(tab) {
    if(tab.url==="http://www.google.com") {
        mainPanel.show();    //This opens panel in centre. I want the panel to be anchored to the button it is associated to(just like it appears when I click on toolbarbutton). How do I get the DOM of the button created by ToolbarButton API?
    }
}

I am using erik-vold's toolbarbutton API: https://github.com/voldsoftware/toolbarbutton-jplib. How do I get the DOM of the button so that I can do something like mainPanel.show(tbb); where tbb = DOM of button? Please help!


Solution

  • panel.show(require('sdk/window/utils').getMostRecentBrowserWindow().document.getElementById('com.user043.myOneButton'))