Created
December 21, 2011 22:32
-
-
Save jethrolarson/1508018 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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