Skip to content

Instantly share code, notes, and snippets.

@buzzedword
Created October 26, 2011 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buzzedword/1317253 to your computer and use it in GitHub Desktop.
Save buzzedword/1317253 to your computer and use it in GitHub Desktop.
Wraps getScript to inline all code, no matter where it came from.
jQuery.extend({
getScript: function(url, callback) {
var head = document.getElementsByTagName("head")[0],
script = document.createElement("script");
script.src = url;
// Handle Script loading
{
var f = false;
// Attach handlers for all browsers
script.onload = script.onreadystatechange = function(){
if ( !f && (!this.readyState ||
this.readyState == "loaded" || this.readyState == "complete") ) {
f = true;
if (callback)
callback();
// Handle memory leak in IE
script.onload = script.onreadystatechange = null;
}
};
}
head.appendChild(script);
return undefined;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment