Interface goog.events.Listenable
code »A listenable interface. A listenable is an object with the ability
to dispatch/broadcast events to "event listeners" registered via
listen/listenOnce.
The interface allows for an event propagation mechanism similar
to one offered by native browser event targets, such as
capture/bubble mechanism, stopping propagation, and preventing
default actions. Capture/bubble mechanism depends on the ancestor
tree constructed via #getParentEventTarget
; this tree
must be directed acyclic graph. The meaning of default action(s)
in preventDefault is specific to a particular use case.
Implementations that do not support capture/bubble or can not have
a parent listenable can simply not implement any ability to set the
parent listenable (and have #getParentEventTarget
return
null).
Implementation of this class can be used with or independently from
goog.events.
Implementation must call #addImplementation(implClass)
.
Instance Methods
code »dispatchEvent ( e ) ⇒ boolean
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.
boolean
Parameters |
---|
|
Returns |
|
Fires all registered listeners in this listenable for the given
type and capture mode, passing them the given eventObject. This
does not perform actual capture/bubble. Only implementors of the
interface should be using this.
Parameters |
---|
|
Returns |
|
code »<SCOPE, EVENTOBJ>
getListener ( type, listener, capture, opt_listenerScope ) ⇒ goog.events.ListenableKey
Gets the goog.events.ListenableKey for the event or null if no such
listener is in use.
<SCOPE, EVENTOBJ>
getListener ( type, listener, capture, opt_listenerScope ) ⇒ goog.events.ListenableKey
Parameters |
---|
|
Returns |
|
Gets all listeners in this listenable for the given type and
capture mode.
Parameters |
---|
|
Returns |
|
Returns the parent of this event target to use for capture/bubble
mechanism.
NOTE(user): The name reflects the original implementation of
custom event target (goog.events.EventTarget
). We decided
that changing the name is not worth it.
goog.events.EventTarget
). We decided
that changing the name is not worth it.Returns |
---|
|
Whether there is any active listeners matching the specified
signature. If either the type or capture parameters are
unspecified, the function will match on the remaining criteria.
Parameters |
---|
|
Returns |
|
code »<SCOPE, EVENTOBJ>
listen ( type, listener, opt_useCapture, opt_listenerScope ) ⇒ goog.events.ListenableKey
Adds an event listener. A listener can only be added once to an
object and if it is added again the key for the listener is
returned. Note that if the existing listener is a one-off listener
(registered via listenOnce), it will no longer be a one-off
listener after a call to listen().
<SCOPE, EVENTOBJ>
listen ( type, listener, opt_useCapture, opt_listenerScope ) ⇒ goog.events.ListenableKey
Parameters |
---|
|
Returns |
|
code »<SCOPE, EVENTOBJ>
listenOnce ( type, listener, opt_useCapture, opt_listenerScope ) ⇒ goog.events.ListenableKey
Adds an event listener that is removed automatically after the
listener fired once.
If an existing listener already exists, listenOnce will do
nothing. In particular, if the listener was previously registered
via listen(), listenOnce() will not turn the listener into a
one-off listener. Similarly, if there is already an existing
one-off listener, listenOnce does not modify the listeners (it is
still a once listener).
<SCOPE, EVENTOBJ>
listenOnce ( type, listener, opt_useCapture, opt_listenerScope ) ⇒ goog.events.ListenableKey
Parameters |
---|
|
Returns |
|
code »removeAllListeners ( opt_type ) ⇒ number
Removes all listeners from this listenable. If type is specified,
it will only remove listeners of the particular type. otherwise all
registered listeners will be removed.
number
Parameters |
---|
|
Returns |
|
Removes an event listener which was added with listen() or listenOnce().
Parameters |
---|
|
Returns |
|
code »unlistenByKey ( key ) ⇒ boolean
Removes an event listener which was added with listen() by the key
returned by listen().
boolean
Parameters |
---|
|
Returns |
|
Global Functions
Marks a given class (constructor) as an implementation of
Listenable, do that we can query that fact at runtime. The class
must have already implemented the interface.
Parameters |
---|
|
Parameters |
---|
|
Returns |
|