Skip to content

Instantly share code, notes, and snippets.

@miketaylr
Created January 13, 2014 23:53
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 miketaylr/8410334 to your computer and use it in GitHub Desktop.
Save miketaylr/8410334 to your computer and use it in GitHub Desktop.
T.load = function () {
var e = r.apply(arguments);
var t = e.pop();
var n = e.length;
var i = 0;
var o = function () {
console.log("callback called");
t.apply(this, arguments)
};
e.forEach(function (e) {
if (A[e]) {
if (--n === 0 && t) o("load");
return
}
var r = null;
var s = e.indexOf(".js") >= 0;
var u = e.indexOf(".css") >= 0;
if (s) {
r = tag("script", {
type: "text/javascript",
src: e,
async: "async"
});
["load", "error"].forEach(function (i) {
r.on(i, function () {
r.off("load").off("error").remove();
if (i === "load") {
A[e] = 1;
D.info("loaded script", e)
}
if (--n === 0 && t) o(i)
})
})
} else if (u) {
r = T.tag("link", {
rel: "stylesheet",
type: "text/css",
href: e
});
i = 0;
r.on("load", function(){
o();
});
}
T("head").append(r)
})
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment