1

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!

4

2 回答 2

0
panel.show(require('sdk/window/utils').getMostRecentBrowserWindow().document.getElementById('com.user043.myOneButton'))
于 2013-04-07T05:03:10.547 回答
0
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",
    onClick: function(view) { 
          view.panel = mainPanel;

      }
});

Instead of using mainPanel.show(),  use view.panel = mainPanel;. It will solve the problem bcz I did the same and it works for me.
于 2013-05-15T06:32:15.073 回答