使用 Firefox Add-on SDK 进行面板定位
我正在尝试使用新的 SDK 将我的面板定位在附加组件中取得一些进展。
我发现文档仅显示了控制面板位置的一种方法,那就是在 show()
时传递锚点:
显示(锚点)
显示面板。 [锚:句柄]
面板应显示的页面中 DOM 节点的句柄 被锚定。如果没有给出,面板将在最里面居中 最近的浏览器窗口。请注意,目前无法 仅使用高级 API 以这种方式锚定面板。
理想情况下,我希望锚点是单击该小部件时面板显示锚定到的小部件,但该小部件不是页面中的 DOM 节点,所以我想不是......
我也许可以解决这个问题,但我什至找不到如何将面板锚定到 DOM 节点的工作示例。当我通过 port
传回 contentScript
中的 DOM 节点时,如下所示:
lib/main.js
var scraper = pageMod.PageMod({
include: ['*'],
contentScriptWhen: 'ready',
contentScriptFile: [data.url('jquery-1.6.2.min.js'), data.url('scraper.js')],
onAttach: function(worker){
worker.port.on('pageLoaded', function(page){
widget.panel.show(page.anchor);
});
}
data/scraper.js< /strong>
$('body').append('
<div id="anchor-to-me" style="position:fixed; bottom: 0; right: 0;">.</div>
');
var anchor = $('#anchor-to-me').get();
self.port.emit('pageLoaded', { anchor : anchor });
我收到以下控制台错误:
error: An exception occurred.
Traceback (most recent call last):
File "resource://jid1-wuvxefqtmptsnw-at-jetpack-addon-kit-lib/panel.js", line 147, in show
let document = getWindow(anchor).document;
File "resource://jid1-wuvxefqtmptsnw-at-jetpack-addon-kit-lib/panel.js", line 345, in getWindow
let anchorWindow = anchor.ownerDocument.defaultView.top;
TypeError: anchor.ownerDocument is undefined
任何可以帮助我成功锚定到 DOM 元素或找到其他方法来定位面板的信息都会很棒。
谢谢。
I am trying to make some headway positioning my panel in an Add-on make with the new SDK.
I see that the documentation shows only one way to control the position of a panel, and that is by passing an anchor when you show()
it:
show(anchor)
Displays the panel. [ anchor : handle ]
A handle to a DOM node in a page to which the panel should appear to
be anchored. If not given, the panel is centered inside the most
recent browser window. Note that it is not currently possible to
anchor panels in this way using only the high level APIs.
Ideally, I'd like the anchor to be the widget that the panel appears anchored to when that widget is clicked, but the widget is not a DOM node in a page
so I guess not...
I can probably work around this, but I can't even find a working example of how to anchor the panel to a DOM node. When I pass back a DOM node in a contentScript
through port
like this:
lib/main.js
var scraper = pageMod.PageMod({
include: ['*'],
contentScriptWhen: 'ready',
contentScriptFile: [data.url('jquery-1.6.2.min.js'), data.url('scraper.js')],
onAttach: function(worker){
worker.port.on('pageLoaded', function(page){
widget.panel.show(page.anchor);
});
}
data/scraper.js
$('body').append('
<div id="anchor-to-me" style="position:fixed; bottom: 0; right: 0;">.</div>
');
var anchor = $('#anchor-to-me').get();
self.port.emit('pageLoaded', { anchor : anchor });
I get the following console error:
error: An exception occurred.
Traceback (most recent call last):
File "resource://jid1-wuvxefqtmptsnw-at-jetpack-addon-kit-lib/panel.js", line 147, in show
let document = getWindow(anchor).document;
File "resource://jid1-wuvxefqtmptsnw-at-jetpack-addon-kit-lib/panel.js", line 345, in getWindow
let anchorWindow = anchor.ownerDocument.defaultView.top;
TypeError: anchor.ownerDocument is undefined
Any info to help me successfully anchor to a DOM element, or find some other way to position the panel would be great.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要使用
mainPanel.show()
,而是使用view.panel = mainPanel;
。它将解决问题,因为我也做了同样的事情。Instead of using
mainPanel.show()
, useview.panel = mainPanel;
. It will solve the problem bcz I did the same.当您定义小部件时,您可以添加一个面板属性,该属性是面板的实例:
这是一个示例(不幸的是,文档中没有这样的示例):
When you define your widget, you can add a panel property that is the instance of your panel:
Here's an example ( unfortunately there isn't an example of this in the docs ):