Created
November 6, 2009 02:39
-
-
Save hotchpotch/227642 to your computer and use it in GitHub Desktop.
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
__jsloader__ = function(scripts, callback, errorback) { | |
var now = (new Date()) - 0; | |
if (typeof errorback != 'function') | |
errorback = function(url) { alert('jsloader load error: ' + url) }; | |
var load = function(url) { | |
var script = document.createElement('script'); | |
script.type = 'text/javascript'; | |
script.charset = 'utf-8'; | |
var current_callback; | |
if (scripts.length) { | |
var u = scripts.shift(); | |
current_callback = function() { load(u) } | |
} else { | |
current_callback = callback; | |
} | |
if (window.ActiveXObject) { // IE | |
script.onreadystatechange = function() { | |
if (script.readyState == 'complete' || script.readyState == 'loaded') | |
current_callback(); | |
} | |
} else { | |
script.onload = current_callback; | |
script.onerror = function() { errorback(url) }; | |
} | |
script.src = url + '?' + now; | |
document.body.appendChild(script); | |
} | |
load(scripts.shift()); | |
} | |
//window.onload = function() { | |
// __jsloader__(['a.js', 'b.js'], function() { alert('loaded') }); | |
//} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment