| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * @param {Array.<{event: string, id: string, | 8 * @param {Array<{event: string, id: string, |
| 9 * fn: function(Event):void}>} actions Array of actions to register. | 9 * fn: function(Event):void}>} actions Array of actions to register. |
| 10 */ | 10 */ |
| 11 function registerEventListeners(actions) { | 11 function registerEventListeners(actions) { |
| 12 for (var i = 0; i < actions.length; ++i) { | 12 for (var i = 0; i < actions.length; ++i) { |
| 13 var action = actions[i]; | 13 var action = actions[i]; |
| 14 registerEventListener(action.id, action.event, action.fn); | 14 registerEventListener(action.id, action.event, action.fn); |
| 15 } | 15 } |
| 16 } | 16 } |
| 17 | 17 |
| 18 /** | 18 /** |
| 19 * Add an event listener to the specified element. | 19 * Add an event listener to the specified element. |
| 20 * @param {string} id Id of element. | 20 * @param {string} id Id of element. |
| 21 * @param {string} eventname Event name. | 21 * @param {string} eventname Event name. |
| 22 * @param {function(Event):void} fn Event handler. | 22 * @param {function(Event):void} fn Event handler. |
| 23 */ | 23 */ |
| 24 function registerEventListener(id, eventname, fn) { | 24 function registerEventListener(id, eventname, fn) { |
| 25 var element = document.getElementById(id); | 25 var element = document.getElementById(id); |
| 26 if (element) { | 26 if (element) { |
| 27 element.addEventListener(eventname, fn, false); | 27 element.addEventListener(eventname, fn, false); |
| 28 } else { | 28 } else { |
| 29 console.error('Could not set ' + eventname + | 29 console.error('Could not set ' + eventname + |
| 30 ' event handler on element ' + id + | 30 ' event handler on element ' + id + |
| 31 ': element not found.'); | 31 ': element not found.'); |
| 32 } | 32 } |
| 33 } | 33 } |
| OLD | NEW |