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 | 6 |
7 /** @const */ var MenuItem = cr.ui.MenuItem; | 7 /** @const */ var MenuItem = cr.ui.MenuItem; |
8 | 8 |
9 /** | 9 /** |
10 * Creates a new menu element. | 10 * Creates a new menu element. |
11 * @param {Object=} opt_propertyBag Optional properties. | 11 * @param {Object=} opt_propertyBag Optional properties. |
12 * @constructor | 12 * @constructor |
13 * @extends {HTMLMenuElement} | 13 * @extends {HTMLMenuElement} |
14 */ | 14 */ |
15 var Menu = cr.ui.define('menu'); | 15 var Menu = cr.ui.define('menu'); |
16 | 16 |
17 Menu.prototype = { | 17 Menu.prototype = { |
18 __proto__: HTMLMenuElement.prototype, | 18 __proto__: HTMLMenuElement.prototype, |
19 | 19 |
20 selectedIndex_: -1, | 20 selectedIndex_: -1, |
21 | 21 |
22 /** | 22 /** |
23 * Initializes the menu element. | 23 * Initializes the menu element. |
24 */ | 24 */ |
25 decorate: function() { | 25 decorate: function() { |
26 this.addEventListener('mouseover', this.handleMouseOver_); | 26 this.addEventListener('mouseover', this.handleMouseOver_); |
27 this.addEventListener('mouseout', this.handleMouseOut_); | 27 this.addEventListener('mouseout', this.handleMouseOut_); |
28 | 28 |
| 29 this.classList.add('decorated'); |
| 30 this.hidden = true; // Hide the menu by default. |
| 31 |
29 // Decorate the children as menu items. | 32 // Decorate the children as menu items. |
30 var children = this.children; | 33 var children = this.children; |
31 for (var i = 0, child; child = children[i]; i++) { | 34 for (var i = 0, child; child = children[i]; i++) { |
32 cr.ui.decorate(child, MenuItem); | 35 cr.ui.decorate(child, MenuItem); |
33 } | 36 } |
34 }, | 37 }, |
35 | 38 |
36 /** | 39 /** |
37 * Adds menu item at the end of the list. | 40 * Adds menu item at the end of the list. |
38 * @param {Object} item Menu item properties. | 41 * @param {Object} item Menu item properties. |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 * @type {number} | 186 * @type {number} |
184 */ | 187 */ |
185 cr.defineProperty(Menu, 'selectedIndex', cr.PropertyKind.JS, | 188 cr.defineProperty(Menu, 'selectedIndex', cr.PropertyKind.JS, |
186 selectedIndexChanged); | 189 selectedIndexChanged); |
187 | 190 |
188 // Export | 191 // Export |
189 return { | 192 return { |
190 Menu: Menu | 193 Menu: Menu |
191 }; | 194 }; |
192 }); | 195 }); |
OLD | NEW |