Guest User

Untitled

a guest
Feb 21st, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. function poll(selector, callback, interval = 50, expiration = 20000) {
  2.  
  3. // If element found, call callbacks
  4. if (typeof window.$ === 'function' && $.fn && $(selector).length) {
  5.  
  6. callback($(selector));
  7.  
  8. // If time has expired, return
  9. } else if (expiration <= 0) {
  10.  
  11. return;
  12.  
  13. // Otherwise, try again and decrement expiration
  14. } else {
  15. expiration -= interval;
  16. return setTimeout(pollForElement.bind(null, selector, callback, interval, expiration), interval);
  17. }
  18.  
  19. }
Add Comment
Please, Sign In to add comment