diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-23 07:07:02 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-23 07:07:02 +0000 |
commit | 02e0da600ccbd1a63857b8d4291901729487d10e (patch) | |
tree | 2efddd0e7d805e02cb7877be2697947fb51c7df3 /chrome/browser/resources/options/chromeos_language_list.js | |
parent | 119655003d8f225282179043e990df879062e529 (diff) | |
download | chromium_src-02e0da600ccbd1a63857b8d4291901729487d10e.zip chromium_src-02e0da600ccbd1a63857b8d4291901729487d10e.tar.gz chromium_src-02e0da600ccbd1a63857b8d4291901729487d10e.tar.bz2 |
Load preferred languages from user preferences.
Slowly making progress. :)
TEST=manually
BUG=chromium-os:4573
Review URL: http://codereview.chromium.org/2806060
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53443 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/resources/options/chromeos_language_list.js')
-rw-r--r-- | chrome/browser/resources/options/chromeos_language_list.js | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/chrome/browser/resources/options/chromeos_language_list.js b/chrome/browser/resources/options/chromeos_language_list.js new file mode 100644 index 0000000..cb4bc50 --- /dev/null +++ b/chrome/browser/resources/options/chromeos_language_list.js @@ -0,0 +1,71 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +cr.define('options.language', function() { + const List = cr.ui.List; + const ListItem = cr.ui.ListItem; + const ArrayDataModel = cr.ui.ArrayDataModel; + + /** + * Creates a new language list. + * @param {Object=} opt_propertyBag Optional properties. + * @constructor + * @extends {cr.ui.List} + */ + var LanguageList = cr.ui.define('list'); + + LanguageList.prototype = { + __proto__: List.prototype, + + pref: 'settings.language.preferred_languages', + + /** @inheritDoc */ + decorate: function() { + List.prototype.decorate.call(this); + + // HACK(arv): http://crbug.com/40902 + window.addEventListener('resize', cr.bind(this.redraw, this)); + + // Listens to pref change. + Preferences.getInstance().addEventListener(this.pref, + cr.bind(this.handlePrefChange_, this)); + }, + + createItem: function(languageCode) { + var languageDisplayName = localStrings.getString(languageCode); + return new ListItem({label: languageDisplayName}); + }, + + /** + * Handles pref change. + * @param {Event} event The change event object. + * @private + */ + handlePrefChange_: function(event) { + this.load_(event.value); + }, + + /** + * Loads given language list. + * @param {string} languageCodesInCsv A CSV string of language codes. + * @private + */ + load_: function(languageCodesInCsv) { + var languageCodes = languageCodesInCsv.split(','); + this.dataModel = new ArrayDataModel(languageCodes); + }, + + /** + * Updates backend. + */ + updateBackend_: function() { + // Encode the language codes into a CSV string. + Preferences.setStringPref(this.pref, this.dataModel.slice().join(',')); + }, + }; + + return { + LanguageList: LanguageList + }; +}); |