OverviewThis is a very nice little plugin I wrote for jQuery to handle situations that don't have callbacks. You can do this manually in code by adding a timeout but what if the function takes to long, or what make users with a faster device wait for slower devices by over estimating the timeout.
Please note that most libraries have their own callbacks and jQuery had a
$().done()mechanism that will do this for common functions and libraries. This solution is for those odd ball code bits that don't or that you don't have control over.
It takes a few pieces of information:
- The root jQuery selector you are binding to, it will become the this in the isValid call.
- If your waiting for a new item to be created do
- This is the function that is run each iteration.
- It should be optimized and return a bool result. Ie don't walk the DOM every time, select the proper parent node into a variable or pass as the selector.
- Miliseconds between each iteration.
- Maximum number of times to try,