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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 * Selects user image with the given URL. | 233 * Selects user image with the given URL. |
234 * @param {string} url URL of the image to select. | 234 * @param {string} url URL of the image to select. |
235 * @private | 235 * @private |
236 */ | 236 */ |
237 setSelectedImage_: function(url) { | 237 setSelectedImage_: function(url) { |
238 $('user-image-grid').selectedItemUrl = url; | 238 $('user-image-grid').selectedItemUrl = url; |
239 }, | 239 }, |
240 | 240 |
241 /** | 241 /** |
242 * Appends default images to the image grid. Should only be called once. | 242 * Appends default images to the image grid. Should only be called once. |
243 * @param {Array.<string>} images An array of URLs to default images. | 243 * @param {Array.<{url: string, author: string, website: string}>} images |
| 244 * An array of default images data, including URL, author and website. |
244 * @private | 245 * @private |
245 */ | 246 */ |
246 setDefaultImages_: function(images) { | 247 setDefaultImages_: function(images) { |
247 var imageGrid = $('user-image-grid'); | 248 var imageGrid = $('user-image-grid'); |
248 for (var i = 0, url; url = images[i]; i++) { | 249 for (var i = 0, data; data = imagesData[i]; i++) { |
249 imageGrid.addItem(url); | 250 imageGrid.addItem(data.url); |
250 } | 251 } |
251 }, | 252 }, |
252 }; | 253 }; |
253 | 254 |
254 var ChangePictureOptionsWebRTCProto = { | 255 var ChangePictureOptionsWebRTCProto = { |
255 // Inherit ChangePictureOptions from OptionsPage. | 256 // Inherit ChangePictureOptions from OptionsPage. |
256 __proto__: options.OptionsPage.prototype, | 257 __proto__: options.OptionsPage.prototype, |
257 | 258 |
258 /** | 259 /** |
259 * Initializes ChangePictureOptions page. | 260 * Initializes ChangePictureOptions page. |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 */ | 383 */ |
383 handleImageSelected_: function() { | 384 handleImageSelected_: function() { |
384 var imageGrid = $('user-image-grid'); | 385 var imageGrid = $('user-image-grid'); |
385 var url = imageGrid.selectedItemUrl; | 386 var url = imageGrid.selectedItemUrl; |
386 // Ignore selection change caused by program itself and selection of one | 387 // Ignore selection change caused by program itself and selection of one |
387 // of the action buttons. | 388 // of the action buttons. |
388 if (!imageGrid.inProgramSelection && | 389 if (!imageGrid.inProgramSelection && |
389 url != ButtonImages.TAKE_PHOTO && url != ButtonImages.CHOOSE_FILE) { | 390 url != ButtonImages.TAKE_PHOTO && url != ButtonImages.CHOOSE_FILE) { |
390 chrome.send('selectImage', [url]); | 391 chrome.send('selectImage', [url]); |
391 } | 392 } |
| 393 // Update image attribution text. |
| 394 var image = imageGrid.selectedItem; |
| 395 $('user-image-author-name').textContent = image.author; |
| 396 $('user-image-author-website').textContent = image.website; |
| 397 $('user-image-author-website').href = image.website; |
| 398 $('user-image-attribution').style.visibility = |
| 399 (image.author || image.website) ? 'visible' : 'hidden'; |
392 }, | 400 }, |
393 | 401 |
394 /** | 402 /** |
395 * Handles image activation (by pressing Enter). | 403 * Handles image activation (by pressing Enter). |
396 * @private | 404 * @private |
397 */ | 405 */ |
398 handleImageActivated_: function() { | 406 handleImageActivated_: function() { |
399 switch ($('user-image-grid').selectedItemUrl) { | 407 switch ($('user-image-grid').selectedItemUrl) { |
400 case ButtonImages.TAKE_PHOTO: | 408 case ButtonImages.TAKE_PHOTO: |
401 this.handleTakePhoto_(); | 409 this.handleTakePhoto_(); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 * Selects user image with the given URL. | 462 * Selects user image with the given URL. |
455 * @param {string} url URL of the image to select. | 463 * @param {string} url URL of the image to select. |
456 * @private | 464 * @private |
457 */ | 465 */ |
458 setSelectedImage_: function(url) { | 466 setSelectedImage_: function(url) { |
459 $('user-image-grid').selectedItemUrl = url; | 467 $('user-image-grid').selectedItemUrl = url; |
460 }, | 468 }, |
461 | 469 |
462 /** | 470 /** |
463 * Appends default images to the image grid. Should only be called once. | 471 * Appends default images to the image grid. Should only be called once. |
464 * @param {Array.<string>} images An array of URLs to default images. | 472 * @param {Array.<{url: string, author: string, website: string}>} images |
| 473 * An array of default images data, including URL, author and website. |
465 * @private | 474 * @private |
466 */ | 475 */ |
467 setDefaultImages_: function(images) { | 476 setDefaultImages_: function(imagesData) { |
468 var imageGrid = $('user-image-grid'); | 477 var imageGrid = $('user-image-grid'); |
469 for (var i = 0, url; url = images[i]; i++) { | 478 for (var i = 0, data; data = imagesData[i]; i++) { |
470 imageGrid.addItem(url).type = 'default'; | 479 var item = imageGrid.addItem(data.url); |
| 480 item.type = 'default'; |
| 481 item.author = data.author; |
| 482 item.website = data.website; |
471 } | 483 } |
472 }, | 484 }, |
473 }; | 485 }; |
474 | 486 |
475 // Forward public APIs to private implementations. | 487 // Forward public APIs to private implementations. |
476 [ | 488 [ |
477 'setCameraPresent', | 489 'setCameraPresent', |
478 'setDefaultImages', | 490 'setDefaultImages', |
479 'setOldImage', | 491 'setOldImage', |
480 'setProfileImage', | 492 'setProfileImage', |
481 'setSelectedImage', | 493 'setSelectedImage', |
482 ].forEach(function(name) { | 494 ].forEach(function(name) { |
483 ChangePictureOptions[name] = function() { | 495 ChangePictureOptions[name] = function() { |
484 var instance = ChangePictureOptions.getInstance(); | 496 var instance = ChangePictureOptions.getInstance(); |
485 return instance[name + '_'].apply(instance, arguments); | 497 return instance[name + '_'].apply(instance, arguments); |
486 }; | 498 }; |
487 }); | 499 }); |
488 | 500 |
489 // Export | 501 // Export |
490 return { | 502 return { |
491 ChangePictureOptions: ChangePictureOptions | 503 ChangePictureOptions: ChangePictureOptions |
492 }; | 504 }; |
493 | 505 |
494 }); | 506 }); |
OLD | NEW |