title: jQuery keyup delay event
body: <p>I'm trying to creat special event for jQuery. I want to make controled delay, which will work when user stops fo 0.5s. But I can't use setTimeout.</p>
  
  <pre><code>jQuery.event.special.keyupdelay = {
      add : function(handler, data, namespaces) {
          var delay = data &amp;&amp; data.delay || 100;
  
          return function(event) {                                                
              setTimeout(function() { handler.apply(this, arguments);}, data);
          }
      },
  
      setup: function(data, namespaces) {
          jQuery(this).bind("keyup", jQuery.event.special.keyupdelay.handler);
      },
  
      teardown: function(namespaces) {
          jQuery(this).unbind("keyup", jQuery.event.special.keyupdelay.handler);        
      },
  
      handler: function(event) {              
          event.type = "keyupdelay";
          jQuery.event.handle.apply(this, arguments);
      }
  };
  </code></pre>
  
  <p>To use it like this</p>
  
  <pre><code>$(".money").bind("keyupdelay", {delay: 1000}, function( event ) {
      alert('Delayed!');
  });  
  </code></pre>
  
  <p>setTimeout not working. </p>
  
  <p>I can make it like this</p>
  
  <pre><code>var timer;
  
  $(".quantity input").keyup(function() {
          var self = $(this);
  
          if(timer) {
              clearTimeout(timer);
              timer = null;
          }
          timer = setTimeout( function() {
              var qty = self.val();
              $(".qty").html(qty);
          }, 300);
  });
  </code></pre>
  
  <p>But I want to create special event, which triggers with delay. I have a lot of controls which have to work with delay.</p>