OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview EventTracker is a simple class that manages the addition and | 6 * @fileoverview EventTracker is a simple class that manages the addition and |
7 * removal of DOM event listeners. In particular, it keeps track of all | 7 * removal of DOM event listeners. In particular, it keeps track of all |
8 * listeners that have been added and makes it easy to remove some or all of | 8 * listeners that have been added and makes it easy to remove some or all of |
9 * them without requiring all the information again. This is particularly handy | 9 * them without requiring all the information again. This is particularly handy |
10 * when the listener is a generated function such as a lambda or the result of | 10 * when the listener is a generated function such as a lambda or the result of |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 /** | 25 /** |
26 * Create an EventTracker to track a set of events. | 26 * Create an EventTracker to track a set of events. |
27 * EventTracker instances are typically tied 1:1 with other objects or | 27 * EventTracker instances are typically tied 1:1 with other objects or |
28 * DOM elements whose listeners should be removed when the object is disposed | 28 * DOM elements whose listeners should be removed when the object is disposed |
29 * or the corresponding elements are removed from the DOM. | 29 * or the corresponding elements are removed from the DOM. |
30 * @constructor | 30 * @constructor |
31 */ | 31 */ |
32 function EventTracker() { | 32 function EventTracker() { |
33 /** | 33 /** |
34 * @type {Array.<EventTrackerEntry>} | 34 * @type {Array<EventTrackerEntry>} |
35 * @private | 35 * @private |
36 */ | 36 */ |
37 this.listeners_ = []; | 37 this.listeners_ = []; |
38 } | 38 } |
39 | 39 |
40 EventTracker.prototype = { | 40 EventTracker.prototype = { |
41 /** | 41 /** |
42 * Add an event listener - replacement for EventTarget.addEventListener. | 42 * Add an event listener - replacement for EventTarget.addEventListener. |
43 * @param {!EventTarget} target The DOM target to add a listener to. | 43 * @param {!EventTarget} target The DOM target to add a listener to. |
44 * @param {string} eventType The type of event to subscribe to. | 44 * @param {string} eventType The type of event to subscribe to. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 | 83 |
84 /** | 84 /** |
85 * Remove a single event listener given it's tracking entry. It's up to the | 85 * Remove a single event listener given it's tracking entry. It's up to the |
86 * caller to ensure the entry is removed from listeners_. | 86 * caller to ensure the entry is removed from listeners_. |
87 * @param {EventTrackerEntry} h The entry describing the listener to remove. | 87 * @param {EventTrackerEntry} h The entry describing the listener to remove. |
88 * @private | 88 * @private |
89 */ | 89 */ |
90 EventTracker.removeEventListener_ = function(h) { | 90 EventTracker.removeEventListener_ = function(h) { |
91 h.target.removeEventListener(h.eventType, h.listener, h.capture); | 91 h.target.removeEventListener(h.eventType, h.listener, h.capture); |
92 }; | 92 }; |
OLD | NEW |