Created
December 21, 2012 22:17
-
-
Save anonymous/4356236 to your computer and use it in GitHub Desktop.
Revisions
-
There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ // how jQuery getScript should work! function getScript (path, callback) { if (!getScript.loaded) { getScript.loaded = {}; $('script').each(function () { var result = $.Deferred(); getScript.loaded[$(this).attr('src')] = result.promise(); result.resolve(); }); } if (!getScript.loaded[path]) { var result = $.Deferred(); var script = document.createElement("script"); script.async = "async"; script.type = "text/javascript"; script.src = path; script.onload = script.onreadystatechange = function(_, isAbort) { if (!script.readyState || /loaded|complete/.test(script.readyState)) { if (!isAbort) { result.reject(); } else { result.resolve(); } } }; script.onerror = function () { result.reject(); }; $("head")[0].appendChild(script); getScript.loaded[path] = result.promise(); } if (callback) { getScript.loaded[path].done(callback); } return getScript.loaded[path]; }