OLD | NEW |
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 /////////////////////////////////////////////////////////////////////////////// | 5 /////////////////////////////////////////////////////////////////////////////// |
6 // LanguageOptions class: | 6 // LanguageOptions class: |
7 | 7 |
8 /** | 8 /** |
9 * Encapsulated handling of ChromeOS language options page. | 9 * Encapsulated handling of ChromeOS language options page. |
10 * @constructor | 10 * @constructor |
11 */ | 11 */ |
12 function LanguageOptions(model) { | 12 function LanguageOptions(model) { |
13 OptionsPage.call(this, 'language', localStrings.getString('languagePage'), | 13 OptionsPage.call(this, 'language', localStrings.getString('languagePage'), |
14 'languagePage'); | 14 'languagePage'); |
15 } | 15 } |
16 | 16 |
17 cr.addSingletonGetter(LanguageOptions); | 17 cr.addSingletonGetter(LanguageOptions); |
18 | 18 |
19 // Inherit LanguageOptions from OptionsPage. | 19 // Inherit LanguageOptions from OptionsPage. |
20 LanguageOptions.prototype = { | 20 LanguageOptions.prototype = { |
21 __proto__: OptionsPage.prototype, | 21 __proto__: OptionsPage.prototype, |
22 | 22 |
23 /** | 23 /** |
24 * Initializes LanguageOptions page. | 24 * Initializes LanguageOptions page. |
25 * Calls base class implementation to starts preference initialization. | 25 * Calls base class implementation to starts preference initialization. |
26 */ | 26 */ |
27 initializePage: function() { | 27 initializePage: function() { |
28 OptionsPage.prototype.initializePage.call(this); | 28 OptionsPage.prototype.initializePage.call(this); |
29 | 29 |
30 options.language.LanguageList.decorate($('language-options-list')); | 30 var languageOptionsList = $('language-options-list'); |
| 31 options.language.LanguageList.decorate(languageOptionsList); |
| 32 |
| 33 languageOptionsList.addEventListener('change', |
| 34 cr.bind(this.handleLanguageOptionsListChange_, this)); |
31 | 35 |
32 this.addEventListener('visibleChange', | 36 this.addEventListener('visibleChange', |
33 cr.bind(this.handleVisibleChange_, this)); | 37 cr.bind(this.handleVisibleChange_, this)); |
| 38 |
| 39 this.initializeInputMethodList_(); |
34 }, | 40 }, |
35 | 41 |
36 languageListInitalized_: false, | 42 languageListInitalized_: false, |
37 | 43 |
38 /** | 44 /** |
| 45 * Initializes the input method list. |
| 46 */ |
| 47 initializeInputMethodList_: function() { |
| 48 var inputMethodList = $('language-options-input-method-list'); |
| 49 var inputMethodListData = templateData.inputMethodList; |
| 50 |
| 51 // Add all input methods, but make all of them invisible here. We'll |
| 52 // change the visibility in handleLanguageOptionsListChange_() based |
| 53 // on the selected language. Note that we only have less than 100 |
| 54 // input methods, so creating DOM nodes at once here should be ok. |
| 55 for (var i = 0; i < inputMethodListData.length; i++) { |
| 56 var inputMethod = inputMethodListData[i]; |
| 57 var input = document.createElement('input'); |
| 58 input.type = 'checkbox'; |
| 59 input.inputMethodId = inputMethod.id; |
| 60 |
| 61 var label = document.createElement('label'); |
| 62 label.appendChild(input); |
| 63 label.appendChild(document.createTextNode(inputMethod.displayName)); |
| 64 label.style.display = 'none'; |
| 65 label.languageCode = inputMethod.languageCode; |
| 66 |
| 67 inputMethodList.appendChild(label); |
| 68 } |
| 69 }, |
| 70 |
| 71 /** |
39 * Handler for OptionsPage's visible property change event. | 72 * Handler for OptionsPage's visible property change event. |
40 * @param {Event} e Property change event. | 73 * @param {Event} e Property change event. |
| 74 * @private |
41 */ | 75 */ |
42 handleVisibleChange_ : function(e) { | 76 handleVisibleChange_ : function(e) { |
43 if (!this.languageListInitalized_ && this.visible) { | 77 if (!this.languageListInitalized_ && this.visible) { |
44 this.languageListInitalized_ = true; | 78 this.languageListInitalized_ = true; |
45 $('language-options-list').redraw(); | 79 $('language-options-list').redraw(); |
46 } | 80 } |
| 81 }, |
| 82 |
| 83 /** |
| 84 * Handler for languageOptionsList's change event. |
| 85 * @param {Event} e Change event. |
| 86 * @private |
| 87 */ |
| 88 handleLanguageOptionsListChange_: function(e) { |
| 89 var languageOptionsList = $('language-options-list'); |
| 90 var index = languageOptionsList.selectionModel.selectedIndex; |
| 91 if (index == -1) |
| 92 return; |
| 93 |
| 94 var languageCode = languageOptionsList.dataModel.item(index); |
| 95 var languageDisplayName = localStrings.getString(languageCode); |
| 96 |
| 97 $('language-options-language-name').textContent = languageDisplayName; |
| 98 // TODO(satorux): The button text should be changed to |
| 99 // 'is_displayed_in_this_language', depending on the current UI |
| 100 // language. |
| 101 $('language-options-ui-language-button').textContent = ( |
| 102 localStrings.getString('display_in_this_language')); |
| 103 |
| 104 // Change the visibility of the input method list. Input methods that |
| 105 // matches |languageCode| will become visible. |
| 106 var inputMethodList = $('language-options-input-method-list'); |
| 107 var labels = inputMethodList.querySelectorAll('label'); |
| 108 for (var i = 0; i < labels.length; i++) { |
| 109 if (labels[i].languageCode == languageCode) { |
| 110 labels[i].style.display = 'block'; |
| 111 } else { |
| 112 labels[i].style.display = 'none'; |
| 113 } |
| 114 } |
47 } | 115 } |
48 }; | 116 }; |
OLD | NEW |