OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 */ var Command = cr.ui.Command; | 6 /** @const */ var 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 21 matching lines...) Expand all Loading... | |
32 decorate: function() { | 32 decorate: function() { |
33 var commandId; | 33 var commandId; |
34 if ((commandId = this.getAttribute('command'))) | 34 if ((commandId = this.getAttribute('command'))) |
35 this.command = commandId; | 35 this.command = commandId; |
36 | 36 |
37 this.addEventListener('mouseup', this.handleMouseUp_); | 37 this.addEventListener('mouseup', this.handleMouseUp_); |
38 | 38 |
39 // Adding the 'custom-appearance' class prevents widgets.css from changing | 39 // Adding the 'custom-appearance' class prevents widgets.css from changing |
40 // the appearance of this element. | 40 // the appearance of this element. |
41 this.classList.add('custom-appearance'); | 41 this.classList.add('custom-appearance'); |
42 | |
43 var iconUrl; | |
44 if ((iconUrl = this.getAttribute('icon'))) | |
45 this.iconUrl = iconUrl; | |
James Hawkins
2012/05/16 17:12:18
Why not:
this.iconUrl = this.getAttribute('icon')
Dmitry Zvorygin
2012/05/17 12:11:15
We don't want to set iconUrl to 'undefined'. Just
| |
42 }, | 46 }, |
43 | 47 |
44 /** | 48 /** |
45 * The command associated with this menu item. If this is set to a string | 49 * The command associated with this menu item. If this is set to a string |
46 * of the form "#element-id" then the element is looked up in the document | 50 * of the form "#element-id" then the element is looked up in the document |
47 * of the command. | 51 * of the command. |
48 * @type {cr.ui.Command} | 52 * @type {cr.ui.Command} |
49 */ | 53 */ |
50 command_: null, | 54 command_: null, |
51 get command() { | 55 get command() { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 * @type {string} | 89 * @type {string} |
86 */ | 90 */ |
87 get label() { | 91 get label() { |
88 return this.textContent; | 92 return this.textContent; |
89 }, | 93 }, |
90 set label(label) { | 94 set label(label) { |
91 this.textContent = label; | 95 this.textContent = label; |
92 }, | 96 }, |
93 | 97 |
94 /** | 98 /** |
99 * Menu icon. | |
100 * @type {string} | |
101 */ | |
102 get iconUrl() { | |
103 return this.style.backgroundImage; | |
104 }, | |
105 set iconUrl(url) { | |
106 this.style.backgroundImage = 'url(' + url + ')'; | |
107 }, | |
108 | |
109 /** | |
95 * @return {boolean} Whether the menu item is a separator. | 110 * @return {boolean} Whether the menu item is a separator. |
96 */ | 111 */ |
97 isSeparator: function() { | 112 isSeparator: function() { |
98 return this.tagName == 'HR'; | 113 return this.tagName == 'HR'; |
99 }, | 114 }, |
100 | 115 |
101 /** | 116 /** |
102 * Handles mouseup events. This dispatches an active event and if there | 117 * Handles mouseup events. This dispatches an active event and if there |
103 * is an assiciated command then that is executed. | 118 * is an assiciated command then that is executed. |
104 * @param {Event} The mouseup event object. | 119 * @param {Event} The mouseup event object. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 * Whether the menu item is checked or not. | 174 * Whether the menu item is checked or not. |
160 * @type {boolean} | 175 * @type {boolean} |
161 */ | 176 */ |
162 cr.defineProperty(MenuItem, 'checked', cr.PropertyKind.BOOL_ATTR); | 177 cr.defineProperty(MenuItem, 'checked', cr.PropertyKind.BOOL_ATTR); |
163 | 178 |
164 // Export | 179 // Export |
165 return { | 180 return { |
166 MenuItem: MenuItem | 181 MenuItem: MenuItem |
167 }; | 182 }; |
168 }); | 183 }); |
OLD | NEW |