is there any way to attach multiple bindings to one single element
with XBL 1?
examples all start from very modular bindings, eg.
two different behaviors on a mouse click
one binding for 'aesthetic' behavior, the other for logic, possibility
to switch one of them only
etc.etc.
The spec says it should be possible (https://developer.mozilla.org/En/
XBL/XBL_1.0_Reference/Anonymous_Content) but I know there's quite a
difference from that spec to FF implementation, and I simply couldn't
find a way to do it.
Any idea?
thanks a lot,
Stefano
Only if they extend each other or are attached from script via
document.addBinding.
-Boris
Thanks Boris for your prompt answer.
'extends' is not an option, since i'd like the bindings to be
independent one from each other.
addBinding is giving me some headaches, in particular it does not add
the <content> template!!!
When i attach the same binding to the same element using MozBinding or
a style it does work.
Also, removeBinding does not work at all, giving me an error:
uncaught exception: [Exception... "Component returned failure code:
0x80004005 (NS_ERROR_FAILURE) [nsIDOMDocumentXBL.removeBinding]"
nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame ::
http://js.mixendo.local/html/test.html :: onclick :: line 1" data: no]
[Break on this error]
Any idea?
thanks a lot,
Stefano
My JS code:
element=$('#elID')[0]; //using jQuery or any other method
document.addBinding(element,'chrome://testmultibindings/content/
bindings.xml#bind1')
document.addBinding(element,'chrome://testmultibindings/content/
bindings.xml#bind2')
[...]
document.removeBinding(element,'chrome://testmultibindings/content/
bindings.xml#bind1')
document.removeBinding(element,'chrome://testmultibindings/content/
bindings.xml#bind2')
and 2 simple almost identical bindings:
<binding id="bind1" inheritstyle ="false">
<content>
<children/>
<span>bind1</span>
</content>
<implementation>
<constructor>
<![CDATA[
console.log('bind1')
]]>
</constructor>
<destructor>
<![CDATA[
console.log('destructor bind1')
]]>
</destructor>
</implementation>
<handlers>
<handler event="click">
<![CDATA[
console.log('click bind1')
]]>
</handler>
</handlers>
</binding>
Odd. Do you have a testcase in the form of an extension, just to make
sure we're looking at the same thing? Nothing I see in the code should
obviously keep that from working. That said, if you have multiple
bindings that all have <content>, behavior will of course be odd (e.g.
depend on the order you called addBinding in).
> Also, removeBinding does not work at all, giving me an error:
>
> uncaught exception: [Exception... "Component returned failure code:
> 0x80004005 (NS_ERROR_FAILURE) [nsIDOMDocumentXBL.removeBinding]"
> nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame ::
> http://js.mixendo.local/html/test.html :: onclick :: line 1" data: no]
> [Break on this error]
Presumably due to this:
// For now we can only handle removing a binding if it's the only one
NS_ENSURE_FALSE(binding->GetBaseBinding(), NS_ERROR_FAILURE);
Basically, what you're trying to do is not very well supported.
-Boris
Boris,
thanks a lot for your answer and time.
Indeed, it sounds like we better wait for XBL2 to use multiple
bindings!
For the not-showing content problem i'll clean up and send you a
sample extension if you care.
thanks,
Stefano
Please do.
-Boris
I thought that was how it was supposed to work (using <content> only
for bindings attached via -moz-binding), but I'm not particularly
sure I know what I'm talking about here.
-David
--
L. David Baron http://dbaron.org/
Mozilla Corporation http://www.mozilla.com/
That's what I seemed to recall, but I just don't see where the code
enforces that....
-Boris
Sorry I took some time to clean up the code and my tests.
I can confirm the following practical findings:
1. removeBinding does not work seem to work (NS_ERROR_FAILURE)
2. in order to remove a binding set with -moz-binding (or
style.MozBinding), an 'empty' binding must be used (eg. * { -moz-
binding: url('bindings.xml#empty') } ). Any other way?
3. addBinding only works with bindings in the chrome://
4. addBinding does allow to add multiple bindings to one element
5. <content> of bindings added with addBinding is not used!!
Though probably you all knew this already, it's hard to find this kind
of information somewhere - the MDC doc is often out of date or
incomplete, unluckily (yes I know, it's extremely hard to keep a doc
up to date!!!)
Boris, I'll send you a zip file with some test files - if that's
redundant just drop it altogether :-)
Thanks a lot for your support,
Stefano
That's not quite right. It _is_ used if the layout objects for the node
are ever recreated. Bug addBinding on its own doesn't trigger such
recreation (probably a bug, really).
For example, if I change your code that adds the binding to look like this:
document.addBinding($('#tobind')[0],
'chrome://multibindings/content/bindings.xml#bind1');
$('#tobind')[0].style.display = 'none';
document.body.offsetWidth;
$('#tobind')[0].style.display = '';
Then the <content> works just fine...
-Boris
Very true!
thanks Boris.
the latest <content> apparently overrides the previous one, which
might be acceptable.
Now if i had a pattern to remove these multiple bindings knowing that
removeBinding does not work that woudl be great!
hopefully Jonas's XBL2 is coming soon ;-)
stefano