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

Side by Side Diff: chrome/browser/resources/settings/languages_page/languages_page.js

Issue 2675453002: Language settings: Fix unnecessarily shown move buttons (Closed)
Patch Set: prettier test Created 3 years, 10 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
OLDNEW
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 cr.exportPath('settings'); 9 cr.exportPath('settings');
10 10
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 this.showAddLanguagesDialog_ = true; 85 this.showAddLanguagesDialog_ = true;
86 this.async(function() { 86 this.async(function() {
87 var dialog = this.$$('settings-add-languages-dialog'); 87 var dialog = this.$$('settings-add-languages-dialog');
88 dialog.addEventListener('close', function() { 88 dialog.addEventListener('close', function() {
89 this.showAddLanguagesDialog_ = false; 89 this.showAddLanguagesDialog_ = false;
90 }.bind(this)); 90 }.bind(this));
91 }); 91 });
92 }, 92 },
93 93
94 /** 94 /**
95 * @param {number} n
96 * @param {!LanguageState} language
97 * @return {boolean} True if |language| is at the |n|th index in the list of
98 * enabled languages. Used to show or hide the "Move" buttons for ordering
99 * preferred languages.
stevenjb 2017/02/02 00:26:34 nit: Put 'Used to show or hide...' at top of comme
michaelpg 2017/02/02 19:38:36 Done.
100 * @private
101 */
102 isNthLanguage_: function(n, language) {
103 var compareLanguage = assert(this.languages.enabled[n]);
104 return language.language == compareLanguage.language;
105 },
106
107 /**
95 * @param {!LanguageState} language 108 * @param {!LanguageState} language
96 * @return {boolean} True if |language| is first in the list of enabled 109 * @return {boolean} True if the "Move to top" option for |language| should be
97 * languages. Used to hide the "Move up" option. 110 * visible.
98 * @private 111 * @private
99 */ 112 */
100 isFirstLanguage_: function(language) { 113 showMoveUp_: function(language) {
101 return language == this.languages.enabled[0]; 114 // "Move up" is a no-op for the top language, and redundant with
115 // "Move to top" for the 2nd language.
116 return !this.isNthLanguage_(0, language) &&
117 !this.isNthLanguage_(1, language);
102 }, 118 },
103 119
104 /** 120 /**
105 * @param {!LanguageState} language 121 * @param {!LanguageState} language
106 * @return {boolean} True if |language| is first or second in the list of 122 * @return {boolean} True if the "Move down" option for |language| should be
107 * enabled languages. Used to hide the "Move to top" option. 123 * visible.
108 * @private 124 * @private
109 */ 125 */
110 isFirstOrSecondLanguage_: function(language) { 126 showMoveDown_: function(language) {
111 return this.languages.enabled.slice(0, 2).includes(language); 127 return !this.isNthLanguage_(this.languages.enabled.length - 1, language);
112 }, 128 },
113 129
114 /** 130 /**
115 * @param {!LanguageState} language
116 * @return {boolean} True if |language| is last in the list of enabled
117 * languages. Used to hide the "Move down" option.
118 * @private
119 */
120 isLastLanguage_: function(language) {
121 return language == this.languages.enabled.slice(-1)[0];
122 },
123
124 /**
125 * @param {!Object} change Polymer change object for languages.enabled.*. 131 * @param {!Object} change Polymer change object for languages.enabled.*.
126 * @return {boolean} True if there are less than 2 languages. 132 * @return {boolean} True if there are less than 2 languages.
127 */ 133 */
128 isHelpTextHidden_: function(change) { 134 isHelpTextHidden_: function(change) {
129 return this.languages.enabled.length <= 1; 135 return this.languages.enabled.length <= 1;
130 }, 136 },
131 137
132 /** 138 /**
133 * @param {!LanguageState} languageState 139 * @param {!LanguageState} languageState
134 * @param {string} prospectiveUILanguage The chosen UI language. 140 * @param {string} prospectiveUILanguage The chosen UI language.
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 if (e.target.tagName == expandButtonTag) 543 if (e.target.tagName == expandButtonTag)
538 return; 544 return;
539 545
540 /** @type {!CrExpandButtonElement} */ 546 /** @type {!CrExpandButtonElement} */
541 var expandButton = e.currentTarget.querySelector(expandButtonTag); 547 var expandButton = e.currentTarget.querySelector(expandButtonTag);
542 assert(expandButton); 548 assert(expandButton);
543 expandButton.expanded = !expandButton.expanded; 549 expandButton.expanded = !expandButton.expanded;
544 }, 550 },
545 }); 551 });
546 })(); 552 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698