Chromium Code Reviews| Index: ui/webui/resources/js/cr/ui/menu_button.js |
| diff --git a/ui/webui/resources/js/cr/ui/menu_button.js b/ui/webui/resources/js/cr/ui/menu_button.js |
| index da5da947b9b3fa3f08ade60d2de4be31e5d88b57..c98b824c1382b0f0abd40272a18937e8f69e40fe 100644 |
| --- a/ui/webui/resources/js/cr/ui/menu_button.js |
| +++ b/ui/webui/resources/js/cr/ui/menu_button.js |
| @@ -2,6 +2,18 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +cr.exportPath('cr.ui'); |
| + |
| +/** |
| + * Enum for type of hide. Delayed is used when called by clicking on a |
| + * checkable menu item. |
| + * @enum {number} |
| + */ |
| +cr.ui.HideType = { |
| + INSTANT: 0, |
| + DELAYED: 1 |
| +}; |
| + |
| cr.define('cr.ui', function() { |
| /** @const */ |
| var Menu = cr.ui.Menu; |
| @@ -9,21 +21,12 @@ cr.define('cr.ui', function() { |
| /** @const */ |
| var positionPopupAroundElement = cr.ui.positionPopupAroundElement; |
| - /** |
| - * Enum for type of hide. Delayed is used when called by clicking on a |
| - * checkable menu item. |
| - * @enum {number} |
| - */ |
| - var HideType = { |
| - INSTANT: 0, |
| - DELAYED: 1 |
| - }; |
| - |
| /** |
| * Creates a new menu button element. |
| * @param {Object=} opt_propertyBag Optional properties. |
| * @constructor |
| * @extends {HTMLButtonElement} |
| + * @implements {EventListener} |
| */ |
| var MenuButton = cr.ui.define('button'); |
| @@ -90,7 +93,8 @@ cr.define('cr.ui', function() { |
| switch (e.type) { |
| case 'mousedown': |
| if (e.currentTarget == this.ownerDocument) { |
| - if (!this.contains(e.target) && !this.menu.contains(e.target)) |
| + if (e.target instanceof Element && !this.contains(e.target) && |
| + !this.menu.contains(e.target)) |
|
Dan Beam
2014/08/19 00:31:54
add curlies
Vitaly Pavlenko
2014/08/19 18:30:27
Done.
|
| this.hideMenu(); |
| else |
| e.preventDefault(); |
| @@ -123,7 +127,8 @@ cr.define('cr.ui', function() { |
| this.classList.remove('using-mouse'); |
| break; |
| case 'focus': |
| - if (!this.contains(e.target) && !this.menu.contains(e.target)) { |
| + if (e.target instanceof Element && !this.contains(e.target) && |
| + !this.menu.contains(e.target)) { |
| this.hideMenu(); |
| // Show the focus ring on focus - if it's come from a mouse event, |
| // the focus ring will be hidden in the mousedown event handler, |
| @@ -186,8 +191,8 @@ cr.define('cr.ui', function() { |
| /** |
| * Hides the menu. If your menu can go out of scope, make sure to call this |
| * first. |
| - * @param {HideType=} opt_hideType Type of hide. |
| - * default: HideType.INSTANT. |
| + * @param {cr.ui.HideType=} opt_hideType Type of hide. |
| + * default: cr.ui.HideType.INSTANT. |
| */ |
| hideMenu: function(opt_hideType) { |
| if (!this.isMenuShown()) |
| @@ -273,22 +278,22 @@ cr.define('cr.ui', function() { |
| * Create the images used to style drop-down-style MenuButtons. |
| * This should be called before creating any MenuButtons that will have the |
| * CSS class 'drop-down'. If no colors are specified, defaults will be used. |
| - * @param {=string} normalColor CSS color for the default button state. |
| - * @param {=string} hoverColor CSS color for the hover button state. |
| - * @param {=string} activeColor CSS color for the active button state. |
| + * @param {string=} opt_normalColor CSS color for the default button state. |
| + * @param {string=} opt_hoverColor CSS color for the hover button state. |
| + * @param {string=} opt_activeColor CSS color for the active button state. |
| */ |
| MenuButton.createDropDownArrows = function( |
| - normalColor, hoverColor, activeColor) { |
| - normalColor = normalColor || 'rgb(192, 195, 198)'; |
| - hoverColor = hoverColor || 'rgb(48, 57, 66)'; |
| - activeColor = activeColor || 'white'; |
| + opt_normalColor, opt_hoverColor, opt_activeColor) { |
| + opt_normalColor = opt_normalColor || 'rgb(192, 195, 198)'; |
| + opt_hoverColor = opt_hoverColor || 'rgb(48, 57, 66)'; |
| + opt_activeColor = opt_activeColor || 'white'; |
| createDropDownArrowCanvas( |
| - 'drop-down-arrow', ARROW_WIDTH, ARROW_HEIGHT, normalColor); |
| + 'drop-down-arrow', ARROW_WIDTH, ARROW_HEIGHT, opt_normalColor); |
| createDropDownArrowCanvas( |
| - 'drop-down-arrow-hover', ARROW_WIDTH, ARROW_HEIGHT, hoverColor); |
| + 'drop-down-arrow-hover', ARROW_WIDTH, ARROW_HEIGHT, opt_hoverColor); |
| createDropDownArrowCanvas( |
| - 'drop-down-arrow-active', ARROW_WIDTH, ARROW_HEIGHT, activeColor); |
| + 'drop-down-arrow-active', ARROW_WIDTH, ARROW_HEIGHT, opt_activeColor); |
| }; |
| // Export |