Created
November 2, 2011 22:44
-
-
Save markhepburn/1335182 to your computer and use it in GitHub Desktop.
Yet another lazy script-loader, with callbacks managed using jQuery Deferred objects.
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 $LL = (function($) { | |
var deferreds = {}; | |
return function(s, c) { | |
if (s in deferreds) { | |
deferreds[s].done(function(){ | |
c(); | |
}); | |
return; | |
} | |
deferreds[s] = $.Deferred(); | |
var d = deferreds[s].done(function() { | |
c(); | |
}); | |
var f = function () { | |
if (!(this.readyState | |
&& this.readyState !== "complete" | |
&& this.readyState !== "loaded")) { | |
this.onload = this.onreadystatechange = null; | |
d.resolve(); | |
} | |
}, | |
g = document.getElementsByTagName("head")[0], | |
i = function (h) { | |
var a = document.createElement("script"); | |
a.async = true; | |
a.src = h; | |
a.onload = a.onreadystatechange = f; | |
g.appendChild(a); | |
}; | |
i(s); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment