OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 // Tracks the currently selected avatar icon. | |
6 var gSelectedAvatarIconIndex = 0; | |
7 | |
8 function load() { | |
9 // Allow platform specific CSS rules. | |
10 cr.enablePlatformSpecificCSSRules(); | |
11 | |
12 // Install handler for key presses. | |
13 document.addEventListener('keydown', keyDownEventHandler); | |
14 | |
15 // Add handlers to HTML elements. | |
16 $('create-button').onclick = function () { onCreate(''); }; | |
James Hawkins
2011/07/01 01:52:48
Remove the parameters to onCreate() (which doesn't
sail
2011/07/01 18:08:56
Done.
| |
17 $('cancel-button').onclick = function () { onCancel(''); }; | |
James Hawkins
2011/07/01 01:52:48
Same with onCancel.
sail
2011/07/01 18:08:56
Done.
| |
18 $('profile-name-form').onsubmit = function () { | |
19 onCreate(''); | |
20 // Return false to prevent the submit handler from doing a post. | |
21 return false; | |
22 }; | |
23 | |
24 chrome.send('requestProfileInfo'); | |
25 updateLogo(); | |
26 $('profile-name').focus(); | |
27 } | |
28 | |
29 function onCreate() { | |
30 chrome.send('create', [$('profile-name').value, | |
31 String(gSelectedAvatarIconIndex)]); | |
32 } | |
33 | |
34 function onCancel() { | |
35 chrome.send('cancel'); | |
36 } | |
37 | |
38 function onAvatarClicked(index) { | |
James Hawkins
2011/07/01 01:52:48
Document all of these functions.
sail
2011/07/01 18:08:56
Done.
| |
39 var menu = $("avatar-menu"); | |
James Hawkins
2011/07/01 01:52:48
Use single quotes, not double quotes.
sail
2011/07/01 18:08:56
Done.
| |
40 for (var i = 0; i < menu.childNodes.length; i++) { | |
41 var button = menu.childNodes[i]; | |
42 if (i == index) | |
43 button.classList.add("avatar-button-selected"); | |
44 else | |
45 button.classList.remove("avatar-button-selected"); | |
46 } | |
47 gSelectedAvatarIconIndex = index; | |
48 } | |
49 | |
50 function updateLogo() { | |
51 var imageId = 'IDR_PRODUCT_LOGO'; | |
52 if (document.documentElement.getAttribute('customlogo') == 'true') | |
53 imageId = 'IDR_CUSTOM_PRODUCT_LOGO'; | |
54 | |
55 $('logo-img').src = 'chrome://theme/' + imageId + '?' + Date.now(); | |
56 } | |
57 | |
58 function keyDownEventHandler() { | |
59 // Close the top overlay or sub-page on esc. | |
James Hawkins
2011/07/01 01:52:48
As per previous comment, fix this comment.
sail
2011/07/01 18:08:56
Removed.
| |
60 if (event.keyCode == 27) { // Esc | |
61 onCancel(); | |
62 } | |
James Hawkins
2011/07/01 01:52:48
nit: Remove braces for one-line blocks.
sail
2011/07/01 18:08:56
Removed.
| |
63 } | |
64 | |
65 function setProfileInfo(profileName, profileIconIndex) { | |
66 $('profile-name').value = profileName; | |
67 onAvatarClicked(profileIconIndex); | |
68 } | |
69 | |
70 function setDefaultAvatarImages(imageUrlList) { | |
71 var menu = $("avatar-menu"); | |
72 for (var i = 0; i < imageUrlList.length; i++) { | |
73 var button = document.createElement("input"); | |
74 button.setAttribute("type", "image"); | |
75 button.setAttribute("class", "avatar-button"); | |
76 button.setAttribute("src", imageUrlList[i]); | |
77 button.setAttribute("onclick", "onAvatarClicked(" + i + ")"); | |
78 menu.appendChild(button); | |
79 } | |
80 } | |
81 | |
82 document.body.onload = load; | |
OLD | NEW |