4

I am creating a firefox add-on with Add-on SDK. My add-on uses a sidebar created with the ui/sidebar API. Is there any way for me to control the initial width of this sidebar?

The user can drag to change its size, but I would like it to start with a greater width than it seems to open at by default. Is this possible?

Thanks.

Pwnosaurus
  • 2,058
  • 1
  • 19
  • 21

2 Answers2

3

Using window/utils you can get the topmost browser window as an nsIDOMWindow instance, then you can get the sidebar element of that window as an HTML element, which would enable you to modify it's CSS properties:

var utils = require('sdk/window/utils');
var win = utils.getMostRecentBrowserWindow();
if (utils.isBrowser (win))
{
    var sidebar = win.document.getElementById ("sidebar");
    sidebar.style.minWidth = "340px";
    sidebar.style.width = "340px";
    sidebar.style.maxWidth = "500px";
}

Note that this will affect all sidebars of the topmost open firefox window (including bookmarks and history sidebars);

razz
  • 9,770
  • 7
  • 50
  • 68
0

Yes use width in the style attribute. Or use min-width. Like style: 'min-width: 14em; width: 18em; max-width: 36em;'

Here is an addon that creates a sidebar. You can install it, its a ready to go demo. _ff-addon-BootstrapSidebar

Noitidart
  • 35,443
  • 37
  • 154
  • 323
  • Which style attribute are you referencing? I'm new to firefox add-ons, but it looks like the example you provided was for a bootstraped extension. My project uses the add-on sdk. Can I set this attribute from within the SDK? Thanks! – Pwnosaurus Mar 07 '14 at 05:45
  • Oh I missed that. In SDK I'm not sure. – Noitidart Mar 07 '14 at 05:47
  • 1
    I see no one has replied to this still. See this addon it is bootstrap, but a simple template to show you about sidebar: [_ff-addon-template-BootstrapSidebar](https://gist.github.com/Noitidart/8728393) the width is controlled in this one – Noitidart Mar 09 '14 at 21:55