Class Event.Listener
Event.Listener
MIX IN: Event.Listener
Description:
easily add support for receiving totally custom events
(to any object or class) by mixing this class into
your own
Usage:
To receive custom events:
1. mix this class with your own via
Object.extend( [your class or prototype], EventListener )
2. listen for events by calling (from your object)
this.listen()
(see params for this.listen, below)
Defined in: event.js.
| Constructor Attributes | Constructor Name and Description |
|---|---|
|
new Event.Listener()
|
| Method Attributes | Method Name and Description |
|---|---|
|
getEventHandlerName(event_name)
Private.
|
|
|
listenForEvent(event_source, event_name, use_capture, onEvent_name)
Causes the listener to "subscribe" for events of type event_name which are published
by event_source, assuming that event_source is an Event.Publisher.
|
|
|
stopListeningForEvent(event_source, event_name, use_capture, onEvent_name)
Unsubscribe the current listener from the events of type
event_name published by event_source.
|
Method Detail
getEventHandlerName(event_name)
Private. If a call to listenForEvent or stopListeningForEvent omits the name of the listener function,
getEventHandlerName is used to find the "correct" name of the listener function.
The "correct" name of the handler function is determined by upper-casing the first character
of the event name, replacing all /[ _]/ with -, camelizing the result,
and then prepending "on". So if the event's name is "i just did_something", this function would return "onIJustDidSomething", and the listener code would then assume that was the name of the listener function.
- Parameters:
- {String} event_name
listenForEvent(event_source, event_name, use_capture, onEvent_name)
Causes the listener to "subscribe" for events of type event_name which are published
by event_source, assuming that event_source is an Event.Publisher.
- Parameters:
- {Object} event_source
- the object which will generate the events, and which implements (or mixes in) the Event.Publisher interface (we need addEventListener)
- {String} event_name
- the name of the event for which your object will listen
- {Boolean} use_capture
- standard DOM Event API param
- {String} onEvent_name
- the name of the method in your object which will be called when the event is received if you omit this param, listen will look for a function named with the CapitalizedCamelCased name of the event with "on" at the front. So, if the event is named "message_received", we'll look for a function named "onMessageReceived" You can override this behavior by overriding getEventHandlerName in your object.
stopListeningForEvent(event_source, event_name, use_capture, onEvent_name)
Unsubscribe the current listener from the events of type
event_name published by event_source.
- Parameters:
- {Object} event_source
- {String} event_name
- {Boolean} use_capture
- {String} onEvent_name