| 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 /** | 5 /** |
| 6 * @fileoverview | 6 * @fileoverview |
| 7 * Class representing a menu button and its associated menu items. | 7 * Class representing a menu button and its associated menu items. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 'use strict'; | 10 'use strict'; |
| 11 | 11 |
| 12 /** @suppress {duplicate} */ | 12 /** @suppress {duplicate} */ |
| 13 var remoting = remoting || {}; | 13 var remoting = remoting || {}; |
| 14 | 14 |
| 15 /** | 15 /** |
| 16 * @constructor | 16 * @constructor |
| 17 * @param {Element} container The element containing the <button> and <ul> | 17 * @param {Element} container The element containing the <button> and <ul> |
| 18 * elements comprising the menu. It should have the "menu-button" class. | 18 * elements comprising the menu. It should have the "menu-button" class. |
| 19 * @param {function():void=} opt_onShow Optional callback invoked before the | 19 * @param {function():void=} opt_onShow Optional callback invoked before the |
| 20 * menu is shown. | 20 * menu is shown. |
| 21 * @param {function():void=} opt_onHide Optional callback after before the | 21 * @param {function():void=} opt_onHide Optional callback after before the |
| 22 * menu is hidden. | 22 * menu is hidden. |
| 23 */ | 23 */ |
| 24 remoting.MenuButton = function(container, opt_onShow, opt_onHide) { | 24 remoting.MenuButton = function(container, opt_onShow, opt_onHide) { |
| 25 /** | 25 /** @private {HTMLElement} */ |
| 26 * @type {HTMLElement} | |
| 27 * @private | |
| 28 */ | |
| 29 this.button_ = /** @type {HTMLElement} */ | 26 this.button_ = /** @type {HTMLElement} */ |
| 30 (container.querySelector('button,.menu-button-activator')); | 27 (container.querySelector('button,.menu-button-activator')); |
| 31 | 28 |
| 32 /** | 29 /** @private {HTMLElement} */ |
| 33 * @type {HTMLElement} | |
| 34 * @private | |
| 35 */ | |
| 36 this.menu_ = /** @type {HTMLElement} */ (container.querySelector('ul')); | 30 this.menu_ = /** @type {HTMLElement} */ (container.querySelector('ul')); |
| 37 | 31 |
| 38 /** | 32 /** @private {undefined|function():void} */ |
| 39 * @type {undefined|function():void} | |
| 40 * @private | |
| 41 */ | |
| 42 this.onShow_ = opt_onShow; | 33 this.onShow_ = opt_onShow; |
| 43 | 34 |
| 44 /** | 35 /** @private {undefined|function():void} */ |
| 45 * @type {undefined|function():void} | |
| 46 * @private | |
| 47 */ | |
| 48 this.onHide_ = opt_onHide; | 36 this.onHide_ = opt_onHide; |
| 49 | 37 |
| 50 /** | 38 /** |
| 51 * Create a "click-trap" div covering the entire document, but below the | 39 * Create a "click-trap" div covering the entire document, but below the |
| 52 * menu in the z-order. This ensures the the menu can be closed by clicking | 40 * menu in the z-order. This ensures the the menu can be closed by clicking |
| 53 * anywhere. Note that adding this event handler to <body> is not enough, | 41 * anywhere. Note that adding this event handler to <body> is not enough, |
| 54 * because elements can prevent event propagation; specifically, the client | 42 * because elements can prevent event propagation; specifically, the client |
| 55 * plugin element does this. | 43 * plugin element does this. |
| 56 * | 44 * |
| 57 * @type {HTMLElement} | 45 * @private {HTMLElement} |
| 58 * @private | |
| 59 */ | 46 */ |
| 60 this.clickTrap_ = /** @type {HTMLElement} */ (document.createElement('div')); | 47 this.clickTrap_ = /** @type {HTMLElement} */ (document.createElement('div')); |
| 61 this.clickTrap_.classList.add('menu-button-click-trap'); | 48 this.clickTrap_.classList.add('menu-button-click-trap'); |
| 62 | 49 |
| 63 /** @type {remoting.MenuButton} */ | 50 /** @type {remoting.MenuButton} */ |
| 64 var that = this; | 51 var that = this; |
| 65 | 52 |
| 66 var closeHandler = function() { | 53 var closeHandler = function() { |
| 67 that.button_.classList.remove(remoting.MenuButton.BUTTON_ACTIVE_CLASS_); | 54 that.button_.classList.remove(remoting.MenuButton.BUTTON_ACTIVE_CLASS_); |
| 68 container.removeChild(that.clickTrap_); | 55 container.removeChild(that.clickTrap_); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 remoting.MenuButton.select = function(item, selected) { | 94 remoting.MenuButton.select = function(item, selected) { |
| 108 if (selected) { | 95 if (selected) { |
| 109 item.classList.add('selected'); | 96 item.classList.add('selected'); |
| 110 } else { | 97 } else { |
| 111 item.classList.remove('selected'); | 98 item.classList.remove('selected'); |
| 112 } | 99 } |
| 113 }; | 100 }; |
| 114 | 101 |
| 115 /** @const @private */ | 102 /** @const @private */ |
| 116 remoting.MenuButton.BUTTON_ACTIVE_CLASS_ = 'active'; | 103 remoting.MenuButton.BUTTON_ACTIVE_CLASS_ = 'active'; |
| OLD | NEW |