Index: chrome/browser/resources/new_profile.js |
diff --git a/chrome/browser/resources/new_profile.js b/chrome/browser/resources/new_profile.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9b2dcdd937c8636238ea357e16c6eb2ef8b01c6e |
--- /dev/null |
+++ b/chrome/browser/resources/new_profile.js |
@@ -0,0 +1,82 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+// Tracks the currently selected avatar icon. |
+var gSelectedAvatarIconIndex = 0; |
+ |
+function load() { |
+ // Allow platform specific CSS rules. |
+ cr.enablePlatformSpecificCSSRules(); |
+ |
+ // Install handler for key presses. |
+ document.addEventListener('keydown', keyDownEventHandler); |
+ |
+ // Add handlers to HTML elements. |
+ $('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.
|
+ $('cancel-button').onclick = function () { onCancel(''); }; |
James Hawkins
2011/07/01 01:52:48
Same with onCancel.
sail
2011/07/01 18:08:56
Done.
|
+ $('profile-name-form').onsubmit = function () { |
+ onCreate(''); |
+ // Return false to prevent the submit handler from doing a post. |
+ return false; |
+ }; |
+ |
+ chrome.send('requestProfileInfo'); |
+ updateLogo(); |
+ $('profile-name').focus(); |
+} |
+ |
+function onCreate() { |
+ chrome.send('create', [$('profile-name').value, |
+ String(gSelectedAvatarIconIndex)]); |
+} |
+ |
+function onCancel() { |
+ chrome.send('cancel'); |
+} |
+ |
+function onAvatarClicked(index) { |
James Hawkins
2011/07/01 01:52:48
Document all of these functions.
sail
2011/07/01 18:08:56
Done.
|
+ 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.
|
+ for (var i = 0; i < menu.childNodes.length; i++) { |
+ var button = menu.childNodes[i]; |
+ if (i == index) |
+ button.classList.add("avatar-button-selected"); |
+ else |
+ button.classList.remove("avatar-button-selected"); |
+ } |
+ gSelectedAvatarIconIndex = index; |
+} |
+ |
+function updateLogo() { |
+ var imageId = 'IDR_PRODUCT_LOGO'; |
+ if (document.documentElement.getAttribute('customlogo') == 'true') |
+ imageId = 'IDR_CUSTOM_PRODUCT_LOGO'; |
+ |
+ $('logo-img').src = 'chrome://theme/' + imageId + '?' + Date.now(); |
+} |
+ |
+function keyDownEventHandler() { |
+ // 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.
|
+ if (event.keyCode == 27) { // Esc |
+ onCancel(); |
+ } |
James Hawkins
2011/07/01 01:52:48
nit: Remove braces for one-line blocks.
sail
2011/07/01 18:08:56
Removed.
|
+} |
+ |
+function setProfileInfo(profileName, profileIconIndex) { |
+ $('profile-name').value = profileName; |
+ onAvatarClicked(profileIconIndex); |
+} |
+ |
+function setDefaultAvatarImages(imageUrlList) { |
+ var menu = $("avatar-menu"); |
+ for (var i = 0; i < imageUrlList.length; i++) { |
+ var button = document.createElement("input"); |
+ button.setAttribute("type", "image"); |
+ button.setAttribute("class", "avatar-button"); |
+ button.setAttribute("src", imageUrlList[i]); |
+ button.setAttribute("onclick", "onAvatarClicked(" + i + ")"); |
+ menu.appendChild(button); |
+ } |
+} |
+ |
+document.body.onload = load; |