events.js
Event Manager. Provides an abstracted interface to the browsers' event systems. This uses an indirect lookup of listener functions to avoid circular references between DOM (in IE) or XPCOM (in Mozilla) objects which leak memory. This makes it easier to write OO Javascript/DOM code. It simulates capture & bubble in Internet Explorer. The listeners will also automagically have their event objects patched, so your handlers don't need to worry about the browser. Example usage:
 goog.events.listen(myNode, 'click', function(e) { alert('woo') });
 goog.events.listen(myNode, 'mouseover', mouseHandler, true);
 goog.events.unlisten(myNode, 'mouseover', mouseHandler, true);
 goog.events.removeAll(myNode);
 goog.events.removeAll();
 
in IE and event object patching]

File Location

events/events.js


Public Protected Private

Global Functions

goog.events.cleanUp_(typecapturesrcUidlistenerArray)
Cleans up the listener array as well as the listener tree
Arguments:
type :
The type of the event.
capture :
Whether to clean up capture phase listeners instead bubble phase listeners.
srcUid :
The unique ID of the source.
listenerArray :
(Array | null)
The array being cleaned.
code »
goog.events.dispatchEvent(srce)
Dispatches an event (or event like object) and calls all listeners listening for events of this type. The type of the event is decided by the type property on the event object. If any of the listeners returns false OR calls preventDefault then this function will return false. If one of the capture listeners calls stopPropagation, then the bubble listeners won't fire.
Arguments:
src :
The event target.
e :
(Object | goog.events.Event | null | string)
Event object.
Returns:   If anyone called preventDefault on the event object (or if any of the handlers returns false) this will also return false. If there are no handlers, or if all handlers return true, this returns true.
code »
goog.events.expose(e)
Provides a nice string showing the normalized event objects public members
Arguments:
e :
(Object | null)
Event Object.
Returns:   String of the public members of the normalized event object.
code »
goog.events.fireListener(listenereventObject)
Fires a listener with a set of arguments
Arguments:
listener :
The listener object to call.
eventObject :
(Object | null)
The event object to pass to the listener.
Returns:   Result of listener.
code »
goog.events.fireListeners(objtypecaptureeventObject)
Fires an object's listeners of a particular type and phase
Arguments:
obj :
(Object | null)
Object whose listeners to call.
type :
Event type.
capture :
Which event phase.
eventObject :
(Object | null)
Event object to be passed to listener.
Returns:   True if all listeners returned true else false.
code »
goog.events.fireListeners_(mapobjtypecaptureeventObject)
Fires an object's listeners of a particular type and phase.
Arguments:
map :
(Object | null)
Object with listeners in it.
obj :
(Object | null)
Object whose listeners to call.
type :
Event type.
capture :
Which event phase.
eventObject :
(Object | null)
Event object to be passed to listener.
Returns:   True if all listeners returned true else false.
code »
goog.events.getListener(srctypelisteneropt_captopt_handler)
Gets the goog.events.Listener for the event or null if no such listener is in use.
Arguments:
src :
(EventTarget | goog.events.EventTarget | null)
The node from which to get listeners.
type :
(null | string)
The name of the event without the 'on' prefix.
listener :
(Object | null)
The listener function to get.
opt_capt :
(boolean | undefined)
In DOM-compliant browsers, this determines whether the listener is fired during the capture or bubble phase of the event.
opt_handler :
(Object | null | undefined)
Element in whose scope to call the listener.
Returns:   the found listener or null if not found.
code »
goog.events.getListeners(objtypecapture)
(Array | null)
Gets the listeners for a given object, type and capture phase.
Arguments:
obj :
(Object | null)
Object to get listeners for.
type :
Event type.
capture :
Capture phase?.
Returns: 
(Array | null)
  Array of listener objects.
code »
goog.events.getListeners_(objtypecapture)
(Array | null)
Gets the listeners for a given object, type and capture phase.
Arguments:
obj :
(Object | null)
Object to get listeners for.
type :
(null | string)
Event type.
capture :
Capture phase?.
Returns: 
(Array | null)
  Array of listener objects. Returns null if object has no listeners of that type.
code »
goog.events.getOnString_(type)
Returns a string wth on prepended to the specified type. This is used for IE which expects "on" to be prepended. This function caches the string in order to avoid extra allocations in steady state.
Arguments:
type :
Event type strng.
Returns:   The type string with 'on' prepended.
code »
goog.events.getProxy()
(Function | null)
Helper function for returning a proxy function.
Returns: 
(Function | null)
  A new or reused function object.
code »
goog.events.getTotalListenerCount()
Gets the total number of listeners currently in the system.
Returns:   Number of listeners.
code »
goog.events.getUniqueId(identifier)
Creates a unique event id.
Arguments:
identifier :
The identifier.
Returns:   A unique identifier.
code »
goog.events.handleBrowserEvent_(keyopt_evt)
Handles an event and dispatches it to the correct listeners. This function is a proxy for the real listener the user specified.
Arguments:
key :
Unique key for the listener.
opt_evt :
(Event | null | undefined)
Optional event object that gets passed in via the native event handlers.
Returns:   Result of the event handler.
code »
goog.events.hasListener(objopt_typeopt_capture)
Returns whether an event target has any active listeners matching the specified signature. If either the type or capture parameters are unspecified, the function will match on the remaining criteria.
Arguments:
obj :
(EventTarget | goog.events.EventTarget | null)
Target to get listeners for.
opt_type :
(string | undefined)
Event type.
opt_capture :
(boolean | undefined)
Whether to check for capture or bubble-phase listeners.
Returns:   Whether an event target has one or more listeners matching the requested type and/or capture phase.
code »
goog.events.isMarkedIeEvent_(e)
This is used to check if an IE event has already been handled by the Closure system so we do not do the Closure pass twice for a bubbling event.
Arguments:
e :
(Event | null)
The IE browser event.
Returns:   True if the event object has been marked.
code »
goog.events.listen(srctypelisteneropt_captopt_handler)
(null | number)
Adds an event listener for a specific event on a DOM Node or an object that has implemented goog.events.EventTarget. A listener can only be added once to an object and if it is added again the key for the listener is returned.
Arguments:
src :
(EventTarget | goog.events.EventTarget | null)
The node to listen to events on.
type :
(Array | null | string)
Event type or array of event types.
listener :
(Object | null)
Callback method, or an object with a handleEvent function.
opt_capt :
(boolean | undefined)
Whether to fire in capture phase (defaults to false).
opt_handler :
(Object | null | undefined)
Element in whose scope to call the listener.
Returns: 
(null | number)
  Unique key for the listener.
code »
goog.events.listenOnce(srctypelisteneropt_captopt_handler)
(null | number)
Adds an event listener for a specific event on a DomNode or an object that has implemented goog.events.EventTarget. After the event has fired the event listener is removed from the target.
Arguments:
src :
(EventTarget | goog.events.EventTarget | null)
The node to listen to events on.
type :
(Array | null | string)
Event type or array of event types.
listener :
(Object | null)
Callback method.
opt_capt :
(boolean | undefined)
Fire in capture phase?.
opt_handler :
(Object | null | undefined)
Element in whose scope to call the listener.
Returns: 
(null | number)
  Unique key for the listener.
code »
goog.events.listenWithWrapper(srcwrapperlisteneropt_captopt_handler)
Adds an event listener with a specific event wrapper on a DOM Node or an object that has implemented goog.events.EventTarget. A listener can only be added once to an object.
Arguments:
src :
(EventTarget | goog.events.EventTarget | null)
The node to listen to events on.
wrapper :
Event wrapper to use.
listener :
(Object | null)
Callback method, or an object with a handleEvent function.
opt_capt :
(boolean | undefined)
Whether to fire in capture phase (defaults to false).
opt_handler :
(Object | null | undefined)
Element in whose scope to call the listener.
code »
goog.events.markIeEvent_(e)
This is used to mark the IE event object so we do not do the Closure pass twice for a bubbling event.
Arguments:
e :
(Event | null)
The IE browser event.
code »
goog.events.protectBrowserEventEntryPoint(errorHandler)
Installs exception protection for the browser event entry point using the given error handler.
Arguments:
errorHandler :
Error handler with which to protect the entry point.
code »
goog.events.removeAll(opt_objopt_typeopt_capt)
Removes all listeners from an object, if no object is specified it will remove all listeners that have been registered. You can also optionally remove listeners of a particular type or capture phase.
Arguments:
opt_obj :
(Object | null | undefined)
Object to remove listeners from.
opt_type :
(string | undefined)
Type of event to, default is all types.
opt_capt :
(boolean | undefined)
Whether to remove the listeners from the capture or bubble phase. If unspecified, will remove both.
Returns:   Number of listeners removed.
code »
goog.events.unlisten(srctypelisteneropt_captopt_handler)
(boolean | null)
Removes an event listener which was added with listen().
Arguments:
src :
(EventTarget | goog.events.EventTarget | null)
The target to stop listening to events on.
type :
(Array | null | string)
The name of the event without the 'on' prefix.
listener :
(Object | null)
The listener function to remove.
opt_capt :
(boolean | undefined)
In DOM-compliant browsers, this determines whether the listener is fired during the capture or bubble phase of the event.
opt_handler :
(Object | null | undefined)
Element in whose scope to call the listener.
Returns: 
(boolean | null)
  indicating whether the listener was there to remove.
code »
goog.events.unlistenByKey(key)
Removes an event listener which was added with listen() by the key returned by listen().
Arguments:
key :
(null | number)
The key returned by listen() for this event listener.
Returns:   indicating whether the listener was there to remove.
code »
goog.events.unlistenWithWrapper(srcwrapperlisteneropt_captopt_handler)
Removes an event listener which was added with listenWithWrapper().
Arguments:
src :
(EventTarget | goog.events.EventTarget | null)
The target to stop listening to events on.
wrapper :
Event wrapper to use.
listener :
(Object | null)
The listener function to remove.
opt_capt :
(boolean | undefined)
In DOM-compliant browsers, this determines whether the listener is fired during the capture or bubble phase of the event.
opt_handler :
(Object | null | undefined)
Element in whose scope to call the listener.
code »

Global Properties

goog.events.keySeparator_ :
Separator used to split up the various parts of an event key, to help avoid the possibilities of collisions.
Code »
goog.events.listenerTree_ :
(Object | null)
The root of the listener tree
Code »
goog.events.listeners_ :
(Object | null)
Container for storing event listeners and their proxies
Code »
goog.events.onStringMap_ :
(Object | null)
Map of computed on strings for IE event types. Caching this removes an extra object allocation in goog.events.listen which improves IE6 performance.
Code »
goog.events.onString_ :
String used to prepend to IE event types. Not a constant so that it is not inlined.
Code »
goog.events.sources_ :
(Object | null)
Lookup for mapping source UIDs to listeners.
Code »
goog.events.uniqueIdCounter_ :
Counter to create unique event ids.
Code »

Directory events

File Reference