https://developer.mozilla.org/en/XBL/XBL_1.0_Reference/Binding_Attachment_and_Detachment
What I understood from the link above, using loadBindingDocument() and
style.MozBinding should work.
Below is my test code. I would expect it to dump "bar" on load event and when
button is clicked. But because binding doesn't seem to be synchronous, I
get "undefined" on load. dump on button click works so there's nothing wrong
with binding itself.
So, what am I doing wrong, or is synchronous binding just not possible?
XBL:
<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://www.mozilla.org/xbl">
<binding
id="button-foo"
extends="chrome://global/content/bindings/button.xml#button">
<implementation>
<field name="foo" readonly="true">"bar"</field>
</implementation>
</binding>
</bindings>
XUL:
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="onLoad()">
<script type="text/javascript">
var xblUrl = "..."
document.loadBindingDocument(xblUrl);
function onLoad()
{
var button = document.getElementById('button');
button.style.MozBinding = "url(" + xblUrl "#button-foo)";
dump(button.foo + "\n");
}
</script>
<button id="button" label="Click me!" oncommand="dump(this.foo + '\n')" />
</window>
--
Atte Kemppilä
This is synchronous.
> button.style.MozBinding = "url(" + xblUrl "#button-foo)";
But this is not. It posts an event to do the restyle. Property lookups
on the node don't trigger restyles.
Does adding a layout flush here (eg. getting the boxobject size for one
of the elements involved) help?
-Boris
Yes, adding "button.boxObject.width" solved the problem. Thank you.
--
Atte Kemppilä