Using an input proxy was crap, switch to tracking doc clicks.
This commit is contained in:
parent
f7da885f05
commit
cc5613698a
1 changed files with 7 additions and 13 deletions
20
js/menus.js
20
js/menus.js
|
@ -92,10 +92,6 @@ define([
|
|||
var Menu = function() {
|
||||
this.element = document.find(".toolbar");
|
||||
this.active = false;
|
||||
//input serves to track focus
|
||||
this.input = document.createElement("input");
|
||||
this.input.style.width = this.input.style.height = "0px";
|
||||
document.body.append(this.input);
|
||||
this.bindEvents();
|
||||
}
|
||||
Menu.prototype = {
|
||||
|
@ -108,8 +104,14 @@ define([
|
|||
bindEvents: function() {
|
||||
var self = this;
|
||||
var menubar = this.element;
|
||||
var clickElsewhere = function(e) {
|
||||
if (e.target.matches(".toolbar *")) return;
|
||||
self.deactivate();
|
||||
self.active = false;
|
||||
document.body.off("click", clickElsewhere);
|
||||
};
|
||||
menubar.addEventListener("click", function(e) {
|
||||
self.input.focus();
|
||||
document.body.on("click", clickElsewhere);
|
||||
var el = e.target;
|
||||
if (el.hasClass("top")) {
|
||||
el.toggle("active");
|
||||
|
@ -132,14 +134,6 @@ define([
|
|||
el.addClass("active");
|
||||
}
|
||||
});
|
||||
this.input.on("blur", function(e) {
|
||||
if (e.relatedTarget == null) return;
|
||||
//handle leaving the menu for something else
|
||||
setTimeout(function() {
|
||||
self.active = false;
|
||||
self.deactivate();
|
||||
});
|
||||
});
|
||||
},
|
||||
deactivate: function() {
|
||||
this.element.findAll(".active").forEach(function(node) { node.removeClass("active") });
|
||||
|
|
Loading…
Reference in a new issue