Chromium Code Reviews| 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 * The |name| is shown in the gui. The |value| us use to set or compare with | 6 * The |name| is shown in the gui. The |value| us use to set or compare with |
| 7 * the preference value. | 7 * the preference value. |
| 8 * @typedef {{ | 8 * @typedef {{ |
| 9 * name: string, | 9 * name: string, |
| 10 * value: (number|string) | 10 * value: (number|string) |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 */ | 28 */ |
| 29 Polymer({ | 29 Polymer({ |
| 30 is: 'settings-dropdown-menu', | 30 is: 'settings-dropdown-menu', |
| 31 | 31 |
| 32 properties: { | 32 properties: { |
| 33 /** A text label for the drop-down menu. */ | 33 /** A text label for the drop-down menu. */ |
| 34 label: String, | 34 label: String, |
| 35 | 35 |
| 36 /** | 36 /** |
| 37 * List of options for the drop-down menu. | 37 * List of options for the drop-down menu. |
| 38 * @type {DropdownMenuOptionList} | 38 * @type {!DropdownMenuOptionList} |
| 39 */ | 39 */ |
| 40 menuOptions: { | 40 menuOptions: { |
| 41 type: Array, | 41 type: Array, |
| 42 value: function() { return []; }, | 42 value: function() { return []; }, |
| 43 }, | 43 }, |
| 44 | 44 |
| 45 /** Whether the dropdown menu should be disabled. */ | 45 /** Whether the dropdown menu should be disabled. */ |
| 46 disabled: { | 46 disabled: { |
| 47 type: Boolean, | 47 type: Boolean, |
| 48 reflectToAttribute: true, | 48 reflectToAttribute: true, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 this.selected_, this.pref); | 113 this.selected_, this.pref); |
| 114 if (prefValue !== undefined) | 114 if (prefValue !== undefined) |
| 115 this.set('pref.value', prefValue); | 115 this.set('pref.value', prefValue); |
| 116 }, | 116 }, |
| 117 | 117 |
| 118 /** | 118 /** |
| 119 * Updates the selected item when the pref or menuOptions change. | 119 * Updates the selected item when the pref or menuOptions change. |
| 120 * @private | 120 * @private |
| 121 */ | 121 */ |
| 122 updateSelected_: function() { | 122 updateSelected_: function() { |
| 123 if (!this.pref) | 123 if (!this.pref || !this.menuOptions.length) |
| 124 return; | 124 return; |
| 125 var prefValue = this.pref.value; | 125 var prefValue = this.pref.value; |
| 126 var option = this.menuOptions.find(function(menuItem) { | 126 var option = this.menuOptions.find(function(menuItem) { |
| 127 return menuItem.value == prefValue; | 127 return menuItem.value == prefValue; |
| 128 }); | 128 }); |
| 129 if (option == undefined) | 129 if (option == undefined) |
| 130 this.selected_ = this.notFoundValue_; | 130 this.selected_ = this.notFoundValue_; |
| 131 else | 131 else |
| 132 this.selected_ = Settings.PrefUtil.prefToString(this.pref); | 132 this.selected_ = Settings.PrefUtil.prefToString(this.pref); |
| 133 }, | 133 }, |
| 134 | 134 |
| 135 /** | 135 /** |
| 136 * @param {string} selected | 136 * @param {string} selected |
| 137 * @return {boolean} | 137 * @return {boolean} |
| 138 * @private | 138 * @private |
| 139 */ | 139 */ |
| 140 isSelectedNotFound_: function(selected) { | 140 isSelectedNotFound_: function(selected) { |
| 141 return this.menuOptions && selected == this.notFoundValue_; | 141 return this.menuOptions.length > 0 && selected == this.notFoundValue_; |
|
Dan Beam
2016/08/11 00:18:23
bummer
| |
| 142 }, | 142 }, |
| 143 | 143 |
| 144 /** | 144 /** |
| 145 * @return {boolean} | 145 * @return {boolean} |
| 146 * @private | 146 * @private |
| 147 */ | 147 */ |
| 148 shouldDisableMenu_: function() { | 148 shouldDisableMenu_: function() { |
| 149 return this.disabled || !this.menuOptions.length; | 149 return this.disabled || !this.menuOptions.length; |
| 150 }, | 150 }, |
| 151 }); | 151 }); |
| OLD | NEW |