title: On Esc, toggle bootstrap dialog
body: <p>Generally, on <code>Esc</code> any dialog disappears. But we want the functionality to launch the bootstrap dialog on <code>Esc</code> and close it on next <code>Esc</code> .
  So this is my code:</p>
  
  <pre><code>1.$(document).on("keyup", function(e){
  2.  if(e.which == 27 &amp;&amp; id == "#esc"){
  3.      if(!$(dialogid).is(":visible")){
  4.          $(dialogid).modal({'show':true, 'keyboard':false});         
  5.        }else{
  6.          $(dialogid).modal('hide');
  7.      }
  8.  }
  9.});
  </code></pre>
  
  <p>It works fine until I press the <code>Esc</code> key slowly. But sometimes if user keeps pressing <code>Esc</code> key faster multiple times, then the dialog disappears permanently. The control reaches to line no 4. i.e.</p>
  
  <pre><code>$(dialogid).modal({'show':true, 'keyboard':false});         
  </code></pre>
  
  <p>but this line doesn't launch the popup. </p>
  
  <ul>
  <li>What could be the reason?</li>
  <li>How can I fix it. </li>
  </ul>