Last active
August 29, 2015 13:56
-
-
Save arigesher/8930705 to your computer and use it in GitHub Desktop.
A dirty-but-effective method for getting inline script blocks to wait for a load of the JQuery library so they can use the superior API it offers. See http://ari.gesher.net/photos-the-gesher-world-tour/ for working example.
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
var waitForJquery = function(jqueryCallback, interval) { | |
if(typeof $ === 'function') { | |
jqueryCallback(); | |
} else { | |
setTimeout(function() { | |
if(typeof $ === 'function'){ | |
jqueryCallback(); | |
} else { | |
waitForJquery(jqueryCallback, interval); | |
} | |
}, interval); | |
} | |
} | |
waitForJquery(function() { | |
$('#dostuff'); | |
}, 50); // poll for jquery every 50ms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment