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

Side by Side Diff: chrome/browser/resources/options/chromeos_language_list.js

Issue 3008016: Display the language name and the input method list dynamically. (Closed)
Patch Set: fix comments Created 10 years, 5 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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.language', function() { 5 cr.define('options.language', function() {
6 const List = cr.ui.List; 6 const List = cr.ui.List;
7 const ListItem = cr.ui.ListItem; 7 const ListItem = cr.ui.ListItem;
8 const ArrayDataModel = cr.ui.ArrayDataModel; 8 const ArrayDataModel = cr.ui.ArrayDataModel;
9 9
10 /** 10 /**
11 * Creates a new language list. 11 * Creates a new language list.
12 * @param {Object=} opt_propertyBag Optional properties. 12 * @param {Object=} opt_propertyBag Optional properties.
13 * @constructor 13 * @constructor
14 * @extends {cr.ui.List} 14 * @extends {cr.ui.List}
15 */ 15 */
16 var LanguageList = cr.ui.define('list'); 16 var LanguageList = cr.ui.define('list');
17 17
18 LanguageList.prototype = { 18 LanguageList.prototype = {
19 __proto__: List.prototype, 19 __proto__: List.prototype,
20 20
21 pref: 'settings.language.preferred_languages', 21 pref: 'settings.language.preferred_languages',
22 22
23 /** @inheritDoc */ 23 /** @inheritDoc */
24 decorate: function() { 24 decorate: function() {
25 List.prototype.decorate.call(this); 25 List.prototype.decorate.call(this);
26 26
27 // HACK(arv): http://crbug.com/40902 27 // HACK(arv): http://crbug.com/40902
28 window.addEventListener('resize', cr.bind(this.redraw, this)); 28 window.addEventListener('resize', cr.bind(this.redraw, this));
29 29
30 // Listens to pref change. 30 // Listen to pref change.
31 Preferences.getInstance().addEventListener(this.pref, 31 Preferences.getInstance().addEventListener(this.pref,
32 cr.bind(this.handlePrefChange_, this)); 32 cr.bind(this.handlePrefChange_, this));
33 }, 33 },
34 34
35 createItem: function(languageCode) { 35 createItem: function(languageCode) {
36 var languageDisplayName = localStrings.getString(languageCode); 36 var languageDisplayName = localStrings.getString(languageCode);
37 return new ListItem({label: languageDisplayName}); 37 return new ListItem({label: languageDisplayName});
38 }, 38 },
39 39
40 /** 40 /**
41 * Handles pref change. 41 * Handles pref change.
42 * @param {Event} event The change event object. 42 * @param {Event} e The change event object.
43 * @private 43 * @private
44 */ 44 */
45 handlePrefChange_: function(event) { 45 handlePrefChange_: function(e) {
46 this.load_(event.value); 46 this.load_(e.value);
47 }, 47 },
48 48
49 /** 49 /**
50 * Loads given language list. 50 * Loads given language list.
51 * @param {string} languageCodesInCsv A CSV string of language codes. 51 * @param {string} languageCodesInCsv A CSV string of language codes.
52 * @private 52 * @private
53 */ 53 */
54 load_: function(languageCodesInCsv) { 54 load_: function(languageCodesInCsv) {
55 var languageCodes = languageCodesInCsv.split(','); 55 var languageCodes = languageCodesInCsv.split(',');
56 this.dataModel = new ArrayDataModel(languageCodes); 56 this.dataModel = new ArrayDataModel(languageCodes);
57 // Select the first item if it's not empty.
58 // TODO(satorux): Switch to a single item selection model that does
59 // not allow no selection, one it's ready: crbug.com/49893
60 if (this.dataModel.length > 0)
61 this.selectionModel.selectedIndex = 0;
57 }, 62 },
58 63
59 /** 64 /**
60 * Updates backend. 65 * Updates backend.
61 */ 66 */
62 updateBackend_: function() { 67 updateBackend_: function() {
63 // Encode the language codes into a CSV string. 68 // Encode the language codes into a CSV string.
64 Preferences.setStringPref(this.pref, this.dataModel.slice().join(',')); 69 Preferences.setStringPref(this.pref, this.dataModel.slice().join(','));
65 }, 70 },
66 }; 71 };
67 72
68 return { 73 return {
69 LanguageList: LanguageList 74 LanguageList: LanguageList
70 }; 75 };
71 }); 76 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698