Created
October 26, 2011 18:23
-
-
Save buzzedword/1317253 to your computer and use it in GitHub Desktop.
Wraps getScript to inline all code, no matter where it came from.
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
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