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

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

Issue 3051013: Add logic to save input method preference based on user clicks. (Closed)
Patch Set: address comments Created 10 years, 4 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
« no previous file with comments | « no previous file | chrome/browser/resources/options/chromeos_language_options.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 /**
(...skipping 25 matching lines...) Expand all
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} e The change event object. 42 * @param {Event} e The change event object.
43 * @private 43 * @private
44 */ 44 */
45 handlePrefChange_: function(e) { 45 handlePrefChange_: function(e) {
46 this.load_(e.value); 46 var languageCodesInCsv = e.value;
47 var languageCodes = this.filterBadLanguageCodes_(
48 languageCodesInCsv.split(','));
49 this.load_(languageCodes);
47 }, 50 },
48 51
49 /** 52 /**
50 * Loads given language list. 53 * Loads given language list.
51 * @param {string} languageCodesInCsv A CSV string of language codes. 54 * @param {Array} languageCodes List of language codes.
52 * @private 55 * @private
53 */ 56 */
54 load_: function(languageCodesInCsv) { 57 load_: function(languageCodes) {
55 var languageCodes = languageCodesInCsv.split(',');
56 this.dataModel = new ArrayDataModel(languageCodes); 58 this.dataModel = new ArrayDataModel(languageCodes);
57 // Select the first item if it's not empty. 59 // Select the first item if it's not empty.
58 // TODO(satorux): Switch to a single item selection model that does 60 // TODO(satorux): Switch to a single item selection model that does
59 // not allow no selection, one it's ready: crbug.com/49893 61 // not allow no selection, one it's ready: crbug.com/49893
60 if (this.dataModel.length > 0) 62 if (this.dataModel.length > 0)
61 this.selectionModel.selectedIndex = 0; 63 this.selectionModel.selectedIndex = 0;
62 }, 64 },
63 65
64 /** 66 /**
65 * Updates backend. 67 * Updates backend.
66 */ 68 */
67 updateBackend_: function() { 69 updateBackend_: function() {
68 // Encode the language codes into a CSV string. 70 // Encode the language codes into a CSV string.
69 Preferences.setStringPref(this.pref, this.dataModel.slice().join(',')); 71 Preferences.setStringPref(this.pref, this.dataModel.slice().join(','));
70 }, 72 },
73
74 /**
75 * Filters bad language codes in case bad language codes are
76 * stored in the preference.
77 * @param {Array} languageCodes List of language codes.
78 * @private
79 */
80 filterBadLanguageCodes_: function(languageCodes) {
81 var filteredLanguageCodes = [];
82 for (var i = 0; i < languageCodes.length; i++) {
83 // Check if the translation for the language code is
84 // present. Otherwise, skip it.
85 if (localStrings.getString(languageCodes[i])) {
86 filteredLanguageCodes.push(languageCodes[i]);
87 }
88 }
89 return filteredLanguageCodes;
90 },
71 }; 91 };
72 92
73 return { 93 return {
74 LanguageList: LanguageList 94 LanguageList: LanguageList
75 }; 95 };
76 }); 96 });
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/options/chromeos_language_options.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698