| 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 var UserImagesGrid = options.UserImagesGrid; | 8 var UserImagesGrid = options.UserImagesGrid; |
| 9 var ButtonImages = UserImagesGrid.ButtonImages; | 9 var ButtonImages = UserImagesGrid.ButtonImages; |
| 10 | 10 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 localStrings.getString('chooseFile'), | 65 localStrings.getString('chooseFile'), |
| 66 this.handleChooseFile_.bind(this)); | 66 this.handleChooseFile_.bind(this)); |
| 67 | 67 |
| 68 // Profile image data. | 68 // Profile image data. |
| 69 this.profileImage_ = imageGrid.addItem( | 69 this.profileImage_ = imageGrid.addItem( |
| 70 ButtonImages.PROFILE_PICTURE, | 70 ButtonImages.PROFILE_PICTURE, |
| 71 localStrings.getString('profilePhotoLoading')); | 71 localStrings.getString('profilePhotoLoading')); |
| 72 | 72 |
| 73 // Old user image data (if present). | 73 // Old user image data (if present). |
| 74 this.oldImage_ = null; | 74 this.oldImage_ = null; |
| 75 |
| 76 chrome.send('onChangePicturePageInitialized'); |
| 75 }, | 77 }, |
| 76 | 78 |
| 77 /** | 79 /** |
| 78 * Called right after the page has been shown to user. | 80 * Called right after the page has been shown to user. |
| 79 */ | 81 */ |
| 80 didShowPage: function() { | 82 didShowPage: function() { |
| 81 $('images-grid').updateAndFocus(); | 83 $('images-grid').updateAndFocus(); |
| 82 chrome.send('onPageShown'); | 84 chrome.send('onChangePicturePageShown'); |
| 83 }, | 85 }, |
| 84 | 86 |
| 85 /** | 87 /** |
| 86 * Called right before the page is hidden. | 88 * Called right before the page is hidden. |
| 87 */ | 89 */ |
| 88 willHidePage: function() { | 90 willHidePage: function() { |
| 91 var imageGrid = $('images-grid'); |
| 92 imageGrid.blur(); // Make sure the image grid is not active. |
| 89 if (this.oldImage_) { | 93 if (this.oldImage_) { |
| 90 $('images-grid').removeItem(this.oldImage_); | 94 imageGrid.removeItem(this.oldImage_); |
| 91 this.oldImage_ = null; | 95 this.oldImage_ = null; |
| 92 } | 96 } |
| 93 }, | 97 }, |
| 94 | 98 |
| 95 /** | 99 /** |
| 96 * Closes current page, returning back to Personal Stuff page. | 100 * Closes current page, returning back to Personal Stuff page. |
| 97 * @private | 101 * @private |
| 98 */ | 102 */ |
| 99 closePage_: function() { | 103 closePage_: function() { |
| 100 $('images-grid').blur(); // Make sure the image grid is not active. | |
| 101 OptionsPage.navigateToPage('personal'); | 104 OptionsPage.navigateToPage('personal'); |
| 102 }, | 105 }, |
| 103 | 106 |
| 104 /** | 107 /** |
| 105 * Handles "Take photo" button activation. | 108 * Handles "Take photo" button activation. |
| 106 * @private | 109 * @private |
| 107 */ | 110 */ |
| 108 handleTakePhoto_: function() { | 111 handleTakePhoto_: function() { |
| 109 chrome.send('takePhoto'); | 112 chrome.send('takePhoto'); |
| 110 this.closePage_(); | 113 this.closePage_(); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 /** | 215 /** |
| 213 * Selects user image with the given URL. | 216 * Selects user image with the given URL. |
| 214 * @param {string} url URL of the image to select. | 217 * @param {string} url URL of the image to select. |
| 215 * @private | 218 * @private |
| 216 */ | 219 */ |
| 217 setSelectedImage_: function(url) { | 220 setSelectedImage_: function(url) { |
| 218 $('images-grid').selectedItemUrl = url; | 221 $('images-grid').selectedItemUrl = url; |
| 219 }, | 222 }, |
| 220 | 223 |
| 221 /** | 224 /** |
| 222 * Appends received images to the image grid. | 225 * Appends default images to the image grid. Should only be called once. |
| 223 * @param {Array.<string>} images An array of URLs to user images. | 226 * @param {Array.<string>} images An array of URLs to default images. |
| 224 * @private | 227 * @private |
| 225 */ | 228 */ |
| 226 setUserImages_: function(images) { | 229 setDefaultImages_: function(images) { |
| 227 var imageGrid = $('images-grid'); | 230 var imageGrid = $('images-grid'); |
| 228 for (var i = 0, url; url = images[i]; i++) { | 231 for (var i = 0, url; url = images[i]; i++) { |
| 229 imageGrid.addItem(url); | 232 imageGrid.addItem(url); |
| 230 } | 233 } |
| 231 }, | 234 }, |
| 232 }; | 235 }; |
| 233 | 236 |
| 234 // Forward public APIs to private implementations. | 237 // Forward public APIs to private implementations. |
| 235 [ | 238 [ |
| 236 'setCameraPresent', | 239 'setCameraPresent', |
| 240 'setDefaultImages', |
| 237 'setOldImage', | 241 'setOldImage', |
| 238 'setProfileImage', | 242 'setProfileImage', |
| 239 'setSelectedImage', | 243 'setSelectedImage', |
| 240 'setUserImages', | |
| 241 ].forEach(function(name) { | 244 ].forEach(function(name) { |
| 242 ChangePictureOptions[name] = function(value1, value2) { | 245 ChangePictureOptions[name] = function(value1, value2) { |
| 243 ChangePictureOptions.getInstance()[name + '_'](value1, value2); | 246 ChangePictureOptions.getInstance()[name + '_'](value1, value2); |
| 244 }; | 247 }; |
| 245 }); | 248 }); |
| 246 | 249 |
| 247 // Export | 250 // Export |
| 248 return { | 251 return { |
| 249 ChangePictureOptions: ChangePictureOptions | 252 ChangePictureOptions: ChangePictureOptions |
| 250 }; | 253 }; |
| 251 | 254 |
| 252 }); | 255 }); |
| 253 | 256 |
| OLD | NEW |