Announcing the PanelView Add-on SDK Module

Yesterday Australis was released to the public with Firefox 29. Australis introduces panelview elements which are used for all the default buttons with panels. The difference between a panelview and a panel essentially are, that the panelview will open as a subview when its anchor (read: button) is in the menupanel.


Mozilla’s Add-on SDK doesn’t offer any way at this point to create such a panelview, it only supports panels. So I wrote a module to create panelviews. My module can’t replace the panel module from the SDK yet, as it can not display frames as its content. Instead it currently only allows you to add buttons and separators, so you can replace what previously were popup-menus, which would open from a button, with a fancy new panelview.

<br />
var { PanelView } = require(&quot;panelview&quot;);<br />
PanelView({<br />
  id: &quot;demo-panelview&quot;,<br />
  title: &quot;Demo&quot;,<br />
  content: [<br />
    {<br />
      type: &quot;button&quot;,<br />
      label: &quot;Test Button&quot;,<br />
      onClick: function() {<br />
        console.info(&quot;Hello World!&quot;);<br />
      }<br />
    }<br />
  ]<br />
});<br />

There are some additional benefits to a panelview: a panelview has a header and optionally a footer (non-SDK panels can have a footer too). The header is only displayed when the panelview is opened in the menu panel, so you know what it is. The footer allows you to add a highlighted action. In Firefox it is mainly used to open a complete view of what the menu summarizes, like the library window.

The module allows you to create special buttons too, like checkboxes or radio items, though I’m not sure you can define radio groups with the current implementation. Of course you can also add an icon and a click listener to your button.

<br />
{<br />
  type: &quot;button&quot;,<br />
  actionType: &quot;checkbox&quot;,<br />
  label: &quot;I like trains&quot;,<br />
  onClick: function(event) {<br />
    // event is the event object from the onCommand event of the button<br />
    console.info(&quot;So you &quot; + event.target.checked ? &quot; &quot; : &quot;don't &quot; + &quot;like trains&quot;);<br />
  }<br />
},<br />
{<br />
  type: &quot;separator&quot;<br />
},<br />
{<br />
  type: &quot;button&quot;,<br />
  icon: &quot;./disabledButton.png&quot;,<br />
  disabled: true,<br />
  onClick: () =&gt; console.info(&quot;You shouldn't see this&quot;)<br />
}<br />

However it is currently not possible to modify the contents after the creation of the PanelView. I do plan on allowing that in the future, I’ll possibly even add support for frames.

It’s also worth mentioning, that you currently have to modify SDK buttons to work properly with the PaneView module as anchor. The buttons close the menu panel on click by default, which has to be changed. The module offers you an easy way to do so, however it currently isn’t working properly with windows opened after the fix is applied.

<br />
// open panelview anchored to the button when the button is clicked<br />
button.on(&quot;click&quot;, () =&gt; panelview.open(button));<br />
// patch the button so it doesn't close the menu panel when clicked<br />
require(&quot;panelview/workaround&quot;).applyButtonFix(button);<br />

The PanelView SDK Module is licensed under the MPL 2.0 and is available for download on GitHub. There is exact documentation of the API included in the module in the docs folder.

I want to note that there is not a lot of documentation apart from Firefox’s code on how to use panelviews. So this module might misbehave or do strange things. I have 52 unit tests, making sure everything works as intended. If you happen to come across bugs, please report them. If you have improvements, please feel free to post pull requests!