OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 cr.define('options', function() { | 5 cr.define('options', function() { |
6 | 6 |
7 var OptionsPage = options.OptionsPage; | 7 var OptionsPage = options.OptionsPage; |
8 | 8 |
9 ///////////////////////////////////////////////////////////////////////////// | 9 ///////////////////////////////////////////////////////////////////////////// |
10 // ChangePictureOptions class: | 10 // ChangePictureOptions class: |
(...skipping 19 matching lines...) Expand all Loading... |
30 /** | 30 /** |
31 * Initializes ChangePictureOptions page. | 31 * Initializes ChangePictureOptions page. |
32 */ | 32 */ |
33 initializePage: function() { | 33 initializePage: function() { |
34 // Call base class implementation to starts preference initialization. | 34 // Call base class implementation to starts preference initialization. |
35 OptionsPage.prototype.initializePage.call(this); | 35 OptionsPage.prototype.initializePage.call(this); |
36 // Add "Take photo" and "Choose a file" buttons in a uniform way with | 36 // Add "Take photo" and "Choose a file" buttons in a uniform way with |
37 // other buttons. | 37 // other buttons. |
38 this.addUserImage_( | 38 this.addUserImage_( |
39 'chrome://theme/IDR_BUTTON_USER_IMAGE_TAKE_PHOTO', | 39 'chrome://theme/IDR_BUTTON_USER_IMAGE_TAKE_PHOTO', |
| 40 localStrings.getString('takePhoto'), |
40 this.handleTakePhoto_); | 41 this.handleTakePhoto_); |
41 this.addUserImage_( | 42 this.addUserImage_( |
42 'chrome://theme/IDR_BUTTON_USER_IMAGE_CHOOSE_FILE', | 43 'chrome://theme/IDR_BUTTON_USER_IMAGE_CHOOSE_FILE', |
| 44 localStrings.getString('chooseFile'), |
43 this.handleChooseFile_); | 45 this.handleChooseFile_); |
44 chrome.send('getAvailableImages'); | 46 chrome.send('getAvailableImages'); |
45 }, | 47 }, |
46 | 48 |
47 /** | 49 /** |
48 * Handler for when the user clicks on "Take photo" button. | 50 * Handler for when the user clicks on "Take photo" button. |
49 * @private | 51 * @private |
50 * @param {Event} e Click Event. | 52 * @param {Event} e Click Event. |
51 */ | 53 */ |
52 handleTakePhoto_: function(e) { | 54 handleTakePhoto_: function(e) { |
(...skipping 17 matching lines...) Expand all Loading... |
70 * @param {Event} e Click Event. | 72 * @param {Event} e Click Event. |
71 */ | 73 */ |
72 handleImageClick_: function(e) { | 74 handleImageClick_: function(e) { |
73 chrome.send('selectImage', [e.target.src]); | 75 chrome.send('selectImage', [e.target.src]); |
74 OptionsPage.navigateToPage('personal'); | 76 OptionsPage.navigateToPage('personal'); |
75 }, | 77 }, |
76 | 78 |
77 /** | 79 /** |
78 * Appends new image to the end of the image list. | 80 * Appends new image to the end of the image list. |
79 * @param {string} src A url for the user image. | 81 * @param {string} src A url for the user image. |
| 82 * @param {string} title A tooltip for the image. |
80 * @param {function} clickHandler A handler for click on image. | 83 * @param {function} clickHandler A handler for click on image. |
81 * @private | 84 * @private |
82 */ | 85 */ |
83 addUserImage_: function(src, clickHandler) { | 86 addUserImage_: function(src, title, clickHandler) { |
84 var imageElement = document.createElement('img'); | 87 var imageElement = document.createElement('img'); |
85 imageElement.src = src; | 88 imageElement.src = src; |
| 89 if (title) |
| 90 imageElement.title = title; |
86 imageElement.addEventListener('click', | 91 imageElement.addEventListener('click', |
87 clickHandler, | 92 clickHandler, |
88 false); | 93 false); |
89 var divElement = document.createElement('div'); | 94 var divElement = document.createElement('div'); |
90 divElement.classList.add('list-element'); | 95 divElement.classList.add('list-element'); |
91 divElement.appendChild(imageElement); | 96 divElement.appendChild(imageElement); |
92 $('images-list').appendChild(divElement); | 97 $('images-list').appendChild(divElement); |
93 }, | 98 }, |
94 | 99 |
95 /** | 100 /** |
96 * Inserts received images before "Choose file" button. | 101 * Inserts received images before "Choose file" button. |
97 * @param {List} images A list of urls to user images. | 102 * @param {List} images A list of urls to user images. |
98 * @private | 103 * @private |
99 */ | 104 */ |
100 addUserImages_: function(images) { | 105 addUserImages_: function(images) { |
101 for (var i = 0; i < images.length; i++) { | 106 for (var i = 0; i < images.length; i++) { |
102 var imageUrl = images[i]; | 107 var imageUrl = images[i]; |
103 this.addUserImage_(imageUrl, this.handleImageClick_); | 108 this.addUserImage_(imageUrl, "", this.handleImageClick_); |
104 } | 109 } |
105 }, | 110 }, |
106 }; | 111 }; |
107 | 112 |
108 // Forward public APIs to private implementations. | 113 // Forward public APIs to private implementations. |
109 [ | 114 [ |
110 'addUserImages', | 115 'addUserImages', |
111 ].forEach(function(name) { | 116 ].forEach(function(name) { |
112 ChangePictureOptions[name] = function(value) { | 117 ChangePictureOptions[name] = function(value) { |
113 ChangePictureOptions.getInstance()[name + '_'](value); | 118 ChangePictureOptions.getInstance()[name + '_'](value); |
114 }; | 119 }; |
115 }); | 120 }); |
116 | 121 |
117 // Export | 122 // Export |
118 return { | 123 return { |
119 ChangePictureOptions: ChangePictureOptions | 124 ChangePictureOptions: ChangePictureOptions |
120 }; | 125 }; |
121 | 126 |
122 }); | 127 }); |
123 | 128 |
OLD | NEW |