| 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; | |
| 6 | |
| 7 /////////////////////////////////////////////////////////////////////////////// | |
| 8 // Helper functions | |
| 9 function $(o) {return document.getElementById(o);} | |
| 10 | |
| 11 function load() { | |
| 12 chrome.send('requestProfileInfo', []); | |
| 13 updateLogo(); | |
| 14 } | |
| 15 | |
| 16 function onCreate() { | |
| 17 chrome.send('create', [$('profile-name').value, | |
| 18 String(gSelectedAvatarIconIndex)]); | |
| 19 } | |
| 20 | |
| 21 function onCancel() { | |
| 22 chrome.send('cancel', []); | |
| 23 } | |
| 24 | |
| 25 function onAvatarClicked(index) { | |
| 26 var menu = document.getElementById("avatar-menu"); | |
| 27 for (var i = 0; i < menu.childNodes.length; i++) { | |
| 28 var button = menu.childNodes[i]; | |
| 29 if (i == index) { | |
| 30 button.setAttribute("style", "background-color: #bbcee9"); | |
| 31 } else { | |
| 32 button.setAttribute("style", "background-color: transparent"); | |
| 33 } | |
| 34 } | |
| 35 gSelectedAvatarIconIndex = index; | |
| 36 } | |
| 37 | |
| 38 function updateLogo() { | |
| 39 var imageId = 'IDR_PRODUCT_LOGO'; | |
| 40 if (document.documentElement.getAttribute('customlogo') == 'true') | |
| 41 imageId = 'IDR_CUSTOM_PRODUCT_LOGO'; | |
| 42 | |
| 43 $('logo-img').src = 'chrome://theme/' + imageId + '?' + Date.now(); | |
| 44 } | |
| 45 | |
| 46 /////////////////////////////////////////////////////////////////////////////// | |
| 47 // Chrome callbacks: | |
| 48 | |
| 49 function setProfileInfo(profileName, profileIconIndex) { | |
| 50 $('profile-name').value = profileName; | |
| 51 onAvatarClicked(profileIconIndex); | |
| 52 } | |
| 53 | |
| 54 function setDefaultAvatarImages(imageUrlList) { | |
| 55 var menu = document.getElementById("avatar-menu"); | |
| 56 for (var i = 0; i < imageUrlList.length; i++) { | |
| 57 var button = document.createElement("input"); | |
| 58 button.setAttribute("type", "image"); | |
| 59 button.setAttribute("class", "avatar-button"); | |
| 60 button.setAttribute("src", imageUrlList[i]); | |
| 61 button.setAttribute("onclick", "onAvatarClicked(" + i + ")"); | |
| 62 menu.appendChild(button); | |
| 63 } | |
| 64 } | |
| 65 | |
| 66 // Add handlers to HTML elements. | |
| 67 document.body.onload = load; | |
| 68 $('create-button').onclick = function () { onCreate(''); }; | |
| 69 $('cancel-button').onclick = function () { onCancel(''); }; | |
| 70 $('profile-name-form').onsubmit = function () { | |
| 71 onCreate(''); | |
| 72 return false; | |
| 73 }; | |
| OLD | NEW |