Overview
This 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:
selector
- 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
$(document).ensure(selector).done()
. isValid
(default$(this).exists()
)- 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.
delay
(default500
milliseconds)- Miliseconds between each iteration.
tries
(default0
)- Maximum number of times to try,
0
for unlimited.
No comments:
Post a Comment