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

Unified Diff: remoting/webapp/menu_button.js

Issue 401623004: Add unit-tests for MenuButton and simplify implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 5 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
« no previous file with comments | « remoting/webapp/menu_button.css ('k') | remoting/webapp/unittests/menu_button_unittest.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/webapp/menu_button.js
diff --git a/remoting/webapp/menu_button.js b/remoting/webapp/menu_button.js
index 225e0e79c409bca120bda26aab2607cd763f0af8..b38ad6b7acd022789e6ad2fb18bea700c7bf6388 100644
--- a/remoting/webapp/menu_button.js
+++ b/remoting/webapp/menu_button.js
@@ -28,6 +28,12 @@ remoting.MenuButton = function(container, opt_onShow) {
(container.querySelector('button,.menu-button-activator'));
/**
+ * @type {HTMLElement}
+ * @private
+ */
+ this.menu_ = /** @type {HTMLElement} */ (container.querySelector('ul'));
+
+ /**
* @type {undefined|function():void}
* @private
*/
@@ -36,46 +42,43 @@ remoting.MenuButton = function(container, opt_onShow) {
/** @type {remoting.MenuButton} */
var that = this;
- // Create event handlers to show and hide the menu, attached to the button
- // and the document <html> tag, respectively. These handlers are added and
- // removed depending on the state of the menu. To prevent both triggering
- // for one click, they are added by a timer.
/**
* @type {function(Event):void}
* @private
*/
- this.onClick_ = function(event) {
- if (that.onShow_) {
- that.onShow_();
- }
- that.button_.classList.add(remoting.MenuButton.BUTTON_ACTIVE_CLASS_);
- that.button_.removeEventListener('click', that.onClick_, false);
- window.setTimeout(
- function() {
- // Attach the click handler to the <html> node so that it includes
- // the document area outside the plugin, which is not covered by
- // the <body> node.
- var htmlNode = document.body.parentNode;
- htmlNode.addEventListener('click', that.closeHandler_, true);
- },
- 100);
+ var closeHandler = function(event) {
+ that.button_.classList.remove(remoting.MenuButton.BUTTON_ACTIVE_CLASS_);
+ document.body.removeEventListener('click', closeHandler, true);
};
/**
* @type {function(Event):void}
* @private
*/
- this.closeHandler_ = function(event) {
- that.button_.classList.remove(remoting.MenuButton.BUTTON_ACTIVE_CLASS_);
- document.body.removeEventListener('click', that.closeHandler_, true);
- window.setTimeout(
- function() {
- that.button_.addEventListener('click', that.onClick_, false);
- },
- 100);
+ var onClick = function(event) {
+ if (that.onShow_) {
+ that.onShow_();
+ }
+ that.button_.classList.toggle(remoting.MenuButton.BUTTON_ACTIVE_CLASS_);
+ document.body.addEventListener('click', closeHandler, false);
+ event.stopPropagation();
};
- this.button_.addEventListener('click', this.onClick_, false);
+ this.button_.addEventListener('click', onClick, false);
+};
+
+/**
+ * @return {HTMLElement} The button that activates the menu.
+ */
+remoting.MenuButton.prototype.button = function() {
+ return this.button_;
+};
+
+/**
+ * @return {HTMLElement} The menu.
+ */
+remoting.MenuButton.prototype.menu = function() {
+ return this.menu_;
};
/**
« no previous file with comments | « remoting/webapp/menu_button.css ('k') | remoting/webapp/unittests/menu_button_unittest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698