Layer XUL Elements/Images/Backgrounds in Firefox 3 Extensions Using Stack
While working on the Read It Later Firefox Extension, I wanted a way to layer multiple background images on a toolbar button so I could create a nice looking notification indicator like on the iPhone. (Note I opt-ed later to use a simpler look, but this method might still be helpful for other applications).
In order to make this work you’ll need to familarize yourself with XBL and XUL Stacks. XBL allows you to essentially reconfigure how an XUL element works/looks.
In this case, we’ll use XBL to replace a normal ToolbarButton into a Stack Element.
So first you’ll need your toolbarbutton added to your XUL overlay:
<toolbarbutton id=”tButton” type=”menu-button” />
Next we need to create the XBL Binding (complete the tutorial linked about XBL if you don’t know what XBL is):
<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://www.mozilla.org/xbl"
xmlns:xbl="http://www.mozilla.org/xbl"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<binding id="toolbarbutton"
display="xul:menu"
extends="chrome://global/content/bindings/button.xml#menu-button-base">
<resources>
<stylesheet src="chrome://global/skin/toolbarbutton.css" />
</resources>
<content>
<xul:toolbarbutton
class="buttonstack"
anonid="button"
flex="1"
allowevents="true"
xbl:inherits="disabled,crop,image,label,accesskey,command,align,
dir,pack,orient,toolbarmode,buttonstyle,status,notifyNumber" />
</content>
</binding>
<binding id="buttonstack">
<content>
<children>
<xul:stack
align="center"
pack="center"
xbl:inherits="allowevents">
<xul:image src="chrome://urextension/skin/buttonimage.png" />
<xul:image src="chrome://urextension/skin/number_circle.png" />
<xul:label value="" xbl:inherits="value=notifyNumber,allowevents" />
</xul:stack>
</children>
</content>
</binding>
</bindings>
document.getElementById(‘tButton’).setAttribute(‘notifyNumber’, 3);
If you look at the XBL code, make note of where ‘notifyNumber’ is inherited. This is how XBL knows to send the attribute down the chain. You can make the attribute anything or add other attributes as well.
Finally, you need to apply the bindings to your toolbar button. In your stylesheet add the following lines:
#tButton {
-moz-binding: url("chrome://urextension/content/yourxblfile.xml#toolbarbutton");
}
.buttonstack {
-moz-binding: url("chrome://urextension/content/yourxblfile.xml#buttonstack");
}
13 Notes/ Hide
-
christinaert liked this
-
waterex10 liked this
-
seeksui09 liked this
-
murphytii0 liked this
-
stephensok85 liked this
-
nateweiner posted this