user706058
user706058

Reputation: 415

jQuery: delay event call in widget

I can't find out how to delay an event handler for a widget. I bind the event like this:

enable: function () {
    this.options.isEnabled = true;
    this.element.bind("keyup", $.proxy(this, "_populateList"));
},

I want to call "_populateList" with a delay. but my attempts with setTimeout are not working.

The "_populateList":

_populateList: function (event) {
    var that = this;
    // do my stuffs
}

Thanks

Upvotes: 0

Views: 379

Answers (1)

Shef
Shef

Reputation: 45599

Try this:

enable: function () {
    this.options.isEnabled = true;
    var that = this;
    this.element.bind("keyup", function(event){
       $(this)
          .delay(1000) // delayed time in milliseconds
          .queue(function(next){
             that._populateList(event);
             next();
          });
    });
},

Upvotes: 1

Related Questions