| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <!-- | 2 <!-- |
| 3 Copyright (c) 2014 The Chromium Authors. All rights reserved. | 3 Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 4 Use of this source code is governed by a BSD-style license that can be | 4 Use of this source code is governed by a BSD-style license that can be |
| 5 found in the LICENSE file. | 5 found in the LICENSE file. |
| 6 --> | 6 --> |
| 7 | 7 |
| 8 <link rel="import" href="/tracing/base/base.html"> | 8 <link rel="import" href="/tracing/base/base.html"> |
| 9 | 9 |
| 10 <script> | 10 <script> |
| 11 'use strict'; | 11 'use strict'; |
| 12 | 12 |
| 13 /** | 13 /** |
| 14 * @fileoverview This contains an implementation of the EventTarget interface | 14 * @fileoverview This contains an implementation of the EventTarget interface |
| 15 * as defined by DOM Level 2 Events. | 15 * as defined by DOM Level 2 Events. |
| 16 */ | 16 */ |
| 17 tr.exportTo('tr.b', function() { | 17 tr.exportTo('tr.b', function() { |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * Creates a new EventTarget. This class implements the DOM level 2 | 20 * Creates a new EventTarget. This class implements the DOM level 2 |
| 21 * EventTarget interface and can be used wherever those are used. | 21 * EventTarget interface and can be used wherever those are used. |
| 22 * @constructor | 22 * @constructor |
| 23 */ | 23 */ |
| 24 function EventTarget() { | 24 function EventTarget() { |
| 25 } | 25 } |
| 26 EventTarget.decorate = function(target) { | 26 EventTarget.decorate = function(target) { |
| 27 for (var k in EventTarget.prototype) { | 27 for (var k in EventTarget.prototype) { |
| 28 if (k == 'decorate') | 28 if (k === 'decorate') |
| 29 continue; | 29 continue; |
| 30 var v = EventTarget.prototype[k]; | 30 var v = EventTarget.prototype[k]; |
| 31 if (typeof v !== 'function') | 31 if (typeof v !== 'function') |
| 32 continue; | 32 continue; |
| 33 target[k] = v; | 33 target[k] = v; |
| 34 } | 34 } |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 EventTarget.prototype = { | 37 EventTarget.prototype = { |
| 38 | 38 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 61 * event. | 61 * event. |
| 62 */ | 62 */ |
| 63 removeEventListener: function(type, handler) { | 63 removeEventListener: function(type, handler) { |
| 64 if (!this.listeners_) | 64 if (!this.listeners_) |
| 65 return; | 65 return; |
| 66 if (type in this.listeners_) { | 66 if (type in this.listeners_) { |
| 67 var handlers = this.listeners_[type]; | 67 var handlers = this.listeners_[type]; |
| 68 var index = handlers.indexOf(handler); | 68 var index = handlers.indexOf(handler); |
| 69 if (index >= 0) { | 69 if (index >= 0) { |
| 70 // Clean up if this was the last listener. | 70 // Clean up if this was the last listener. |
| 71 if (handlers.length == 1) | 71 if (handlers.length === 1) |
| 72 delete this.listeners_[type]; | 72 delete this.listeners_[type]; |
| 73 else | 73 else |
| 74 handlers.splice(index, 1); | 74 handlers.splice(index, 1); |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 }, | 77 }, |
| 78 | 78 |
| 79 /** | 79 /** |
| 80 * Dispatches an event and calls all the listeners that are listening to | 80 * Dispatches an event and calls all the listeners that are listening to |
| 81 * the type of the event. | 81 * the type of the event. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 }, | 116 }, |
| 117 | 117 |
| 118 hasEventListener: function(type) { | 118 hasEventListener: function(type) { |
| 119 return this.listeners_[type] !== undefined; | 119 return this.listeners_[type] !== undefined; |
| 120 } | 120 } |
| 121 }; | 121 }; |
| 122 | 122 |
| 123 var EventTargetHelper = { | 123 var EventTargetHelper = { |
| 124 decorate: function(target) { | 124 decorate: function(target) { |
| 125 for (var k in EventTargetHelper) { | 125 for (var k in EventTargetHelper) { |
| 126 if (k == 'decorate') | 126 if (k === 'decorate') |
| 127 continue; | 127 continue; |
| 128 var v = EventTargetHelper[k]; | 128 var v = EventTargetHelper[k]; |
| 129 if (typeof v !== 'function') | 129 if (typeof v !== 'function') |
| 130 continue; | 130 continue; |
| 131 target[k] = v; | 131 target[k] = v; |
| 132 } | 132 } |
| 133 target.listenerCounts_ = {}; | 133 target.listenerCounts_ = {}; |
| 134 }, | 134 }, |
| 135 | 135 |
| 136 addEventListener: function(type, listener, useCapture) { | 136 addEventListener: function(type, listener, useCapture) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 152 } | 152 } |
| 153 }; | 153 }; |
| 154 | 154 |
| 155 // Export | 155 // Export |
| 156 return { | 156 return { |
| 157 EventTarget: EventTarget, | 157 EventTarget: EventTarget, |
| 158 EventTargetHelper: EventTargetHelper | 158 EventTargetHelper: EventTargetHelper |
| 159 }; | 159 }; |
| 160 }); | 160 }); |
| 161 </script> | 161 </script> |
| OLD | NEW |