Using an input proxy was crap, switch to tracking doc clicks.

This commit is contained in:
Thomas Wilburn 2013-11-21 09:40:09 -08:00
parent f7da885f05
commit cc5613698a

View file

@ -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") });