A Busy Developer's Guide to Seth's Custom Javascript Events
There's a link here to a Busy Developer's Guide to Seth's Javascript Custom Event mixins.
It's a truly simple example. Loading the page will fire the event causing an alert to pop with the event name and the data of the event. The data in our case is a simple JSON object.
The essence of the code is this script block where we set up a broker and register the event publisher and the event listener respectively. Then we just fire off the event:
var my_broker_object = Class.create();
Object.extend( my_broker_object, Event.Broker )
var publisher_control = Class.create();
Object.extend(publisher_control, Event.Publisher);
my_broker_object.registerEventsPublisher("myEvent", publisher_control)
var listener_control = Class.create();
Object.extend(listener_control, Event.Listener);
Object.extend(listener_control, {
onMyEvent: function( evt)
{
alert("event occured: " +
evt.event_data.event_name +
" :: " + evt.event_data.data.message);
}
});
listener_control.listenForEvent(my_broker_object, "myEvent", false)
publisher_control.dispatchEvent( "myEvent", {message: "my data stuff"} );
Enjoy!
