Poor Man's XBL

Summary

Poor Man's XBL is a light-weight element binding (or behavior) framework. It accepts binding documents in the XBL-2.0 format, but doesn't implement XBL templates and doesn't even maintain state in the bindings.

The XBL system relies completely on event delegation, i.e. event listeners are registered on the document rather than the bound-elements. For every event that might need handling by XBL bindings, the system analyzes the event path from event-target to the document-root and attaches bindings and calls handlers as appropriate.

This simplifies the code in two ways:

There are also disadvantages of this approach:

What's it for?

Poor Man's XBL was written to demonstrate the usefulness of Element.matchesSelector() combined with event-delegation. Element.matchesSelector() was proposed for the W3C Selectors-API specification but was ruled out due to lack of use-cases. (It may be in a future version of the spec).

My opinion is that this is a huge hole in the spec and the lack of use-cases demonstrates that the domain isn't properly understood... but my arguments haven't had any impact (mostly because I spoke up too late I suppose), so I wrote this implementation to make the point.

There's some simple demos to prove that it works.

Licensing

Poor Man's XBL is not permitted for any use (apart from it's demonstration on this site).