An implementation of goog.events.Listenable with full W3C
EventTarget-like support (capture/bubble mechanism, stopping event
propagation, preventing default actions).
You may subclass this class to turn your class into a Listenable.
Unless propagation is stopped, an event dispatched by an
EventTarget will bubble to the parent returned by
getParentEventTarget. To set the parent, call
setParentEventTarget. Subclasses that don't support
changing the parent can override the setter to throw an error.
Example usage:
var source = new goog.events.EventTarget();
function handleEvent(e) {
alert('Type: ' + e.type + '; Target: ' + e.target);
}
source.listen('foo', handleEvent);
// Or: goog.events.listen(source, 'foo', handleEvent);
...
source.dispatchEvent('foo'); // will call handleEvent
...
source.unlisten('foo', handleEvent);
// Or: goog.events.unlisten(source, 'foo', handleEvent);
Deprecated: Use #listen instead, when possible. Otherwise, use
goog.events.listen if you are passing Object
(instead of Function) as handler.
Adds an event listener to the event target. The same handler can only be
added once per the type. Even if you add the same handler multiple times
using the same type then it will only be called once when the event is
dispatched.
Removes listeners from this object. Classes that extend EventTarget may
need to override this method in order to remove references to DOM Elements
and additional listeners.
Deprecated: Use #unlisten instead, when possible. Otherwise, use
goog.events.unlisten if you are passing Object
(instead of Function) as handler.
Removes an event listener from the event target. The handler must be the
same object as the one added. If the handler has not been added then
nothing is done.
Disposes of the object. If the object hasn't already been disposed of, calls
#disposeInternal. Classes that extend goog.Disposable should
override #disposeInternal in order to delete references to COM
objects, DOM nodes, and other disposable objects. Reentrant.
Parent event target, used during event bubbling.
TODO(user): Change this to goog.events.Listenable. This
currently breaks people who expect getParentEventTarget to return
goog.events.EventTarget.