锚点面板到ToggleButton上显示?

时间:2014-12-29 13:22:36

标签: javascript firefox-addon-sdk

我试图显示panel并根据button定位它,但panel仍显示在窗口的中央,是我错过了什么?

我可以定位panel onclick,使其锚定到togglebutton,但是当尝试以编程方式锚定它时,它不起作用。

main.js ..

var Button = require("./ToggleButton"),
  Panel = require("sdk/panel"),
  Data = require("./Data");

var panel = Panel.Panel({
  width: 350,
  height: 130,
  contentURL: Data.get("html/view.html"),
  contentScriptFile: Data.get("js/controller.js")
});

panel.port.on("selectDir", function () {
  // Chrome API access, user selects a directory, then re-show the panel anchored to Panel?
  panel.show({
    position: Button.get()
  });
});

ToggleButton.js ..

var { ToggleButton } = require("sdk/ui/button/toggle"),
  Data = require("./Data"),
  button;

exports.init = function() {

  button = ToggleButton({
    id: "widget",
    label: 'Label',
    icon: Data.get("images/ico-64.png"),
  });
}

exports.get = function() {
  return button;
}

1 个答案:

答案 0 :(得分:2)

panel = Panel.Panel({
    width: 350,
    height: 130,
    contentURL: Data.get("html/view.html"),
    contentScriptFile: Data.get("js/controller.js"),
    position: Button.get()
});

..做了伎俩。