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 var gSelectedAvatarIconIndex = 0; | |
James Hawkins
2011/06/30 23:02:58
Document this variable.
sail
2011/07/01 01:16:18
Done.
| |
6 | |
7 /////////////////////////////////////////////////////////////////////////////// | |
8 // Helper functions | |
James Hawkins
2011/06/30 23:02:58
Use a more descriptive name or remove the comment.
sail
2011/07/01 01:16:18
Done.
| |
9 function $(o) {return document.getElementById(o);} | |
James Hawkins
2011/06/30 23:02:58
Haven't you already included cr.js? This is alread
sail
2011/07/01 01:16:18
Done.
| |
10 | |
11 function load() { | |
12 // Allow platform specific CSS rules. | |
13 cr.enablePlatformSpecificCSSRules(); | |
14 | |
15 // Install handler for key presses. | |
16 document.addEventListener('keydown', keyDownEventHandler); | |
17 | |
18 chrome.send('requestProfileInfo', []); | |
James Hawkins
2011/06/30 23:02:58
No need for the empty last param, here and elsewhe
sail
2011/07/01 01:16:18
Done.
| |
19 updateLogo(); | |
20 $('profile-name').focus(); | |
21 } | |
22 | |
23 function onCreate() { | |
24 chrome.send('create', [$('profile-name').value, | |
25 String(gSelectedAvatarIconIndex)]); | |
26 } | |
27 | |
28 function onCancel() { | |
29 chrome.send('cancel', []); | |
30 } | |
31 | |
32 function onAvatarClicked(index) { | |
33 var menu = document.getElementById("avatar-menu"); | |
James Hawkins
2011/06/30 23:02:58
$('')
sail
2011/07/01 01:16:18
Done.
| |
34 for (var i = 0; i < menu.childNodes.length; i++) { | |
35 var button = menu.childNodes[i]; | |
36 if (i == index) { | |
37 button.setAttribute("style", "background-color: #bbcee9"); | |
James Hawkins
2011/06/30 23:02:58
You should use a class that specifies this instead
sail
2011/07/01 01:16:18
Done.
| |
38 } else { | |
39 button.setAttribute("style", "background-color: transparent"); | |
40 } | |
41 } | |
42 gSelectedAvatarIconIndex = index; | |
43 } | |
44 | |
45 function updateLogo() { | |
46 var imageId = 'IDR_PRODUCT_LOGO'; | |
47 if (document.documentElement.getAttribute('customlogo') == 'true') | |
James Hawkins
2011/06/30 23:02:58
$('')
sail
2011/07/01 01:16:18
Done.
| |
48 imageId = 'IDR_CUSTOM_PRODUCT_LOGO'; | |
49 | |
50 $('logo-img').src = 'chrome://theme/' + imageId + '?' + Date.now(); | |
51 } | |
52 | |
53 function keyDownEventHandler() { | |
54 // Close the top overlay or sub-page on esc. | |
James Hawkins
2011/06/30 23:02:58
You copied this comment from options_page.js and f
sail
2011/07/01 01:16:18
Asking.
Now that I think about it, I agree that es
| |
55 if (event.keyCode == 27) { // Esc | |
56 onCancel(); | |
57 } | |
58 } | |
59 | |
60 /////////////////////////////////////////////////////////////////////////////// | |
61 // Chrome callbacks: | |
62 | |
63 function setProfileInfo(profileName, profileIconIndex) { | |
64 $('profile-name').value = profileName; | |
65 onAvatarClicked(profileIconIndex); | |
66 } | |
67 | |
68 function setDefaultAvatarImages(imageUrlList) { | |
69 var menu = document.getElementById("avatar-menu"); | |
James Hawkins
2011/06/30 23:02:58
$('')
| |
70 for (var i = 0; i < imageUrlList.length; i++) { | |
71 var button = document.createElement("input"); | |
72 button.setAttribute("type", "image"); | |
73 button.setAttribute("class", "avatar-button"); | |
74 button.setAttribute("src", imageUrlList[i]); | |
75 button.setAttribute("onclick", "onAvatarClicked(" + i + ")"); | |
76 menu.appendChild(button); | |
77 } | |
78 } | |
79 | |
80 // Add handlers to HTML elements. | |
81 document.body.onload = load; | |
82 $('create-button').onclick = function () { onCreate(''); }; | |
James Hawkins
2011/06/30 23:02:58
Do all of this work in load().
sail
2011/07/01 01:16:18
Done.
| |
83 $('cancel-button').onclick = function () { onCancel(''); }; | |
84 $('profile-name-form').onsubmit = function () { | |
85 onCreate(''); | |
86 // Return false to prevent the submit handler from doing a post. | |
87 return false; | |
88 }; | |
OLD | NEW |