Created
May 22, 2011 14:36
-
-
Save marr/985531 to your computer and use it in GitHub Desktop.
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 filename = "https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"; | |
test("Lazy-load jQuery", function() | |
{ | |
stop(3000); | |
loadScript(filename, function() { | |
start(); | |
ok(/loaded|complete/.test(document.readyState), "document is complete"); | |
ok(typeof $ == "function", "$ is a function"); | |
ok(typeof jQuery == "function", "jQuery is a function"); | |
}); | |
}); | |
function loadScript(filename, callback) | |
{ | |
var script = document.createElement('script') | |
script.setAttribute("type","text/javascript") | |
script.setAttribute("src", filename) | |
if (typeof script!="undefined") | |
document.getElementsByTagName("head")[0].appendChild(script); | |
var interval = setInterval(function() | |
{ | |
if (/loaded|complete/.test(document.readyState)) | |
{ | |
clearInterval(interval); | |
callback(); | |
} | |
}, 10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment