Here is what I've been using for custom events in my projects.
It is pretty straight forward and small.
http://www.brandonaaron.net/prototype/src/event.custom.js

You create an event like this:

var onMyEvent = new Event.Custom('myEvent'[, someObject || window]);

The first param is the name of the event, it defaults to
'customEvent'. The second param is global scope correction for all
observers. It defaults to window.

Then you can attach observers to it like this:

onMyEvent.observe(function(event[, extra, params]) { /*...*/ }[,
override scope || event scope ]);

You can detach an observer by replacing observe in the previous
example with stopObserving. I would suggest using the scope override
instead of bind to properly stopObserving functions without having to
create handlers for your observers.

You can fire the event like this:

onMyEvent.fire(eventObject[, param1, param2 /*... */]);

The eventObject is something you would create ... by default it will
contain a name property and has the name of the event when you created
it. The fire method can take any number of extra params that will be
passed onto the observers.

You can unsubscribe all observers by calling onMyEvent.unsubscribeAll()

Let me know if you use it and if it works for you. I just recently
rewrote it ... so let me know if you run into any bugs.

Brandon

On 8/17/06, Seth Dillingham <[EMAIL PROTECTED]> wrote:
On 8/17/06, Brian Feliciano <[EMAIL PROTECTED]> wrote:
> Hi guys!
> i know prototype can create custom events and can subscribe to it, but is
> there already a library for this?

<http://www.truerwords.net/articles/web-tech/custom_events.html>
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

Reply via email to