Created
April 25, 2014 20:44
-
-
Save creage/11302659 to your computer and use it in GitHub Desktop.
$.wait
This file contains 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
(function ($, window, document, undefined) { | |
$.extend({ | |
/* | |
* wait for timeout until condition returns true | |
*/ | |
wait: function (conditionCallback, timeout) { | |
timeout = timeout || 50; | |
return $.Deferred(function (dfd) { | |
(function toExec() { | |
if (conditionCallback()) { | |
dfd.resolve(); | |
} else setTimeout(toExec, timeout); | |
})(); | |
}); | |
} | |
}); | |
}(jQuery, window, document)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment