title: How to open and close modal with same hotkey
body: <p>I'm trying to open and close modal window with same hotkey:</p>
  
  <pre><code>if !$('#new-stuff').length or $('#new-stuff').is(':hidden')
    $(document).keydown( (e) -&gt;
      if e.altKey &amp;&amp; e.which == 65
        e.preventDefault
        modal.open(
          content: '&lt;input type="text" placeholder="New stuff here!" id="new-stuff"&gt;&lt;br /&gt;&lt;input type="submit" value="Do stuff!"&gt;'
        )
    ).keyup( -&gt;
      $('#new-stuff').focus()
    )
  else
    $(document).keyup( (e) -&gt;
      if e.altKey &amp;&amp; e.which == 65
        e.preventDefault()
        modal.close()
    )
  </code></pre>
  
  <p>When I'm pressing <code>alt + A</code> modal is opening and focus is on the input. But when I'm pressing <code>alt + A</code> again it focuses on input again, but not closing.</p>
  
  <pre><code>!$('#new-stuff').length or $('#new-stuff').is(':hidden')
  </code></pre>
  
  <p>Both are <code>false</code>, but <code>$('#new-stuff').focus()</code> is happening. Why?<br>
  And how to close modal with <code>alt + A</code>?</p>
  
  <p><strong>UPDATE</strong><br>
  Here is working code:</p>
  
  <pre><code>$(document).keydown( (e) -&gt;
    if e.altKey &amp;&amp; e.which == 65
      if $('#new-stuff').is(':visible')
        e.preventDefault()
        modal.close()
      else
        e.preventDefault
        modal.open(
          content: '&lt;input type="text" placeholder="New stuff here!" id="new-stuff"&gt;&lt;br /&gt;&lt;input type="submit" value="Do stuff!"&gt;'
        )
  ).keyup( -&gt;
    $('#new-stuff').focus() if $('#new-stuff').is(':visible')
  )
  </code></pre>