| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 | 59 |
| 60 imageGrid.addEventListener('select', | 60 imageGrid.addEventListener('select', |
| 61 this.handleImageSelected_.bind(this)); | 61 this.handleImageSelected_.bind(this)); |
| 62 imageGrid.addEventListener('activate', | 62 imageGrid.addEventListener('activate', |
| 63 this.handleImageActivated_.bind(this)); | 63 this.handleImageActivated_.bind(this)); |
| 64 imageGrid.addEventListener('phototaken', | 64 imageGrid.addEventListener('phototaken', |
| 65 this.handlePhotoTaken_.bind(this)); | 65 this.handlePhotoTaken_.bind(this)); |
| 66 imageGrid.addEventListener('photoupdated', | 66 imageGrid.addEventListener('photoupdated', |
| 67 this.handlePhotoTaken_.bind(this)); | 67 this.handlePhotoTaken_.bind(this)); |
| 68 | 68 |
| 69 // Set the title for "Take Photo" button. | |
| 70 imageGrid.cameraTitle = loadTimeData.getString('takePhoto'); | |
| 71 | |
| 72 // Add the "Choose file" button. | 69 // Add the "Choose file" button. |
| 73 imageGrid.addItem(ButtonImages.CHOOSE_FILE, | 70 imageGrid.addItem(ButtonImages.CHOOSE_FILE, |
| 74 loadTimeData.getString('chooseFile'), | 71 loadTimeData.getString('chooseFile'), |
| 75 this.handleChooseFile_.bind(this)).type = 'file'; | 72 this.handleChooseFile_.bind(this)).type = 'file'; |
| 76 | 73 |
| 77 // Profile image data. | 74 // Profile image data. |
| 78 this.profileImage_ = imageGrid.addItem( | 75 this.profileImage_ = imageGrid.addItem( |
| 79 ButtonImages.PROFILE_PICTURE, | 76 ButtonImages.PROFILE_PICTURE, |
| 80 loadTimeData.getString('profilePhotoLoading')); | 77 loadTimeData.getString('profilePhotoLoading')); |
| 81 this.profileImage_.type = 'profile'; | 78 this.profileImage_.type = 'profile'; |
| 82 | 79 |
| 80 // Set the title for camera item in the grid. |
| 81 imageGrid.setCameraTitles( |
| 82 loadTimeData.getString('takePhoto'), |
| 83 loadTimeData.getString('photoFromCamera')); |
| 84 |
| 83 $('take-photo').addEventListener( | 85 $('take-photo').addEventListener( |
| 84 'click', this.handleTakePhoto_.bind(this)); | 86 'click', this.handleTakePhoto_.bind(this)); |
| 85 $('discard-photo').addEventListener( | 87 $('discard-photo').addEventListener( |
| 86 'click', imageGrid.discardPhoto.bind(imageGrid)); | 88 'click', this.handleDiscardPhoto_.bind(this)); |
| 87 | 89 |
| 88 // Toggle 'animation' class for the duration of WebKit transition. | 90 // Toggle 'animation' class for the duration of WebKit transition. |
| 89 $('flip-photo').addEventListener( | 91 $('flip-photo').addEventListener( |
| 90 'click', function(e) { | 92 'click', this.handleFlipPhoto_.bind(this)); |
| 91 previewElement.classList.add('animation'); | |
| 92 imageGrid.flipPhoto = !imageGrid.flipPhoto; | |
| 93 }); | |
| 94 $('user-image-stream-crop').addEventListener( | 93 $('user-image-stream-crop').addEventListener( |
| 95 'webkitTransitionEnd', function(e) { | 94 'webkitTransitionEnd', function(e) { |
| 96 previewElement.classList.remove('animation'); | 95 previewElement.classList.remove('animation'); |
| 97 }); | 96 }); |
| 98 $('user-image-preview-img').addEventListener( | 97 $('user-image-preview-img').addEventListener( |
| 99 'webkitTransitionEnd', function(e) { | 98 'webkitTransitionEnd', function(e) { |
| 100 previewElement.classList.remove('animation'); | 99 previewElement.classList.remove('animation'); |
| 101 }); | 100 }); |
| 102 | 101 |
| 103 // Old user image data (if present). | 102 // Old user image data (if present). |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 /** | 144 /** |
| 146 * Closes the overlay, returning to the main settings page. | 145 * Closes the overlay, returning to the main settings page. |
| 147 * @private | 146 * @private |
| 148 */ | 147 */ |
| 149 closeOverlay_: function() { | 148 closeOverlay_: function() { |
| 150 if (!$('change-picture-page').hidden) | 149 if (!$('change-picture-page').hidden) |
| 151 OptionsPage.closeOverlay(); | 150 OptionsPage.closeOverlay(); |
| 152 }, | 151 }, |
| 153 | 152 |
| 154 /** | 153 /** |
| 154 * Handle camera-photo flip. |
| 155 */ |
| 156 handleFlipPhoto_: function() { |
| 157 var imageGrid = $('user-image-grid'); |
| 158 imageGrid.previewElement.classList.add('animation'); |
| 159 imageGrid.flipPhoto = !imageGrid.flipPhoto; |
| 160 var flipMessageId = imageGrid.flipPhoto ? |
| 161 'photoFlippedAccessibleText' : 'photoFlippedBackAccessibleText'; |
| 162 this.announceAccessibleMessage_( |
| 163 loadTimeData.getString(flipMessageId)); |
| 164 }, |
| 165 |
| 166 /** |
| 155 * Handles "Take photo" button click. | 167 * Handles "Take photo" button click. |
| 156 * @private | 168 * @private |
| 157 */ | 169 */ |
| 158 handleTakePhoto_: function() { | 170 handleTakePhoto_: function() { |
| 159 $('user-image-grid').takePhoto(); | 171 $('user-image-grid').takePhoto(); |
| 172 chrome.send('takePhoto'); |
| 160 }, | 173 }, |
| 161 | 174 |
| 162 /** | 175 /** |
| 163 * Handle photo captured event. | 176 * Handle photo captured event. |
| 164 * @param {Event} e Event with 'dataURL' property containing a data URL. | 177 * @param {Event} e Event with 'dataURL' property containing a data URL. |
| 165 */ | 178 */ |
| 166 handlePhotoTaken_: function(e) { | 179 handlePhotoTaken_: function(e) { |
| 167 chrome.send('photoTaken', [e.dataURL]); | 180 chrome.send('photoTaken', [e.dataURL]); |
| 168 }, | 181 }, |
| 169 | 182 |
| 170 /** | 183 /** |
| 184 * Handles "Discard photo" button click. |
| 185 * @private |
| 186 */ |
| 187 handleDiscardPhoto_: function() { |
| 188 $('user-image-grid').discardPhoto(); |
| 189 chrome.send('discardPhoto'); |
| 190 }, |
| 191 |
| 192 /** |
| 171 * Handles "Choose a file" button activation. | 193 * Handles "Choose a file" button activation. |
| 172 * @private | 194 * @private |
| 173 */ | 195 */ |
| 174 handleChooseFile_: function() { | 196 handleChooseFile_: function() { |
| 175 chrome.send('chooseFile'); | 197 chrome.send('chooseFile'); |
| 176 this.closeOverlay_(); | 198 this.closeOverlay_(); |
| 177 }, | 199 }, |
| 178 | 200 |
| 179 /** | 201 /** |
| 180 * Handles image selection change. | 202 * Handles image selection change. |
| 181 * @param {Event} e Selection change Event. | 203 * @param {Event} e Selection change Event. |
| 182 * @private | 204 * @private |
| 183 */ | 205 */ |
| 184 handleImageSelected_: function(e) { | 206 handleImageSelected_: function(e) { |
| 185 var imageGrid = $('user-image-grid'); | 207 var imageGrid = $('user-image-grid'); |
| 186 var url = imageGrid.selectedItemUrl; | 208 var url = imageGrid.selectedItemUrl; |
| 209 |
| 210 // Flip button available only for camera picture. |
| 211 imageGrid.flipPhotoElement.tabIndex = |
| 212 imageGrid.selectionType == 'camera' ? 1 : -1; |
| 187 // Ignore selection change caused by program itself and selection of one | 213 // Ignore selection change caused by program itself and selection of one |
| 188 // of the action buttons. | 214 // of the action buttons. |
| 189 if (!imageGrid.inProgramSelection && | 215 if (!imageGrid.inProgramSelection && |
| 190 url != ButtonImages.TAKE_PHOTO && url != ButtonImages.CHOOSE_FILE) { | 216 url != ButtonImages.TAKE_PHOTO && url != ButtonImages.CHOOSE_FILE) { |
| 191 chrome.send('selectImage', [url, imageGrid.selectionType]); | 217 chrome.send('selectImage', [url, imageGrid.selectionType]); |
| 192 } | 218 } |
| 193 // Start/stop camera on (de)selection. | 219 // Start/stop camera on (de)selection. |
| 194 if (!imageGrid.inProgramSelection && | 220 if (!imageGrid.inProgramSelection && |
| 195 imageGrid.selectionType != e.oldSelectionType) { | 221 imageGrid.selectionType != e.oldSelectionType) { |
| 196 if (imageGrid.selectionType == 'camera') { | 222 if (imageGrid.selectionType == 'camera') { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 224 case ButtonImages.CHOOSE_FILE: | 250 case ButtonImages.CHOOSE_FILE: |
| 225 this.handleChooseFile_(); | 251 this.handleChooseFile_(); |
| 226 break; | 252 break; |
| 227 default: | 253 default: |
| 228 this.closeOverlay_(); | 254 this.closeOverlay_(); |
| 229 break; | 255 break; |
| 230 } | 256 } |
| 231 }, | 257 }, |
| 232 | 258 |
| 233 /** | 259 /** |
| 260 * Add an accessible message to the page that will be announced to |
| 261 * users who have spoken feedback on, but will be invisible to all |
| 262 * other users. It's removed right away so it doesn't clutter the DOM. |
| 263 */ |
| 264 announceAccessibleMessage_: function(msg) { |
| 265 var element = document.createElement('div'); |
| 266 element.setAttribute('aria-live', 'polite'); |
| 267 element.style.position = 'relative'; |
| 268 element.style.left = '-9999px'; |
| 269 element.style.height = '0px'; |
| 270 element.innerText = msg; |
| 271 document.body.appendChild(element); |
| 272 window.setTimeout(function() { |
| 273 document.body.removeChild(element); |
| 274 }, 0); |
| 275 }, |
| 276 |
| 277 /** |
| 234 * Adds or updates old user image taken from file/camera (neither a profile | 278 * Adds or updates old user image taken from file/camera (neither a profile |
| 235 * image nor a default one). | 279 * image nor a default one). |
| 236 * @param {string} imageUrl Old user image, as data or internal URL. | 280 * @param {string} imageUrl Old user image, as data or internal URL. |
| 237 * @private | 281 * @private |
| 238 */ | 282 */ |
| 239 setOldImage_: function(imageUrl) { | 283 setOldImage_: function(imageUrl) { |
| 240 var imageGrid = $('user-image-grid'); | 284 var imageGrid = $('user-image-grid'); |
| 241 if (this.oldImage_) { | 285 if (this.oldImage_) { |
| 242 this.oldImage_ = imageGrid.updateItem(this.oldImage_, imageUrl); | 286 this.oldImage_ = imageGrid.updateItem(this.oldImage_, imageUrl); |
| 243 } else { | 287 } else { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 /** | 326 /** |
| 283 * Appends default images to the image grid. Should only be called once. | 327 * Appends default images to the image grid. Should only be called once. |
| 284 * @param {Array.<{url: string, author: string, website: string}>} | 328 * @param {Array.<{url: string, author: string, website: string}>} |
| 285 * imagesData An array of default images data, including URL, author and | 329 * imagesData An array of default images data, including URL, author and |
| 286 * website. | 330 * website. |
| 287 * @private | 331 * @private |
| 288 */ | 332 */ |
| 289 setDefaultImages_: function(imagesData) { | 333 setDefaultImages_: function(imagesData) { |
| 290 var imageGrid = $('user-image-grid'); | 334 var imageGrid = $('user-image-grid'); |
| 291 for (var i = 0, data; data = imagesData[i]; i++) { | 335 for (var i = 0, data; data = imagesData[i]; i++) { |
| 292 var item = imageGrid.addItem(data.url); | 336 var item = imageGrid.addItem(data.url, data.title); |
| 293 item.type = 'default'; | 337 item.type = 'default'; |
| 294 item.author = data.author || ''; | 338 item.author = data.author || ''; |
| 295 item.website = data.website || ''; | 339 item.website = data.website || ''; |
| 296 } | 340 } |
| 297 }, | 341 }, |
| 298 }; | 342 }; |
| 299 | 343 |
| 300 // Forward public APIs to private implementations. | 344 // Forward public APIs to private implementations. |
| 301 [ | 345 [ |
| 302 'closeOverlay', | 346 'closeOverlay', |
| 303 'setCameraPresent', | 347 'setCameraPresent', |
| 304 'setDefaultImages', | 348 'setDefaultImages', |
| 305 'setOldImage', | 349 'setOldImage', |
| 306 'setProfileImage', | 350 'setProfileImage', |
| 307 'setSelectedImage', | 351 'setSelectedImage', |
| 308 ].forEach(function(name) { | 352 ].forEach(function(name) { |
| 309 ChangePictureOptions[name] = function() { | 353 ChangePictureOptions[name] = function() { |
| 310 var instance = ChangePictureOptions.getInstance(); | 354 var instance = ChangePictureOptions.getInstance(); |
| 311 return instance[name + '_'].apply(instance, arguments); | 355 return instance[name + '_'].apply(instance, arguments); |
| 312 }; | 356 }; |
| 313 }); | 357 }); |
| 314 | 358 |
| 315 // Export | 359 // Export |
| 316 return { | 360 return { |
| 317 ChangePictureOptions: ChangePictureOptions | 361 ChangePictureOptions: ChangePictureOptions |
| 318 }; | 362 }; |
| 319 | 363 |
| 320 }); | 364 }); |
| OLD | NEW |