Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: chrome/browser/resources/chromeos/wallpaper_manager/js/wallpaper_manager.js

Issue 10453032: Add wallpaper experimental api framework and add a simple category list. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 /**
64 * One-time initialization of various DOM nodes.
65 */
66 WallpaperManager.prototype.initDom_ = function() {
67 this.categoriesList = this.dialogDom_.querySelector('#categories-list');
68 this.categoriesList.appendChild(CategoryItem(this, str('FEATURED_LABEL')));
69 this.categoriesList.appendChild(CategoryItem(this, str('NATURE_LABEL')));
70 this.categoriesList.appendChild(CategoryItem(this, str('ABSTRACT_LABEL')));
71 this.categoriesList.appendChild(CategoryItem(this, str('URBAN_LABEL')));
72 this.categoriesList.appendChild(CategoryItem(this, str('COLORS_LABEL')));
73 this.categoriesList.appendChild(CategoryItem(this, str('CUSTOM_LABEL')));
74 };
75
76 WallpaperManager.prototype.onCategoryItemClicked = function(e) {
77 var newSelection = e.currentTarget;
78 if (this.selectedCategory == newSelection)
79 return;
80
81 newSelection.classList.add('selected');
82 if (this.selectedCategory)
83 this.selectedCategory.classList.remove('selected');
84 this.selectedCategory = newSelection;
85 };
86
87 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698