Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * WallpaperManager constructor. | |
| 7 * | |
| 8 * WallpaperManager objects encapsulate the functionality of the wallpaper | |
| 9 * picker dialogs. | |
| 10 * | |
| 11 * @constructor | |
| 12 * @param {HTMLElement} dialogDom The DOM node containing the prototypical | |
| 13 * dialog UI. | |
| 14 */ | |
| 15 | |
| 16 function WallpaperManager(dialogDom) { | |
| 17 this.dialogDom_ = dialogDom; | |
| 18 this.document_ = dialogDom.ownerDocument; | |
| 19 this.selectedCategory = null; | |
| 20 this.initDom_(); | |
| 21 } | |
| 22 | |
| 23 // Anonymous "namespace". | |
| 24 (function() { | |
| 25 | |
| 26 /** | |
| 27 * Translated strings. | |
| 28 */ | |
| 29 var localStrings; | |
| 30 | |
| 31 function CategoryItem(wallpaperManager, label) { | |
| 32 var li = wallpaperManager.document_.createElement('li'); | |
| 33 li.innerText = label; | |
| 34 li.addEventListener('click', | |
| 35 wallpaperManager.onCategoryItemClicked.bind(wallpaperManager)); | |
| 36 return li; | |
| 37 } | |
| 38 | |
| 39 /** | |
| 40 * Return a translated string. | |
| 41 * | |
| 42 * Wrapper function to make dealing with translated strings more concise. | |
| 43 * Equivilant to localStrings.getString(id). | |
| 44 * | |
| 45 * @param {string} id The id of the string to return. | |
| 46 * @return {string} The translated string. | |
| 47 */ | |
| 48 function str(id) { | |
| 49 return localStrings.getString(id) || ('UNLOCALIZED STRING ' + id); | |
| 50 } | |
| 51 | |
| 52 /** | |
| 53 * Load translated strings. | |
| 54 */ | |
| 55 WallpaperManager.initStrings = function(callback) { | |
| 56 chrome.experimental.wallpaperManager.getStrings(function(strings) { | |
| 57 localStrings = new LocalStrings(strings); | |
| 58 if (callback) | |
| 59 callback(); | |
| 60 }); | |
| 61 }; | |
| 62 | |
| 63 WallpaperManager.prototype.createCategoryItem_ = function(label) { | |
|
flackr
2012/07/12 19:40:51
Document.
| |
| 64 var li = this.document_.createElement('li'); | |
| 65 li.innerText = label; | |
| 66 li.addEventListener('click', this.onCategoryItemClicked.bind(this)); | |
| 67 return li; | |
| 68 }; | |
| 69 | |
| 70 /** | |
| 71 * One-time initialization of various DOM nodes. | |
| 72 */ | |
| 73 WallpaperManager.prototype.initDom_ = function() { | |
| 74 this.categoriesList = this.dialogDom_.querySelector('#categories-list'); | |
| 75 this.categoriesList.appendChild( | |
| 76 this.createCategoryItem_(str('FEATURED_LABEL'))); | |
|
flackr
2012/07/12 19:40:51
Perhaps createCategoryItem should also add the cat
| |
| 77 this.categoriesList.appendChild( | |
| 78 this.createCategoryItem_(str('NATURE_LABEL'))); | |
| 79 this.categoriesList.appendChild( | |
| 80 this.createCategoryItem_(str('ABSTRACT_LABEL'))); | |
| 81 this.categoriesList.appendChild( | |
| 82 this.createCategoryItem_(str('URBAN_LABEL'))); | |
| 83 this.categoriesList.appendChild( | |
| 84 this.createCategoryItem_(str('COLORS_LABEL'))); | |
| 85 this.categoriesList.appendChild( | |
| 86 this.createCategoryItem_(str('CUSTOM_LABEL'))); | |
| 87 }; | |
| 88 | |
| 89 WallpaperManager.prototype.onCategoryItemClicked = function(e) { | |
| 90 var newSelection = e.currentTarget; | |
| 91 if (this.selectedCategory == newSelection) | |
| 92 return; | |
| 93 | |
| 94 newSelection.classList.add('selected'); | |
| 95 if (this.selectedCategory) | |
| 96 this.selectedCategory.classList.remove('selected'); | |
| 97 this.selectedCategory = newSelection; | |
| 98 }; | |
| 99 | |
| 100 })(); | |
| OLD | NEW |