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 cr.define("newProfile", function() { | |
6 'use strict'; | |
7 | |
8 // Tracks the currently selected avatar icon. | |
9 var selectedAvatarIconIndex = 0; | |
10 | |
11 // Initializes everything once the document loads. | |
12 function load() { | |
13 // Allow platform specific CSS rules. | |
14 cr.enablePlatformSpecificCSSRules(); | |
15 | |
16 // Add handlers to HTML elements. | |
17 $('create-button').onclick = onCreate; | |
18 $('cancel-button').onclick = onCancel; | |
19 $('profile-name-form').onsubmit = function () { | |
20 onCreate(); | |
21 // Return false to prevent the submit handler from doing a post. | |
22 return false; | |
23 }; | |
24 | |
25 chrome.send('requestProfileInfo'); | |
26 updateLogo(); | |
27 $('profile-name').focus(); | |
28 } | |
29 | |
30 // Sends the profile information to the browser. | |
31 function onCreate() { | |
32 chrome.send('create', [$('profile-name').value, | |
33 String(selectedAvatarIconIndex)]); | |
34 } | |
35 | |
36 // Lets the browser know that the user doesn't want to create the profile. | |
37 function onCancel() { | |
38 chrome.send('cancel'); | |
39 } | |
40 | |
41 // Changes the selected profile. | |
42 function onAvatarClicked(index) { | |
43 var menu = $('avatar-menu'); | |
44 for (var i = 0; i < menu.childNodes.length; i++) { | |
45 var button = menu.childNodes[i]; | |
46 if (i == index) | |
47 button.classList.add("avatar-button-selected"); | |
48 else | |
49 button.classList.remove("avatar-button-selected"); | |
50 } | |
51 selectedAvatarIconIndex = index; | |
52 } | |
53 | |
54 // Sets the logo image. | |
55 function updateLogo() { | |
56 var imageId = 'IDR_PRODUCT_LOGO'; | |
57 if (document.documentElement.getAttribute('customlogo') == 'true') | |
58 imageId = 'IDR_CUSTOM_PRODUCT_LOGO'; | |
59 | |
60 $('logo-img').src = 'chrome://theme/' + imageId + '?' + Date.now(); | |
61 } | |
62 | |
63 // Callback from the browser to set the profile information on the page. | |
64 function setProfileInfo(profileName, profileIconIndex) { | |
65 $('profile-name').value = profileName; | |
66 onAvatarClicked(profileIconIndex); | |
67 } | |
68 | |
69 // Callback from the browser to fill the avatar menu with default avatar | |
70 // images. | |
71 function setDefaultAvatarImages(imageUrlList) { | |
72 var menu = $('avatar-menu'); | |
73 for (var i = 0; i < imageUrlList.length; i++) { | |
74 var button = document.createElement("input"); | |
75 button.setAttribute("type", "image"); | |
76 button.setAttribute("class", "avatar-button"); | |
77 button.setAttribute("src", imageUrlList[i]); | |
78 button.setAttribute("onclick", "newProfile.onAvatarClicked(" + i + ")"); | |
79 menu.appendChild(button); | |
80 } | |
81 } | |
82 | |
83 // Return an object with all the exports. | |
84 return { | |
85 load: load, | |
86 onCreate: onCreate, | |
87 onCancel: onCancel, | |
88 onAvatarClicked: onAvatarClicked, | |
89 updateLogo: updateLogo, | |
90 setProfileInfo: setProfileInfo, | |
91 setDefaultAvatarImages: setDefaultAvatarImages, | |
92 }; | |
93 }); | |
94 | |
95 window.addEventListener('DOMContentLoaded', newProfile.load); | |
OLD | NEW |