fat/bean — pull request #41 by eleith (2011-11-28 19:39:56+00:00)
Title: extendable custom events for bean

how it works:

1. expose `bean.customEvents` out in the open
2. allow for customEvents to have `base`, `handler` and `condition` fields
3. on add/bind (on a custom event with both a base and a handler), register a listener for the base type using the custom handler and normally register a listener for the custom event
4. custom handler should eventually lead to a fire/trigger on the custom event type

here is an example of how to extend the custom events with a basic tripleclick event

```
bean.customEvents.threeclicks = {
base: 'click',
handler: function(event)
{
var elem = this, clicks = this.__threeclicks__ || 0;
clicks += 1;
if ( clicks === 3) {
clicks = 0;

// set event type to "tripleclick"
event.type = "threeclicks";

//FIRE AWAY
bean.fire(this, "threeclicks", event);
}
this.__threeclicks__ = clicks;
}
}
```

to register the event:

```
bean.add(element, "tripleclick", function() { alert('triple clicked!'); });
```

to remove the event:

```
bean.remove(element, "tripleclick")
```

it should still support namespacing, using the element/ender object as context in the handlers, and all the different ways add/remove can be called.

i've also added these examples in the tests.js framework to show (and prove) how add/remove works on these extended custom events.