API-provided widgets 编辑

To create a widget, you should pass a specification object with its desired properties. This document details the available properties.

Properties

PropertyDescription
idthe ID of the widget (required).
typea string indicating the type of widget. Possible types are
button
for simple button widgets (the default)
view
for buttons that open a panel or subview, depending on where they are placed.
custom
for fine-grained control over the creation of the widget.
viewIdOnly useful for views (and required there): the id of the that should be shown when clicking the widget.
tooltiptextstring to use for the tooltip of the widget
labelstring to use for the label of the widget
removablewhether the widget is removable (optional, default: true).
NB: if you specify false here, you must provide a defaultArea, too.
overflowswhether widget can overflow when in an overflowable toolbar (optional, default: true)
defaultAreadefault area to add the widget to (optional, default: none; required if non-removable)
shortcutIdid of an element that has a shortcut for this widget (optional, default: null). This is only used to display the shortcut as part of the tooltip for builtin widgets (which have strings inside customizableWidgets.properties). If you're in an add-on, you should not set this property, and should instead include the shortcut as part of the tooltiptext you pass in yourself.
showInPrivateBrowsingwhether to show the widget in private browsing mode (optional, default: true)

Event handlers

You can also define several event handlers which will be called at various stages in a widget's lifetime:

Event handler nameDescription
onBuild(aDoc)Only useful for custom widgets (and required there); a function that will be invoked with the document in which to build a widget. Should return the DOM node that has been constructed. NB: the DOM node you construct should have the same ID as the id property described above, so that CustomizableUI can find the node again later.
onBeforeCreated(aDoc)Attached to all non-custom widgets; a function that will be invoked before the widget gets a DOM node constructed, passing the document in which that will happen.
This is useful especially for 'view' type widgets that need to construct their views on the fly (e.g. from bootstrapped add-ons).
onCreated(aNode)Attached to all widgets; a function that will be invoked whenever the widget has a DOM node constructed, passing the constructed node as an argument.
onDestroyed(aDoc)Attached to all non-custom widgets; a function that will be invoked after the widget has a DOM node destroyed, passing the document from which it was removed. This is useful especially for 'view' type widgets that need to cleanup after views that were constructed on the fly.
onCommand(aEvt)Only useful for button widgets; a function that will be invoked when the user activates the button.
onClick(aEvt)Attached to all widgets; a function that will be invoked when the user clicks the widget.
onViewShowing(aEvt)Only useful for views; a function that will be invoked when a user shows your view.
onViewHiding(aEvt)Only useful for views; a function that will be invoked when a user hides your view.

 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:112 次

字数:4625

最后编辑:8年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文