I created a widget in XBL in my own namespace, and the users should be
able to provide event handlers (e.g. onmouseup) in their XUL file for
it.
Here is a minimal example of what I did:
example.css:
@import url(chrome://global/skin/);
@namespace url(http://my-namespace/example#);
drawing {
-moz-binding: url(example.xbl#example);
display: -moz-box;
}
example.xbl:
<?xml version="1.0" encoding="UTF-8" ?>
<bindings xmlns="http://www.mozilla.org/xbl"
xmlns:svg="http://www.w3.org/2000/svg"
>
<binding id="example"
extends="chrome://global/content/bindings/general.xml#basecontrol">
<content>
<svg:svg version="1.1" height="100px" width="100px">
<svg:circle cx="50" cy="50" r="30" fill="blue"/>
</svg:svg>
</content>
</binding>
</bindings>
The user of this widget should be able to provide 'on...' event handlers
as in this example:
example.xul
<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet href="example.css" type="text/css"?>
<window
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<example xmlns="http://my-namespace/example#" id="experiment"
onmouseup="alert(event);"
/>
</window>
When I don't use a namespace for the widget, this works. Is there
something I can implement in addition to make this work in my custom
namespace?
Thank you,
Klaus
I just noticed an error in my post:
> @namespace url(http://my-namespace/example#);
> drawing {
> -moz-binding: url(example.xbl#example);
> display: -moz-box;
> }
should be:
@namespace url(http://my-namespace/example#);
example {
-moz-binding: url(example.xbl#example);
display: -moz-box;
}
That happened because I simplified the example and changed
some names. Sorry for that.
--
Klaus
> Is there something I can implement in addition to make this work in my
> custom namespace?
I don't think so; if you use a custom namespace then all your elements
will be generic XML elements and won't have any useful properties
(class, id, event handler, etc.)
--
Warning: May contain traces of nuts.
Your XBL binding constructor could go through the element's attributes, look for
on* ones, get the values, and use addEventListener accordingly. Then install
mutation listeners for those attributes so you can handle dynamic changes, etc.
Basically, duplicate the existing C++ on* code, more or less.
Depending on how transparent you want this to be, you'd also have to handle sets
of on* properties somehow. That might be harder.
-Boris
I'm going to try that, thank you.
--
Klaus