Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1485)

Unified Diff: remoting/webapp/menu_button.js

Issue 592793003: Make pop-up menus more easily dismissable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add click-trap to the container element, not the body Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/webapp/menu_button.js
diff --git a/remoting/webapp/menu_button.js b/remoting/webapp/menu_button.js
index 73c7642d1e12995b339dc54294ea9219f16a66a0..f2dac45b8086c45bf37b5f97d2252f5a087e1253 100644
--- a/remoting/webapp/menu_button.js
+++ b/remoting/webapp/menu_button.js
@@ -47,35 +47,35 @@ remoting.MenuButton = function(container, opt_onShow, opt_onHide) {
*/
this.onHide_ = opt_onHide;
- /** @type {remoting.MenuButton} */
- var that = this;
-
/**
- * @type {function(Event):void}
+ * @type {HTMLElement}
* @private
*/
- var closeHandler = function(event) {
+ this.clickTrap_ = /** @type {HTMLElement} */ (document.createElement('div'));
+ this.clickTrap_.classList.add('menu-button-click-trap');
Wez 2014/09/23 16:36:49 I think the clickTrap needs some documentation, e.
Jamie 2014/09/23 21:06:34 Done.
+
+ /** @type {remoting.MenuButton} */
+ var that = this;
+
+ var closeHandler = function() {
that.button_.classList.remove(remoting.MenuButton.BUTTON_ACTIVE_CLASS_);
- document.body.removeEventListener('click', closeHandler, false);
+ container.removeChild(that.clickTrap_);
if (that.onHide_) {
that.onHide_();
}
};
- /**
- * @type {function(Event):void}
- * @private
- */
- var onClick = function(event) {
+ var onClick = function() {
if (that.onShow_) {
that.onShow_();
}
that.button_.classList.add(remoting.MenuButton.BUTTON_ACTIVE_CLASS_);
- document.body.addEventListener('click', closeHandler, false);
- event.stopPropagation();
+ container.appendChild(that.clickTrap_);
};
this.button_.addEventListener('click', onClick, false);
+ this.clickTrap_.addEventListener('click', closeHandler, false);
+ this.menu_.addEventListener('click', closeHandler, false);
};
/**

Powered by Google App Engine
This is Rietveld 408576698