Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function poll(selector, callback, interval = 50, expiration = 20000) {
- // If element found, call callbacks
- if (typeof window.$ === 'function' && $.fn && $(selector).length) {
- callback($(selector));
- // If time has expired, return
- } else if (expiration <= 0) {
- return;
- // Otherwise, try again and decrement expiration
- } else {
- expiration -= interval;
- return setTimeout(pollForElement.bind(null, selector, callback, interval, expiration), interval);
- }
- }
Add Comment
Please, Sign In to add comment