Skip to content

Instantly share code, notes, and snippets.

@jethrolarson
Created December 21, 2011 22:32
Show Gist options
  • Select an option

  • Save jethrolarson/1508018 to your computer and use it in GitHub Desktop.

Select an option

Save jethrolarson/1508018 to your computer and use it in GitHub Desktop.
//You can use jQuery deferreds as well as traditional callbacks
$.fn.wait = function (ms,callback){
var dfd = $.Deferred();
setTimeout(function(){
dfd.resolve();
},ms);
if(callback){
dfd.done(callback);
}
return dfd.promise();
};
$.fn.defer = function (callback){
return $.fn.wait.call(this, 1, callback);
};
/* Examples:
$('.hugeTable').addClass('loading').defer().done(function(){
$(this).sortable().removeClass('loading');
});
$('form').submit(function(){
$('#button').text('Submitting...').wait(5000,function(){
$(this).text('Still submitting...');
});
});
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment