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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 if ((!cr.isChromeOS && !cr.isWindows) || loadTimeData.getBoolean('isGuest')) | 61 if ((!cr.isChromeOS && !cr.isWindows) || loadTimeData.getBoolean('isGuest')) |
62 return; | 62 return; |
63 | 63 |
64 // Set the prospective UI language. This won't take effect until a restart. | 64 // Set the prospective UI language. This won't take effect until a restart. |
65 var tapEvent = /** @type {!{model: !{item: !LanguageState}}} */(e); | 65 var tapEvent = /** @type {!{model: !{item: !LanguageState}}} */(e); |
66 if (tapEvent.model.item.language.supportsUI) | 66 if (tapEvent.model.item.language.supportsUI) |
67 this.languageHelper.setUILanguage(tapEvent.model.item.language.code); | 67 this.languageHelper.setUILanguage(tapEvent.model.item.language.code); |
68 }, | 68 }, |
69 | 69 |
70 /** | 70 /** |
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. | 71 * Handler for enabling or disabling spell check. |
82 * @param {!{target: Element, model: !{item: !LanguageState}}} e | 72 * @param {!{target: Element, model: !{item: !LanguageState}}} e |
83 */ | 73 */ |
84 onSpellCheckChange_: function(e) { | 74 onSpellCheckChange_: function(e) { |
85 this.languageHelper.toggleSpellCheck(e.model.item.language.code, | 75 this.languageHelper.toggleSpellCheck(e.model.item.language.code, |
86 e.target.checked); | 76 e.target.checked); |
87 }, | 77 }, |
88 | 78 |
89 /** @private */ | 79 /** @private */ |
90 onBackTap_: function() { | 80 onBackTap_: function() { |
91 this.$.pages.back(); | 81 this.$.pages.back(); |
92 }, | 82 }, |
93 | 83 |
94 /** | 84 /** |
95 * Stamps and opens the Add Languages dialog, registering a listener to | 85 * Stamps and opens the Add Languages dialog, registering a listener to |
96 * disable the dialog's dom-if again on close. | 86 * disable the dialog's dom-if again on close. |
97 * @private | 87 * @private |
98 */ | 88 */ |
99 onAddLanguagesTap_: function() { | 89 onAddLanguagesTap_: function() { |
100 this.showAddLanguagesDialog_ = true; | 90 this.showAddLanguagesDialog_ = true; |
101 this.async(function() { | 91 this.async(function() { |
102 var dialog = this.$$('settings-add-languages-dialog'); | 92 var dialog = this.$$('settings-add-languages-dialog'); |
103 dialog.addEventListener('close', function() { | 93 dialog.addEventListener('close', function() { |
104 this.showAddLanguagesDialog_ = false; | 94 this.showAddLanguagesDialog_ = false; |
105 }.bind(this)); | 95 }.bind(this)); |
106 }); | 96 }); |
107 }, | 97 }, |
108 | 98 |
109 /** | 99 /** |
110 * @param {number} index Index of the language in the list of languages. | 100 * @param {!LanguageState} language |
111 * @param {!Object} change Polymer change object for languages.enabled.*. | 101 * @return {boolean} True if |language| is first in the list of enabled |
112 * @return {boolean} True if the given language is the first one in the list | 102 * languages. Used to hide the "Move up" option. |
113 * of languages. | |
114 * @private | 103 * @private |
115 */ | 104 */ |
116 isFirstLanguage_: function(index, change) { | 105 isFirstLanguage_: function(language) { |
117 return index == 0; | 106 return language == this.languages.enabled[0]; |
118 }, | 107 }, |
119 | 108 |
120 /** | 109 /** |
121 * @param {number} index Index of the language in the list of languages. | 110 * @param {!LanguageState} language |
122 * @param {!Object} change Polymer change object for languages.enabled.*. | 111 * @return {boolean} True if |language| is last in the list of enabled |
123 * @return {boolean} True if the given language is the last one in the list of | 112 * languages. Used to hide the "Move down" option. |
124 * languages. | |
125 * @private | 113 * @private |
126 */ | 114 */ |
127 isLastLanguage_: function(index, change) { | 115 isLastLanguage_: function(language) { |
128 return index == this.languages.enabled.length - 1; | 116 return language == this.languages.enabled.slice(-1)[0]; |
129 }, | 117 }, |
130 | 118 |
131 /** | 119 /** |
132 * @param {!Object} change Polymer change object for languages.enabled.*. | 120 * @param {!Object} change Polymer change object for languages.enabled.*. |
133 * @return {boolean} True if there are less than 2 languages. | 121 * @return {boolean} True if there are less than 2 languages. |
134 */ | 122 */ |
135 isHelpTextHidden_: function(change) { | 123 isHelpTextHidden_: function(change) { |
136 return this.languages.enabled.length <= 1; | 124 return this.languages.enabled.length <= 1; |
137 }, | 125 }, |
138 | 126 |
139 /** | 127 /** |
140 * Moves the language up in the list. | 128 * Moves the language up in the list. |
141 * @param {!{model: !{item: !LanguageState}}} e | |
142 * @private | 129 * @private |
143 */ | 130 */ |
144 onMoveUpTap_: function(e) { | 131 onMoveUpTap_: function() { |
145 this.languageHelper.moveLanguage(e.model.item.language.code, -1); | 132 this.menu_.closeMenu(); |
133 this.languageHelper.moveLanguage(this.detailLanguage_.language.code, -1); | |
146 }, | 134 }, |
147 | 135 |
148 /** | 136 /** |
149 * Moves the language down in the list. | 137 * Moves the language down in the list. |
150 * @param {!{model: !{item: !LanguageState}}} e | |
151 * @private | 138 * @private |
152 */ | 139 */ |
153 onMoveDownTap_: function(e) { | 140 onMoveDownTap_: function() { |
154 this.languageHelper.moveLanguage(e.model.item.language.code, 1); | 141 this.menu_.closeMenu(); |
142 this.languageHelper.moveLanguage(this.detailLanguage_.language.code, 1); | |
155 }, | 143 }, |
156 | 144 |
157 /** | 145 /** |
158 * Disables the language. | 146 * Disables the language. |
159 * @param {!{model: !{item: !LanguageState}}} e | |
160 * @private | 147 * @private |
161 */ | 148 */ |
162 onRemoveLanguageTap_: function(e) { | 149 onRemoveLanguageTap_: function() { |
163 this.languageHelper.disableLanguage(e.model.item.language.code); | 150 this.menu_.closeMenu(); |
151 this.languageHelper.disableLanguage(this.detailLanguage_.language.code); | |
164 }, | 152 }, |
165 | 153 |
166 /** | 154 /** |
167 * Opens the Language Detail page for the language. | 155 * Opens the Language Detail page for the language. |
168 * @param {!{model: !{item: !LanguageState}}} e | |
169 * @private | 156 * @private |
170 */ | 157 */ |
171 onShowLanguageDetailTap_: function(e) { | 158 onShowLanguageDetailTap_: function() { |
172 this.detailLanguage_ = e.model.item; | 159 this.menu_.closeMenu(); |
173 settings.navigateTo(settings.Route.LANGUAGES_DETAIL); | 160 settings.navigateTo(settings.Route.LANGUAGES_DETAIL); |
174 }, | 161 }, |
175 | 162 |
176 /** | 163 /** |
177 * Opens the Manage Input Methods page. | 164 * Opens the Manage Input Methods page. |
178 * @private | 165 * @private |
179 */ | 166 */ |
180 onManageInputMethodsTap_: function() { | 167 onManageInputMethodsTap_: function() { |
181 assert(cr.isChromeOS); | 168 assert(cr.isChromeOS); |
182 settings.navigateTo(settings.Route.INPUT_METHODS); | 169 settings.navigateTo(settings.Route.INPUT_METHODS); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
341 | 328 |
342 /** | 329 /** |
343 * HACK(michaelpg): This is necessary to show the list when navigating to | 330 * HACK(michaelpg): This is necessary to show the list when navigating to |
344 * the sub-page. Remove this function when PolymerElements/neon-animation#60 | 331 * the sub-page. Remove this function when PolymerElements/neon-animation#60 |
345 * is fixed. | 332 * is fixed. |
346 * @param {string} tagName Name of the element containing the <iron-list>. | 333 * @param {string} tagName Name of the element containing the <iron-list>. |
347 */ | 334 */ |
348 forceRenderList_: function(tagName) { | 335 forceRenderList_: function(tagName) { |
349 this.$$(tagName).$$('iron-list').fire('iron-resize'); | 336 this.$$(tagName).$$('iron-list').fire('iron-resize'); |
350 }, | 337 }, |
338 | |
339 /** | |
340 * Opens or closes the shared menu at the location of the tapped item. | |
341 * @param {!Event} e | |
342 * @private | |
343 */ | |
344 toggleMenu_: function(e) { | |
345 e.stopPropagation(); // Prevent the tap event from closing the menu. | |
346 | |
347 this.detailLanguage_ = | |
348 /** @type {!{model: !{item: !LanguageState}}} */(e).model.item; | |
349 | |
350 // Ensure the template has been stamped. | |
351 if (!this.menu_) { | |
352 this.$.menuTemplate.if = true; | |
353 this.$.menuTemplate.render(); | |
stevenjb
2016/08/26 22:56:48
Nice. I assume this is more robust than data-bindi
michaelpg
2016/08/27 02:07:31
Yeah, I didn't want to interfere with the menu's o
| |
354 this.menu_ = /** @type {CrSharedMenuElement} */( | |
355 this.$$('cr-shared-menu')); | |
356 } | |
357 this.menu_.toggleMenu(e.target); | |
358 }, | |
351 }); | 359 }); |
352 })(); | 360 })(); |
OLD | NEW |