The goog.events Namespace

The goog.events.ActionEvent Class

This class is used for the goog.events.ActionHandler.EventType.ACTION event. … more

The goog.events.ActionHandler Class

A wrapper around an element that you want to listen to ACTION events on. … more

The goog.events.BeforeActionEvent Class

This class is used for the goog.events.ActionHandler.EventType.BEFOREACTION event. BEFOREACTION gives a chance to the application so the keyboard focus can be restored back, if required. … more

The goog.events.BrowserEvent Class

Accepts a browser event object and creates a patched, cross browser event object. The content of this object will not be initialized if no event object is provided. If this is the case, init() needs to be invoked separately. … more

The goog.events.BrowserFeature Enum

Enum of browser capabilities. … more

The goog.events.Event Class

A base class for event objects, so that they can support preventDefault and stopPropagation. … more

The goog.events.EventHandler Class

Super class for objects that want to easily manage a number of event listeners. It allows a short cut to listen and also provides a quick way to remove all events listeners belonging to this object. … more

The goog.events.EventTarget Class

Inherit from this class to give your object the ability to dispatch events. Note that this class provides event sending behaviour, not event receiving behaviour: your object will be able to broadcast events, and other objects will be able to listen for those events using goog.events.listen().

The name "EventTarget" reflects the fact that this class implements the EventTarget interface as defined by W3C DOM 2/3, with a few differences:

Unless propagation is stopped, an event dispatched by an EventTarget will bubble to the parent returned by getParentEventTarget. To set the parent, call setParentEventTarget or override getParentEventTarget in a subclass. Subclasses that don't support changing the parent should override the setter to throw an error.

Example usage:

   var source = new goog.events.EventTarget();
   function handleEvent(event) {
     alert('Type: ' + e.type + '\nTarget: ' + e.target);
   }
   goog.events.listen(source, 'foo', handleEvent);
   ...
   source.dispatchEvent({type: 'foo'}); // will call handleEvent
   // or source.dispatchEvent('foo');
   ...
   goog.events.unlisten(source, 'foo', handleEvent);

   // You can also use the Listener interface:
   var listener = {
     handleEvent: function(event) {
       ...
     }
   };
   goog.events.listen(source, 'bar', listener);
 
… more

The goog.events.EventType Enum

Constants for event names. … more

The goog.events.EventWrapper Interface

Interface for event wrappers. @interface … more

The goog.events.FileDropHandler Class

A files drag and drop event detector. Gets an {@code element} as parameter and fires {@code goog.events.FileDropHandler.EventType.DROP} event when files are dropped in the {@code element}. … more

The goog.events.FocusHandler Class

This event handler allows you to catch focus events when descendants gain or loses focus. … more

The goog.events.ImeHandler Class

Dispatches high-level events for IMEs. … more

The goog.events.InputHandler Class

This event handler will dispatch events when the user types into a text input, password input or a textarea … more

The goog.events.KeyCodes Enum

Key codes for common characters. This list is not localized and therefore some of the key codes are not correct for non US keyboard layouts. See comments below. … more

The goog.events.KeyEvent Class

This class is used for the goog.events.KeyHandler.EventType.KEY event and it overrides the key code with the fixed key code. … more

The goog.events.KeyHandler Class

A wrapper around an element that you want to listen to keyboard events on. … more

.KeyNames

Key names for common characters. This list is not localized and therefore some of the key codes are not correct for non-US keyboard layouts.

@see
goog.events.KeyCodes
@enum
{string}

The goog.events.Listener Class

Simple class that stores information about a listener … more

The goog.events.MouseWheelEvent Class

A base class for mouse wheel events. This is used with the MouseWheelHandler. … more

The goog.events.MouseWheelHandler Class

This event handler allows you to catch mouse wheel events in a consistent manner. … more

The goog.events.OnlineHandler Class

Basic object for detecting whether the online state changes. … more

The goog.events.PasteHandler Class

A paste event detector. Gets an {@code element} as parameter and fires {@code goog.events.PasteHandler.EventType.PASTE} events when text is pasted in the {@code element}. Uses heuristics to detect paste events in FF2. See more details of the heuristic on {@link #handleEvent_}. … more

.actionEventWrapper {goog.events.ActionEventWrapper_}

Singleton instance of ActionEventWrapper_.

.dispatchEvent(src, e)

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.

src {goog.events.EventTarget}
The event target.
e {string|Object|goog.events.Event}
Event object.
returns {boolean}
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.

.expose(e)

Provides a nice string showing the normalized event objects public members

e {Object}
Event Object.
returns {string}
String of the public members of the normalized event object.

.fireListener(listener, eventObject)

Fires a listener with a set of arguments

listener {goog.events.Listener}
The listener object to call.
eventObject {Object}
The event object to pass to the listener.
returns {boolean}
Result of listener.

.fireListeners(obj, type, capture, eventObject)

Fires an object's listeners of a particular type and phase

obj {Object}
Object whose listeners to call.
type {string}
Event type.
capture {boolean}
Which event phase.
eventObject {Object}
Event object to be passed to listener.
returns {boolean}
True if all listeners returned true else false.

.getListener(src, type, listener, opt_capt, opt_handler)

Gets the goog.events.Listener for the event or null if no such listener is in use.

src {EventTarget|goog.events.EventTarget}
The node from which to get listeners.
type {?string}
The name of the event without the 'on' prefix.
listener {Function|Object}
The listener function to get.
opt_capt {boolean=}
In DOM-compliant browsers, this determines whether the listener is fired during the capture or bubble phase of the event.
opt_handler {Object=}
Element in whose scope to call the listener.
returns {goog.events.Listener?}
the found listener or null if not found.

.getListeners(obj, type, capture)

Gets the listeners for a given object, type and capture phase.

obj {Object}
Object to get listeners for.
type {string}
Event type.
capture {boolean}
Capture phase?.
returns {Array.<goog.events.Listener>}
Array of listener objects.

.getProxy()

Helper function for returning a proxy function.

returns {Function}
A new or reused function object.

.getTotalListenerCount()

Gets the total number of listeners currently in the system.

returns {number}
Number of listeners.

.getUniqueId(identifier)

Creates a unique event id.

identifier {string}
The identifier.
returns {string}
A unique identifier.

.hasListener(obj, opt_type, opt_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.

obj {EventTarget|goog.events.EventTarget}
Target to get listeners for.
opt_type {string=}
Event type.
opt_capture {boolean=}
Whether to check for capture or bubble-phase listeners.
returns {boolean}
Whether an event target has one or more listeners matching the requested type and/or capture phase.

.listen(src, type, listener, opt_capt, opt_handler)

Adds an event listener for a specific event on a DOM Node or an object that has implemented {@link 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.

src {EventTarget|goog.events.EventTarget}
The node to listen to events on.
type {string|Array.<string>}
Event type or array of event types.
listener {Function|Object}
Callback method, or an object with a handleEvent function.
opt_capt {boolean=}
Whether to fire in capture phase (defaults to false).
opt_handler {Object=}
Element in whose scope to call the listener.
returns {?number}
Unique key for the listener.

.listenOnce(src, type, listener, opt_capt, opt_handler)

Adds an event listener for a specific event on a DomNode or an object that has implemented {@link goog.events.EventTarget}. After the event has fired the event listener is removed from the target.

src {EventTarget|goog.events.EventTarget}
The node to listen to events on.
type {string|Array.<string>}
Event type or array of event types.
listener {Function|Object}
Callback method.
opt_capt {boolean=}
Fire in capture phase?.
opt_handler {Object=}
Element in whose scope to call the listener.
returns {?number}
Unique key for the listener.

.listenWithWrapper(src, wrapper, listener, opt_capt, opt_handler)

Adds an event listener with a specific event wrapper on a DOM Node or an object that has implemented {@link goog.events.EventTarget}. A listener can only be added once to an object.

src {EventTarget|goog.events.EventTarget}
The node to listen to events on.
wrapper {goog.events.EventWrapper}
Event wrapper to use.
listener {Function|Object}
Callback method, or an object with a handleEvent function.
opt_capt {boolean=}
Whether to fire in capture phase (defaults to false).
opt_handler {Object=}
Element in whose scope to call the listener.

.protectBrowserEventEntryPoint(errorHandler)

Installs exception protection for the browser event entry point using the given error handler.

errorHandler {goog.debug.ErrorHandler}
Error handler with which to protect the entry point.

.removeAll(opt_obj, opt_type, opt_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.

opt_obj {Object=}
Object to remove listeners from.
opt_type {string=}
Type of event to, default is all types.
opt_capt {boolean=}
Whether to remove the listeners from the capture or bubble phase. If unspecified, will remove both.
returns {number}
Number of listeners removed.

.unlisten(src, type, listener, opt_capt, opt_handler)

Removes an event listener which was added with listen().

src {EventTarget|goog.events.EventTarget}
The target to stop listening to events on.
type {string|Array.<string>}
The name of the event without the 'on' prefix.
listener {Function|Object}
The listener function to remove.
opt_capt {boolean=}
In DOM-compliant browsers, this determines whether the listener is fired during the capture or bubble phase of the event.
opt_handler {Object=}
Element in whose scope to call the listener.
returns {?boolean}
indicating whether the listener was there to remove.

.unlistenByKey(key)

Removes an event listener which was added with listen() by the key returned by listen().

key {?number}
The key returned by listen() for this event listener.
returns {boolean}
indicating whether the listener was there to remove.

.unlistenWithWrapper(src, wrapper, listener, opt_capt, opt_handler)

Removes an event listener which was added with listenWithWrapper().

src {EventTarget|goog.events.EventTarget}
The target to stop listening to events on.
wrapper {goog.events.EventWrapper}
Event wrapper to use.
listener {Function|Object}
The listener function to remove.
opt_capt {boolean=}
In DOM-compliant browsers, this determines whether the listener is fired during the capture or bubble phase of the event.
opt_handler {Object=}
Element in whose scope to call the listener.