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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 this.iconUrl = iconUrl; | 51 this.iconUrl = iconUrl; |
52 }, | 52 }, |
53 | 53 |
54 /** | 54 /** |
55 * The command associated with this menu item. If this is set to a string | 55 * The command associated with this menu item. If this is set to a string |
56 * of the form "#element-id" then the element is looked up in the document | 56 * of the form "#element-id" then the element is looked up in the document |
57 * of the command. | 57 * of the command. |
58 * @type {cr.ui.Command} | 58 * @type {cr.ui.Command} |
59 */ | 59 */ |
60 command_: null, | 60 command_: null, |
61 get command() { return this.command_; }, | 61 get command() { |
| 62 return this.command_; |
| 63 }, |
62 set command(command) { | 64 set command(command) { |
63 if (this.command_) { | 65 if (this.command_) { |
64 this.command_.removeEventListener('labelChange', this); | 66 this.command_.removeEventListener('labelChange', this); |
65 this.command_.removeEventListener('disabledChange', this); | 67 this.command_.removeEventListener('disabledChange', this); |
66 this.command_.removeEventListener('hiddenChange', this); | 68 this.command_.removeEventListener('hiddenChange', this); |
67 this.command_.removeEventListener('checkedChange', this); | 69 this.command_.removeEventListener('checkedChange', this); |
68 } | 70 } |
69 | 71 |
70 if (typeof command == 'string' && command[0] == '#') { | 72 if (typeof command == 'string' && command[0] == '#') { |
71 command = assert(this.ownerDocument.getElementById(command.slice(1))); | 73 command = assert(this.ownerDocument.getElementById(command.slice(1))); |
(...skipping 17 matching lines...) Expand all Loading... |
89 this.command_.addEventListener('checkedChange', this); | 91 this.command_.addEventListener('checkedChange', this); |
90 } | 92 } |
91 | 93 |
92 this.updateShortcut_(); | 94 this.updateShortcut_(); |
93 }, | 95 }, |
94 | 96 |
95 /** | 97 /** |
96 * The text label. | 98 * The text label. |
97 * @type {string} | 99 * @type {string} |
98 */ | 100 */ |
99 get label() { return this.textContent; }, | 101 get label() { |
100 set label(label) { this.textContent = label; }, | 102 return this.textContent; |
| 103 }, |
| 104 set label(label) { |
| 105 this.textContent = label; |
| 106 }, |
101 | 107 |
102 /** | 108 /** |
103 * Menu icon. | 109 * Menu icon. |
104 * @type {string} | 110 * @type {string} |
105 */ | 111 */ |
106 get iconUrl() { return this.style.backgroundImage; }, | 112 get iconUrl() { |
107 set iconUrl(url) { this.style.backgroundImage = 'url(' + url + ')'; }, | 113 return this.style.backgroundImage; |
| 114 }, |
| 115 set iconUrl(url) { |
| 116 this.style.backgroundImage = 'url(' + url + ')'; |
| 117 }, |
108 | 118 |
109 /** | 119 /** |
110 * @return {boolean} Whether the menu item is a separator. | 120 * @return {boolean} Whether the menu item is a separator. |
111 */ | 121 */ |
112 isSeparator: function() { return this.tagName == 'HR'; }, | 122 isSeparator: function() { |
| 123 return this.tagName == 'HR'; |
| 124 }, |
113 | 125 |
114 /** | 126 /** |
115 * Updates shortcut text according to associated command. If command has | 127 * Updates shortcut text according to associated command. If command has |
116 * multiple shortcuts, only first one is displayed. | 128 * multiple shortcuts, only first one is displayed. |
117 */ | 129 */ |
118 updateShortcut_: function() { | 130 updateShortcut_: function() { |
119 this.removeAttribute('shortcutText'); | 131 this.removeAttribute('shortcutText'); |
120 | 132 |
121 if (!this.command_ || !this.command_.shortcut || | 133 if (!this.command_ || !this.command_.shortcut || |
122 this.command_.hideShortcutText) | 134 this.command_.hideShortcutText) |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 cr.defineProperty(MenuItem, 'checked', cr.PropertyKind.BOOL_ATTR); | 262 cr.defineProperty(MenuItem, 'checked', cr.PropertyKind.BOOL_ATTR); |
251 | 263 |
252 /** | 264 /** |
253 * Whether the menu item is checkable or not. | 265 * Whether the menu item is checkable or not. |
254 */ | 266 */ |
255 cr.defineProperty(MenuItem, 'checkable', cr.PropertyKind.BOOL_ATTR); | 267 cr.defineProperty(MenuItem, 'checkable', cr.PropertyKind.BOOL_ATTR); |
256 | 268 |
257 // Export | 269 // Export |
258 return {MenuItem: MenuItem}; | 270 return {MenuItem: MenuItem}; |
259 }); | 271 }); |
OLD | NEW |