My favorites | Sign in
Project Logo
                
Blogs:
Feeds:
People details
Project owners:
  gregreimer
Project committers:
andrew.p...@sun.com

Why not behavior sheets?

CSS is nice because it lets you declare styles without worrying about DOM load, traversal or having to reattach styles as the DOM gets updated over the lifetime of the page. Which raises the question, why isn't the behavior layer similarly declarative?

/* the style sheet */
div.menu li > a { color: blue; }

/* why not a behavior sheet? */
div.menu li > a { click: function(e) { ... }; }

reglib's goal is to get as close to that as possible:

reg.click("div.menu li > a", function(e) { ... });

reglib is so named because it lets you "register" an event handler against a CSS selector. Like CSS, once the above code is "declared", the event handling behavior takes effect globally. This is true regardless of whether the onload event has fired, or whether the DOM has finished loading off the network, or whether arbitrary sections of DOM have been overwritten.

Besides event declaration, this lib contains a few other convenience and helper utilities. Specifically:

Whenever possible this lib takes advantage of native APIs, such as Node.getElementsByClassName() and Node.querySelector(), falling back on more laborious manual methods for doing the same things in older clients.









Hosted by Google Code