title: How to fire keydown-event before ui-dialog onClose?
body: <p>I'm using some jQueryUI dialogs like this:</p>
  
  <pre><code>$("#PersonDialog").dialog({
          bgiframe : true,
          autoOpen : false,
          closeOnEscape : true,
          resizable : false,
          height : 150,
          modal : true,
          open: function(){
                 activeWindow="dialog"
          },
          close: function(){
                 activeWindow="person"
          }
          ....
          ....
      })
  </code></pre>
  
  <p>I also have some divs that I want to close when escape is pressed. I also use code from <a href="https://stackoverflow.com/a/2641047/1423171">this answer</a>, but it didn't solve my problem:</p>
  
  <pre><code>$("body").bindFirst("keydown", function(e) {
          console.info(activeWindow)
              if (e.keyCode == 27) {
                  switch(activeWindow){
                      case "dialog":
                           //do something
                      break;
                      case "person":
                          //do something else
                      break;
                      ....
              }
          }
      })
  $.fn.bindFirst = function(name, fn) {
      this.on(name, fn);
      this.each(function() {
          var handlers = $._data(this, 'events')[name.split('.')[0]];
          var handler = handlers.pop();
          handlers.splice(0, 0, handler);
      });
  };
  </code></pre>
  
  <p>My problem is that when the dialog is open I press escape, both (div and dialog) get closed and <code>console.info(activeWindow)</code> return "person". I guess that <code>closeOnEscape</code> is fired first and than the keydown-event. Is there a way to change this?</p>