selenium-webdriver
Version:
The official WebDriver JavaScript bindings from the Selenium project
68 lines (64 loc) • 24.9 kB
HTML
<meta charset="UTF-8"><meta http-equiv="Content-Language" content="en" /><title>goog.events.EventTarget</title><link href="dossier.css" rel="stylesheet" type="text/css"><div id="main-wrapper"><input type="checkbox" id="sidenav-toggle" /><main><header><h1>Class goog.events.EventTarget</h1><a class="source" href="source/lib/goog/events/eventtarget.js.src.html#l70">code »</a><pre><code><a href="class_goog_Disposable.html">goog.Disposable</a>
└ goog.events.EventTarget</code></pre><dl><dt>All implemented interfaces:<dd><code><a href="interface_goog_disposable_IDisposable.html">goog.disposable.IDisposable</a></code>, <code><a href="interface_goog_events_Listenable.html">goog.events.Listenable</a></code></dl></header><section><p>An implementation of <code >goog.events.Listenable</code> 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
<code >getParentEventTarget</code>. To set the parent, call
<code >setParentEventTarget</code>. Subclasses that don't support
changing the parent can override the setter to throw an error.
Example usage:
<pre>
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);
</pre><h2>Constructor</h2><div class="ctor wrap-details public"><div><div class="ctor"><span class="member">goog.events.EventTarget <span class="args">( )</span></span></div></div></div></section><div id="visibility-controls"><b>Show:</b><label for="show-public"><span><input type="checkbox" id="show-public" checked/></span>Public</label><label for="show-protected"><span><input type="checkbox" id="show-protected"/></span>Protected</label><label for="show-private"><span><input type="checkbox" id="show-private"/></span>Private</label></div><section id="instance-methods"><h2>Instance Methods</h2><h3>Defined in <code class="type">goog.events.EventTarget</code></h3><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/events/eventtarget.js.src.html#l151">code »</a><span class="member deprecation-notice"><a name="addEventListener">addEventListener</a> <span class="args">( type, handler, opt_capture, opt_handlerScope )</span></span></div><div class="deprecation-notice">Deprecated: <span class="deprecation-reason">Use <code >#listen</code> instead, when possible. Otherwise, use
<code >goog.events.listen</code> if you are passing Object
(instead of Function) as handler.</span></div><p>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.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>type: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code><dd>The type of the event to listen for.<dt>handler: <code class="type">(function(?): ?|{handleEvent: function(?): ?}|<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Null">null</a>)</code><dd>The function
to handle the event. The handler can also be an object that implements
the handleEvent method which takes the event object as argument.<dt>opt_capture: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a>=</code><dd>In DOM-compliant browsers, this determines
whether the listener is fired during the capture or bubble phase
of the event.<dt>opt_handlerScope: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>=</code><dd>Object in whose scope to call
the listener.</dl></table></div></details></div></div><div class="wrap-details private"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/events/eventtarget.js.src.html#l330">code »</a><span class="member"><a name="assertInitialized_">assertInitialized_</a> <span class="args">( )</span></span></div><p>Asserts that the event target instance is initialized properly.</summary></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/events/eventtarget.js.src.html#l182">code »</a><span class="member"><a name="dispatchEvent">dispatchEvent</a> <span class="args">( e )</span> ⇒ <code class="type">boolean</code></span></div></summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>e</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/events/eventtarget.js.src.html#l208">code »</a><span class="member"><a name="disposeInternal">disposeInternal</a> <span class="args">( )</span></span></div><p>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.</summary></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/events/eventtarget.js.src.html#l262">code »</a><span class="member"><a name="fireListeners">fireListeners</a> <span class="args">( type, capture, eventObject )</span> ⇒ <code class="type">boolean</code></span></div></summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>type<dt>capture<dt>eventObject</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/events/eventtarget.js.src.html#l300">code »</a><span class="member"><a name="getListener">getListener</a> <span class="args">( type, listener, capture, opt_listenerScope )</span> ⇒ <code class="type">(goog.events.ListenableKey|null)</code></span></div></summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>type<dt>listener<dt>capture<dt>opt_listenerScope</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/events/eventtarget.js.src.html#l294">code »</a><span class="member"><a name="getListeners">getListeners</a> <span class="args">( type, capture )</span> ⇒ <code class="type">Array.<(goog.events.ListenableKey|null)></code></span></div></summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>type<dt>capture</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/events/eventtarget.js.src.html#l117">code »</a><span class="member"><a name="getParentEventTarget">getParentEventTarget</a> <span class="args">( )</span> ⇒ <code class="type"><a href="class_goog_events_EventTarget.html">goog.events.EventTarget</a></code></span></div><p>Returns the parent of this event target to use for bubbling.</summary><div class="info"><table><tbody><tr><th>Returns<tr><td><dl>The parent EventTarget or null if
there is no parent.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/events/eventtarget.js.src.html#l308">code »</a><span class="member"><a name="hasListener">hasListener</a> <span class="args">( opt_type, opt_capture )</span> ⇒ <code class="type">boolean</code></span></div></summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>opt_type<dt>opt_capture</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/events/eventtarget.js.src.html#l217">code »</a><span class="member"><a name="listen">listen</a> <span class="args">( type, listener, opt_useCapture, opt_listenerScope )</span> ⇒ <code class="type">(goog.events.ListenableKey|null)</code></span></div></summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>type<dt>listener<dt>opt_useCapture<dt>opt_listenerScope</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/events/eventtarget.js.src.html#l227">code »</a><span class="member"><a name="listenOnce">listenOnce</a> <span class="args">( type, listener, opt_useCapture, opt_listenerScope )</span> ⇒ <code class="type">(goog.events.ListenableKey|null)</code></span></div></summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>type<dt>listener<dt>opt_useCapture<dt>opt_listenerScope</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/events/eventtarget.js.src.html#l250">code »</a><span class="member"><a name="removeAllListeners">removeAllListeners</a> <span class="args">( opt_type )</span> ⇒ <code class="type">number</code></span></div></summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>opt_type</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/events/eventtarget.js.src.html#l175">code »</a><span class="member deprecation-notice"><a name="removeEventListener">removeEventListener</a> <span class="args">( type, handler, opt_capture, opt_handlerScope )</span></span></div><div class="deprecation-notice">Deprecated: <span class="deprecation-reason">Use <code >#unlisten</code> instead, when possible. Otherwise, use
<code >goog.events.unlisten</code> if you are passing Object
(instead of Function) as handler.</span></div><p>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.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>type: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code><dd>The type of the event to listen for.<dt>handler: <code class="type">(function(?): ?|{handleEvent: function(?): ?}|<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Null">null</a>)</code><dd>The function
to handle the event. The handler can also be an object that implements
the handleEvent method which takes the event object as argument.<dt>opt_capture: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a>=</code><dd>In DOM-compliant browsers, this determines
whether the listener is fired during the capture or bubble phase
of the event.<dt>opt_handlerScope: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>=</code><dd>Object in whose scope to call
the listener.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/events/eventtarget.js.src.html#l127">code »</a><span class="member"><a name="setParentEventTarget">setParentEventTarget</a> <span class="args">( parent )</span></span></div><p>Sets the parent of this event target to use for capture/bubble
mechanism.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>parent: <code class="type"><a href="class_goog_events_EventTarget.html">goog.events.EventTarget</a></code><dd>Parent listenable (null if none).</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/events/eventtarget.js.src.html#l321">code »</a><span class="member"><a name="setTargetForTesting">setTargetForTesting</a> <span class="args">( target )</span></span></div><p>Sets the target to be used for <code >event.target</code> when firing
event. Mainly used for testing. For example, see
<code >goog.testing.events.mixinListenable</code>.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>target: <code class="type">!<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a></code><dd>The target.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/events/eventtarget.js.src.html#l236">code »</a><span class="member"><a name="unlisten">unlisten</a> <span class="args">( type, listener, opt_useCapture, opt_listenerScope )</span> ⇒ <code class="type">boolean</code></span></div></summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>type<dt>listener<dt>opt_useCapture<dt>opt_listenerScope</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/events/eventtarget.js.src.html#l244">code »</a><span class="member"><a name="unlistenByKey">unlistenByKey</a> <span class="args">( key )</span> ⇒ <code class="type">boolean</code></span></div></summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>key</dl></table></div></details></div></div><h3>Defined in <code class="type"><a href="class_goog_Disposable.html">goog.Disposable</a></code></h3><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/disposable/disposable.js.src.html#l214">code »</a><code class="type"><T></code> <span class="member"><a name="addOnDisposeCallback">addOnDisposeCallback</a> <span class="args">( callback, opt_scope )</span></span></div><p>Invokes a callback function when this object is disposed. Callbacks are
invoked in the order in which they were added.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>callback: <code class="type">function(this: T): ?</code><dd>The callback function.<dt>opt_scope: <code class="type">T=</code><dd>An optional scope to call the callback in.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/disposable/disposable.js.src.html#l175">code »</a><span class="member"><a name="dispose">dispose</a> <span class="args">( )</span> ⇒ <code class="type">void</code></span></div><p>Disposes of the object. If the object hasn't already been disposed of, calls
<code class="type"><a class="unresolved-link">#disposeInternal</a></code>. Classes that extend <code >goog.Disposable</code> should
override <code class="type"><a class="unresolved-link">#disposeInternal</a></code> in order to delete references to COM
objects, DOM nodes, and other disposable objects. Reentrant.</summary><div class="info"><table><tbody><tr><th>Returns<tr><td><dl>Nothing.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/disposable/disposable.js.src.html#l163">code »</a><span class="member deprecation-notice"><a name="getDisposed">getDisposed</a> <span class="args">( )</span> ⇒ <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code></span></div><div class="deprecation-notice">Deprecated: <span class="deprecation-reason">Use <code class="type"><a class="unresolved-link">#isDisposed</a></code> instead.</span></div></summary><div class="info"><table><tbody><tr><th>Returns<tr><td><dl>Whether the object has been disposed of.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/disposable/disposable.js.src.html#l154">code »</a><span class="member"><a name="isDisposed">isDisposed</a> <span class="args">( )</span> ⇒ <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code></span></div></summary><div class="info"><table><tbody><tr><th>Returns<tr><td><dl>Whether the object has been disposed of.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/disposable/disposable.js.src.html#l202">code »</a><span class="member"><a name="registerDisposable">registerDisposable</a> <span class="args">( disposable )</span></span></div><p>Associates a disposable object with this object so that they will be disposed
together.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>disposable: <code class="type"><a href="interface_goog_disposable_IDisposable.html">goog.disposable.IDisposable</a></code><dd>that will be disposed when
this object is disposed.</dl></table></div></details></div></div></section><section id="instance-properties"><h2>Instance Properties</h2><h3>Defined in <code class="type">goog.events.EventTarget</code></h3><div class="wrap-details private"><div><details><summary><div><a class="source" href="source/lib/goog/events/eventtarget.js.src.html#l84">code »</a><span class="member"><a name="actualEventTarget_">actualEventTarget_</a> : <code class="type">!<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a></code></span></div><p>The object to use for event.target. Useful when mixing in an
EventTarget to another object.</summary></details></div></div><div class="wrap-details private"><div><details><summary><div><a class="source" href="source/lib/goog/events/eventtarget.js.src.html#l77">code »</a><span class="member"><a name="eventTargetListeners_">eventTargetListeners_</a> : <code class="type">!<a href="class_goog_events_ListenerMap.html">goog.events.ListenerMap</a></code></span></div><p>Maps of event type to an array of listeners.</summary></details></div></div><div class="wrap-details private"><div><details><summary><div><a class="source" href="source/lib/goog/events/eventtarget.js.src.html#l95">code »</a><span class="member"><a name="parentEventTarget_">parentEventTarget_</a> : <code class="type"><a href="class_goog_events_EventTarget.html">goog.events.EventTarget</a></code></span></div><p>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.</summary></details></div></div><h3>Defined in <code class="type"><a href="class_goog_Disposable.html">goog.Disposable</a></code></h3><div class="wrap-details public"><div><details><summary><div><a class="source" href="source/lib/goog/disposable/disposable.js.src.html#l147">code »</a><span class="member"><a name="creationStack">creationStack</a> : <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code></span></div><p>If monitoring the goog.Disposable instances is enabled, stores the creation
stack trace of the Disposable instance.</summary></details></div></div><div class="wrap-details private"><div><details><summary><div><a class="source" href="source/lib/goog/disposable/disposable.js.src.html#l131">code »</a><span class="member"><a name="disposed_">disposed_</a> : <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code></span></div><p>Whether the object has been disposed of.</summary></details></div></div><div class="wrap-details private"><div><details><summary><div><a class="source" href="source/lib/goog/disposable/disposable.js.src.html#l139">code »</a><span class="member"><a name="onDisposeCallbacks_">onDisposeCallbacks_</a> : <code class="type"><a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a></code></span></div><p>Callbacks to invoke when this object is disposed.</summary></details></div></div></section><section id="static-functions"><h2>Static Functions</h2><div class="wrap-details private"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/events/eventtarget.js.src.html#l350">code »</a><span class="member"><a name="goog.events.EventTarget.dispatchEventInternal_">goog.events.EventTarget.dispatchEventInternal_</a> <span class="args">( target, e, opt_ancestorsTree )</span> ⇒ <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code></span></div><p>Dispatches the given event on the ancestorsTree.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>target: <code class="type">!<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a></code><dd>The target to dispatch on.<dt>e: <code class="type">(<a href="class_goog_events_Event.html">goog.events.Event</a>|<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>|<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>)</code><dd>The event object.<dt>opt_ancestorsTree: <code class="type"><a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<<a href="interface_goog_events_Listenable.html">goog.events.Listenable</a>>=</code><dd>The ancestors
tree of the target, in reverse order from the closest ancestor
to the root event target. May be null if the target has no ancestor.</dl><tr><th>Returns<tr><td><dl>If anyone called preventDefault on the event object (or
if any of the listeners returns false) this will also return false.</dl></table></div></details></div></div></section><section id="static-properties"><h2>Static Properties</h2><div class="wrap-details private"><div><details><summary><div><a class="source" href="source/lib/goog/events/eventtarget.js.src.html#l107">code »</a><span class="member"><a name="goog.events.EventTarget.MAX_ANCESTORS_">goog.events.EventTarget.MAX_ANCESTORS_</a> : <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code></span></div><p>An artificial cap on the number of ancestors you can have. This is mainly
for loop detection.</summary></details></div></div><div class="wrap-details public"><div><details><summary><div><a class="source" href="source/lib/goog/events/eventtarget.js.src.html#l70">code »</a><span class="member"><a name="goog.events.EventTarget.superClass_">goog.events.EventTarget.superClass_</a> : <code class="type"><a href="class_goog_Disposable.html">goog.Disposable.prototype</a></code></span></div></summary></details></div></div></section></main><nav id="topnav"><div><div id="menubutton"><label for="sidenav-toggle">Menu</label></div><form id="searchbox"><div><input type="search" placeholder="Search" tabindex="1"></div></form></div></nav><nav id="sidenav"><input type="checkbox" id="sidenav-types-ctrl" /><input type="checkbox" id="sidenav-files-ctrl" /><input type="checkbox" id="sidenav-modules-ctrl" /><a id="sidenav-overview"><div><h4>Overview</h4></div></a><div id="sidenav-types"><label for="sidenav-types-ctrl"><h4>Types</h4></label><i>Loading</i></div><div id="sidenav-modules"><label for="sidenav-modules-ctrl"><h4>Modules</h4></label><i>Loading</i></div><div id="sidenav-files"><label for="sidenav-files-ctrl"><h4>Files</h4></label><i>Loading</i></div><a href="license.html"><div><h4>License</h4></div></a></nav><div id="push-footer"></div></div><footer><a href="https://github.com/jleyba/js-dossier">Generated by dossier</a></footer><script src="types.js"></script><script src="dossier.js"></script>