define(function(require) {

  var $ = require("jquery");
  var KeyHandler = require("fc/bramble-keyhandler");
  var Underlay = require("fc/bramble-underlay");

  function PopupMenu(button, menu) {
    var self = this;
    self._button$ = $(button);
    self._menu$ = $(menu);

    // Toggle the menu on/off when the button is clicked.
    self._button$.on("click", function() {
      if(!self.showing) {
        self.show();
      } else {
        self.close();
      }
    });
  }
  PopupMenu.create = function(button, menu) {
    return new PopupMenu(button, menu);
  };
  PopupMenu.prototype.show = function() {
    // Determine where to horizontally place menu based on button's icon location

    var menuWidth = this._menu$.width();
    var leftOffset = this._button$.offset().left - menuWidth/2 + 11;
    this._menu$.css("left", leftOffset).show();

    this._underlay = new Underlay(this._menu$, this.close.bind(this));
    this._escKeyHandler = new KeyHandler.ESC(this.close.bind(this));
    // Close on resize
    $(window).on("resize", this.close.bind(this));

    this.showing = true;
  };
  PopupMenu.prototype.close = function() {
    this._menu$.hide();

    this._underlay.remove();
    this._underlay = null;

    this._escKeyHandler.stop();
    this._escKeyHandler = null;

    $(window).off("resize", this.close.bind(this));

    delete this.showing;
  };

  return PopupMenu;
});

@@ -266,24 +266,424 @@
 = $(menu);%0A%0A
+    self.close = function() %7B%0A      if(!self.showing) %7B%0A        return;%0A      %7D%0A%0A      $(window).off(%22resize%22, self.close);%0A%0A      self._menu$.hide();%0A%0A      if(self._underlay) %7B%0A        self._underlay.remove();%0A        self._underlay = null;%0A      %7D%0A%0A      if(self._escKeyHandler) %7B%0A        self._escKeyHandler.stop();%0A        self._escKeyHandler = null;%0A      %7D%0A%0A      delete self.showing;%0A    %7D;%0A%0A
     // Toggl
@@ -1004,24 +1004,46 @@
 unction() %7B%0A
+    var self = this;%0A%0A
     // Deter
@@ -1112,17 +1112,16 @@
 ocation%0A
-%0A
     var 
@@ -1132,20 +1132,20 @@
 Width = 
-this
+self
 ._menu$.
@@ -1174,20 +1174,20 @@
 ffset = 
-this
+self
 ._button
@@ -1222,28 +1222,28 @@
 2 + 11;%0A    
-this
+self
 ._menu$.css(
@@ -1267,36 +1267,36 @@
 t).show();%0A%0A    
-this
+self
 ._underlay = new
@@ -1305,20 +1305,20 @@
 nderlay(
-this
+self
 ._menu$,
@@ -1322,40 +1322,29 @@
 u$, 
-this
+self
 .close
-.bind(this)
 );%0A    
-this
+self
 ._es
@@ -1376,37 +1376,26 @@
 ler.ESC(
-this
+self
 .close
-.bind(this)
 );%0A    /
@@ -1443,329 +1443,45 @@
 e%22, 
-this
+self
 .close
-.bind(this));%0A%0A    this.showing = true;%0A  %7D;%0A  PopupMenu.prototype.close = function() %7B%0A    this._menu$.hide();%0A%0A    this._underlay.remove();%0A    this._underlay = null;%0A%0A    this._escKeyHandler.stop();%0A    this._escKeyHandler = null;%0A%0A    $(window).off(%22resize%22, this.close.bind(this));%0A%0A    delete this.showing
+);%0A%0A    self.showing = true
 ;%0A  

Fix #932 - stop popup menu from throwing on resize, missing click events