Created
January 13, 2014 23:53
-
-
Save miketaylr/8410334 to your computer and use it in GitHub Desktop.
rewritten T.load from https://s.amebame.com/#top?frm_id=c.am-brow_l.top-_r.am-www
This file contains hidden or 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
| 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