OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 * @fileoverview 'settings-languages-page' is the settings page | 6 * @fileoverview 'settings-languages-page' is the settings page |
7 * for language and input method settings. | 7 * for language and input method settings. |
8 */ | 8 */ |
9 (function() { | 9 (function() { |
10 'use strict'; | 10 'use strict'; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 * The language to display the details for. | 44 * The language to display the details for. |
45 * @type {!LanguageState|undefined} | 45 * @type {!LanguageState|undefined} |
46 * @private | 46 * @private |
47 */ | 47 */ |
48 detailLanguage_: Object, | 48 detailLanguage_: Object, |
49 | 49 |
50 /** @private */ | 50 /** @private */ |
51 showAddLanguagesDialog_: Boolean, | 51 showAddLanguagesDialog_: Boolean, |
52 }, | 52 }, |
53 | 53 |
54 ready: function() { | |
55 this.menu_ = /** @type {CrSharedMenuElement} */(this.$$('cr-shared-menu')); | |
56 }, | |
57 | |
54 /** | 58 /** |
55 * Handler for clicking a language on the main page, which selects the | 59 * Handler for clicking a language on the main page, which selects the |
56 * language as the prospective UI language on Chrome OS and Windows. | 60 * language as the prospective UI language on Chrome OS and Windows. |
57 * @param {!Event} e The tap event. | 61 * @param {!Event} e The tap event. |
58 */ | 62 */ |
59 onLanguageTap_: function(e) { | 63 onLanguageTap_: function(e) { |
60 // Only change the UI language on platforms that allow it. | 64 // Only change the UI language on platforms that allow it. |
61 if ((!cr.isChromeOS && !cr.isWindows) || loadTimeData.getBoolean('isGuest')) | 65 if ((!cr.isChromeOS && !cr.isWindows) || loadTimeData.getBoolean('isGuest')) |
62 return; | 66 return; |
63 | 67 |
64 // Set the prospective UI language. This won't take effect until a restart. | 68 // Set the prospective UI language. This won't take effect until a restart. |
65 var tapEvent = /** @type {!{model: !{item: !LanguageState}}} */(e); | 69 var tapEvent = /** @type {!{model: !{item: !LanguageState}}} */(e); |
66 if (tapEvent.model.item.language.supportsUI) | 70 if (tapEvent.model.item.language.supportsUI) |
67 this.languageHelper.setUILanguage(tapEvent.model.item.language.code); | 71 this.languageHelper.setUILanguage(tapEvent.model.item.language.code); |
68 }, | 72 }, |
69 | 73 |
70 /** | 74 /** |
71 * Stops tap events on the language options menu, its trigger, or its items | |
72 * from bubbling up to the language itself. Tap events on the language are | |
73 * handled in onLanguageTap_. | |
74 * @param {!Event} e The tap event. | |
75 */ | |
76 stopPropagationHandler_: function(e) { | |
77 e.stopPropagation(); | |
78 }, | |
79 | |
80 /** | |
81 * Handler for enabling or disabling spell check. | 75 * Handler for enabling or disabling spell check. |
82 * @param {!{target: Element, model: !{item: !LanguageState}}} e | 76 * @param {!{target: Element, model: !{item: !LanguageState}}} e |
83 */ | 77 */ |
84 onSpellCheckChange_: function(e) { | 78 onSpellCheckChange_: function(e) { |
85 this.languageHelper.toggleSpellCheck(e.model.item.language.code, | 79 this.languageHelper.toggleSpellCheck(e.model.item.language.code, |
86 e.target.checked); | 80 e.target.checked); |
87 }, | 81 }, |
88 | 82 |
89 /** @private */ | 83 /** @private */ |
90 onBackTap_: function() { | 84 onBackTap_: function() { |
91 this.$.pages.back(); | 85 this.$.pages.back(); |
92 }, | 86 }, |
93 | 87 |
94 /** | 88 /** |
95 * Stamps and opens the Add Languages dialog, registering a listener to | 89 * Stamps and opens the Add Languages dialog, registering a listener to |
96 * disable the dialog's dom-if again on close. | 90 * disable the dialog's dom-if again on close. |
97 * @private | 91 * @private |
98 */ | 92 */ |
99 onAddLanguagesTap_: function() { | 93 onAddLanguagesTap_: function() { |
100 this.showAddLanguagesDialog_ = true; | 94 this.showAddLanguagesDialog_ = true; |
101 this.async(function() { | 95 this.async(function() { |
102 var dialog = this.$$('settings-add-languages-dialog'); | 96 var dialog = this.$$('settings-add-languages-dialog'); |
103 dialog.addEventListener('close', function() { | 97 dialog.addEventListener('close', function() { |
104 this.showAddLanguagesDialog_ = false; | 98 this.showAddLanguagesDialog_ = false; |
105 }.bind(this)); | 99 }.bind(this)); |
106 }); | 100 }); |
107 }, | 101 }, |
108 | 102 |
109 /** | 103 /** |
110 * @param {number} index Index of the language in the list of languages. | 104 * @return {boolean} True if |language| is first in the list of enabled |
111 * @param {!Object} change Polymer change object for languages.enabled.*. | 105 * languages. Used to hide the "Move up" option. |
112 * @return {boolean} True if the given language is the first one in the list | |
113 * of languages. | |
114 * @private | 106 * @private |
115 */ | 107 */ |
116 isFirstLanguage_: function(index, change) { | 108 isFirstLanguage_: function(language) { |
stevenjb
2016/08/25 16:36:57
@param for language
michaelpg
2016/08/26 22:16:21
Done.
| |
117 return index == 0; | 109 return language == this.languages.enabled[0]; |
118 }, | 110 }, |
119 | 111 |
120 /** | 112 /** |
121 * @param {number} index Index of the language in the list of languages. | 113 * @return {boolean} True if |language| is last in the list of enabled |
122 * @param {!Object} change Polymer change object for languages.enabled.*. | 114 * languages. Used to hide the "Move down" option. |
123 * @return {boolean} True if the given language is the last one in the list of | |
124 * languages. | |
125 * @private | 115 * @private |
126 */ | 116 */ |
127 isLastLanguage_: function(index, change) { | 117 isLastLanguage_: function(language) { |
stevenjb
2016/08/25 16:36:57
ditto
michaelpg
2016/08/26 22:16:20
Done.
| |
128 return index == this.languages.enabled.length - 1; | 118 return language == this.languages.enabled.slice(-1)[0]; |
stevenjb
2016/08/25 16:36:57
eww, but I guess that's JS for you. (I did a sear
michaelpg
2016/08/26 22:16:20
pretty sure creating a 1-length array containing a
| |
129 }, | 119 }, |
130 | 120 |
131 /** | 121 /** |
132 * @param {!Object} change Polymer change object for languages.enabled.*. | 122 * @param {!Object} change Polymer change object for languages.enabled.*. |
133 * @return {boolean} True if there are less than 2 languages. | 123 * @return {boolean} True if there are less than 2 languages. |
134 */ | 124 */ |
135 isHelpTextHidden_: function(change) { | 125 isHelpTextHidden_: function(change) { |
136 return this.languages.enabled.length <= 1; | 126 return this.languages.enabled.length <= 1; |
137 }, | 127 }, |
138 | 128 |
139 /** | 129 /** |
140 * Moves the language up in the list. | 130 * Moves the language up in the list. |
141 * @param {!{model: !{item: !LanguageState}}} e | |
142 * @private | 131 * @private |
143 */ | 132 */ |
144 onMoveUpTap_: function(e) { | 133 onMoveUpTap_: function(e) { |
stevenjb
2016/08/25 16:36:57
elim (e) if unused
michaelpg
2016/08/26 22:16:20
Done.
| |
145 this.languageHelper.moveLanguage(e.model.item.language.code, -1); | 134 this.menu_.closeMenu(); |
135 this.languageHelper.moveLanguage(this.detailLanguage_.language.code, -1); | |
146 }, | 136 }, |
147 | 137 |
148 /** | 138 /** |
149 * Moves the language down in the list. | 139 * Moves the language down in the list. |
150 * @param {!{model: !{item: !LanguageState}}} e | |
151 * @private | 140 * @private |
152 */ | 141 */ |
153 onMoveDownTap_: function(e) { | 142 onMoveDownTap_: function(e) { |
154 this.languageHelper.moveLanguage(e.model.item.language.code, 1); | 143 this.menu_.closeMenu(); |
144 this.languageHelper.moveLanguage(this.detailLanguage_.language.code, 1); | |
155 }, | 145 }, |
156 | 146 |
157 /** | 147 /** |
158 * Disables the language. | 148 * Disables the language. |
159 * @param {!{model: !{item: !LanguageState}}} e | |
160 * @private | 149 * @private |
161 */ | 150 */ |
162 onRemoveLanguageTap_: function(e) { | 151 onRemoveLanguageTap_: function(e) { |
163 this.languageHelper.disableLanguage(e.model.item.language.code); | 152 this.menu_.closeMenu(); |
153 this.languageHelper.disableLanguage(this.detailLanguage_.language.code); | |
164 }, | 154 }, |
165 | 155 |
166 /** | 156 /** |
167 * Opens the Language Detail page for the language. | 157 * Opens the Language Detail page for the language. |
168 * @param {!{model: !{item: !LanguageState}}} e | |
169 * @private | 158 * @private |
170 */ | 159 */ |
171 onShowLanguageDetailTap_: function(e) { | 160 onShowLanguageDetailTap_: function() { |
172 this.detailLanguage_ = e.model.item; | 161 this.menu_.closeMenu(); |
173 settings.navigateTo(settings.Route.LANGUAGES_DETAIL); | 162 settings.navigateTo(settings.Route.LANGUAGES_DETAIL); |
174 }, | 163 }, |
175 | 164 |
176 /** | 165 /** |
177 * Opens the Manage Input Methods page. | 166 * Opens the Manage Input Methods page. |
178 * @private | 167 * @private |
179 */ | 168 */ |
180 onManageInputMethodsTap_: function() { | 169 onManageInputMethodsTap_: function() { |
181 assert(cr.isChromeOS); | 170 assert(cr.isChromeOS); |
182 settings.navigateTo(settings.Route.INPUT_METHODS); | 171 settings.navigateTo(settings.Route.INPUT_METHODS); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
341 | 330 |
342 /** | 331 /** |
343 * HACK(michaelpg): This is necessary to show the list when navigating to | 332 * HACK(michaelpg): This is necessary to show the list when navigating to |
344 * the sub-page. Remove this function when PolymerElements/neon-animation#60 | 333 * the sub-page. Remove this function when PolymerElements/neon-animation#60 |
345 * is fixed. | 334 * is fixed. |
346 * @param {string} tagName Name of the element containing the <iron-list>. | 335 * @param {string} tagName Name of the element containing the <iron-list>. |
347 */ | 336 */ |
348 forceRenderList_: function(tagName) { | 337 forceRenderList_: function(tagName) { |
349 this.$$(tagName).$$('iron-list').fire('iron-resize'); | 338 this.$$(tagName).$$('iron-list').fire('iron-resize'); |
350 }, | 339 }, |
340 | |
341 toggleMenu_: function(e) { | |
stevenjb
2016/08/25 16:36:57
@param for e
michaelpg
2016/08/26 22:16:20
Done.
| |
342 e.stopPropagation(); // Prevent the tap event from closing the menu. | |
343 | |
344 this.detailLanguage_ = e.model.item; | |
345 this.menu_.toggleMenu(e.target, e.model.item); | |
346 }, | |
351 }); | 347 }); |
352 })(); | 348 })(); |
OLD | NEW |