| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 <include src="user_chooser_common.js"></include> |
| 5 |
| 6 cr.define('UserChooser', function() { |
| 7 'use strict'; |
| 8 |
| 9 /** |
| 10 * Setups given "select" element using the list and adds callback. |
| 11 * @param {!Element} select Select object to be updated. |
| 12 * @param {!Object} list List of the options to be added. |
| 13 * @param {string} callback Callback name which should be send to Chrome or |
| 14 * an empty string if the event listener shouldn't be added. |
| 15 */ |
| 16 function setupSelect(select, list, callback) { |
| 17 select.options.length = 0; |
| 18 for (var i = 0; i < list.length; ++i) { |
| 19 var item = list[i]; |
| 20 var option = |
| 21 new Option(item.title, item.value, item.selected, item.selected); |
| 22 select.appendChild(option); |
| 23 } |
| 24 if (callback) { |
| 25 var sendCallback = function() { |
| 26 chrome.send(callback, [select.options[select.selectedIndex].value]); |
| 27 }; |
| 28 select.addEventListener('blur', sendCallback); |
| 29 select.addEventListener('click', sendCallback); |
| 30 select.addEventListener('keyup', function(event) { |
| 31 var keycodeInterested = [ |
| 32 9, // Tab |
| 33 13, // Enter |
| 34 27, // Escape |
| 35 ]; |
| 36 if (keycodeInterested.indexOf(event.keyCode) >= 0) |
| 37 sendCallback(); |
| 38 }); |
| 39 } |
| 40 } |
| 41 |
| 42 function initialize() { |
| 43 login.AccountPickerScreen.register(); |
| 44 login.GaiaSigninScreen.register(); |
| 45 |
| 46 cr.ui.Bubble.decorate($('bubble')); |
| 47 login.HeaderBar.decorate($('login-header-bar')); |
| 48 |
| 49 chrome.send('userChooserInitialize'); |
| 50 } |
| 51 |
| 52 // Return an object with all of the exports. |
| 53 return { |
| 54 initialize: initialize, |
| 55 setupSelect: setupSelect |
| 56 }; |
| 57 }); |
| 58 |
| 59 document.addEventListener('DOMContentLoaded', UserChooser.initialize); |
| OLD | NEW |