| 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 cr.define('cr.ui', function() { | 5 cr.define('cr.ui', function() { |
| 6 const Command = cr.ui.Command; | 6 const Command = cr.ui.Command; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Creates a new menu item element. | 9 * Creates a new menu item element. |
| 10 * @param {Object=} opt_propertyBag Optional properties. | 10 * @param {Object=} opt_propertyBag Optional properties. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 */ | 45 */ |
| 46 command_: null, | 46 command_: null, |
| 47 get command() { | 47 get command() { |
| 48 return this.command_; | 48 return this.command_; |
| 49 }, | 49 }, |
| 50 set command(command) { | 50 set command(command) { |
| 51 if (this.command_) { | 51 if (this.command_) { |
| 52 this.command_.removeEventListener('labelChange', this); | 52 this.command_.removeEventListener('labelChange', this); |
| 53 this.command_.removeEventListener('disabledChange', this); | 53 this.command_.removeEventListener('disabledChange', this); |
| 54 this.command_.removeEventListener('hiddenChange', this); | 54 this.command_.removeEventListener('hiddenChange', this); |
| 55 this.command_.removeEventListener('checkedChange', this); |
| 55 } | 56 } |
| 56 | 57 |
| 57 if (typeof command == 'string' && command[0] == '#') { | 58 if (typeof command == 'string' && command[0] == '#') { |
| 58 command = this.ownerDocument.getElementById(command.slice(1)); | 59 command = this.ownerDocument.getElementById(command.slice(1)); |
| 59 cr.ui.decorate(command, Command); | 60 cr.ui.decorate(command, Command); |
| 60 } | 61 } |
| 61 | 62 |
| 62 this.command_ = command; | 63 this.command_ = command; |
| 63 if (command) { | 64 if (command) { |
| 64 if (command.id) | 65 if (command.id) |
| 65 this.setAttribute('command', '#' + command.id); | 66 this.setAttribute('command', '#' + command.id); |
| 66 | 67 |
| 67 this.label = command.label; | 68 this.label = command.label; |
| 68 this.disabled = command.disabled; | 69 this.disabled = command.disabled; |
| 69 this.hidden = command.hidden; | 70 this.hidden = command.hidden; |
| 70 | 71 |
| 71 this.command_.addEventListener('labelChange', this); | 72 this.command_.addEventListener('labelChange', this); |
| 72 this.command_.addEventListener('disabledChange', this); | 73 this.command_.addEventListener('disabledChange', this); |
| 73 this.command_.addEventListener('hiddenChange', this); | 74 this.command_.addEventListener('hiddenChange', this); |
| 75 this.command_.addEventListener('checkedChange', this); |
| 74 } | 76 } |
| 75 }, | 77 }, |
| 76 | 78 |
| 77 /** | 79 /** |
| 78 * The text label. | 80 * The text label. |
| 79 * @type {string} | 81 * @type {string} |
| 80 */ | 82 */ |
| 81 get label() { | 83 get label() { |
| 82 return this.textContent; | 84 return this.textContent; |
| 83 }, | 85 }, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 switch (e.type) { | 119 switch (e.type) { |
| 118 case 'disabledChange': | 120 case 'disabledChange': |
| 119 this.disabled = this.command.disabled; | 121 this.disabled = this.command.disabled; |
| 120 break; | 122 break; |
| 121 case 'hiddenChange': | 123 case 'hiddenChange': |
| 122 this.hidden = this.command.hidden; | 124 this.hidden = this.command.hidden; |
| 123 break; | 125 break; |
| 124 case 'labelChange': | 126 case 'labelChange': |
| 125 this.label = this.command.label; | 127 this.label = this.command.label; |
| 126 break; | 128 break; |
| 129 case 'checkedChange': |
| 130 this.checked = this.command.checked; |
| 131 break; |
| 127 } | 132 } |
| 128 } | 133 } |
| 129 }; | 134 }; |
| 130 | 135 |
| 131 /** | 136 /** |
| 132 * Whether the menu item is disabled or not. | 137 * Whether the menu item is disabled or not. |
| 133 * @type {boolean} | 138 * @type {boolean} |
| 134 */ | 139 */ |
| 135 cr.defineProperty(MenuItem, 'disabled', cr.PropertyKind.BOOL_ATTR); | 140 cr.defineProperty(MenuItem, 'disabled', cr.PropertyKind.BOOL_ATTR); |
| 136 | 141 |
| 137 /** | 142 /** |
| 138 * Whether the menu item is hidden or not. | 143 * Whether the menu item is hidden or not. |
| 139 * @type {boolean} | 144 * @type {boolean} |
| 140 */ | 145 */ |
| 141 cr.defineProperty(MenuItem, 'hidden', cr.PropertyKind.BOOL_ATTR); | 146 cr.defineProperty(MenuItem, 'hidden', cr.PropertyKind.BOOL_ATTR); |
| 142 | 147 |
| 143 /** | 148 /** |
| 144 * Whether the menu item is selected or not. | 149 * Whether the menu item is selected or not. |
| 145 * @type {boolean} | 150 * @type {boolean} |
| 146 */ | 151 */ |
| 147 cr.defineProperty(MenuItem, 'selected', cr.PropertyKind.BOOL_ATTR); | 152 cr.defineProperty(MenuItem, 'selected', cr.PropertyKind.BOOL_ATTR); |
| 148 | 153 |
| 154 /** |
| 155 * Whether the menu item is checked or not. |
| 156 * @type {boolean} |
| 157 */ |
| 158 cr.defineProperty(MenuItem, 'checked', cr.PropertyKind.BOOL_ATTR); |
| 159 |
| 149 // Export | 160 // Export |
| 150 return { | 161 return { |
| 151 MenuItem: MenuItem | 162 MenuItem: MenuItem |
| 152 }; | 163 }; |
| 153 }); | 164 }); |
| OLD | NEW |