Created
June 19, 2013 16:59
-
-
Save d48/5815925 to your computer and use it in GitHub Desktop.
js loader
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
BLS.unitTests.loadJS = function(strJS, cb) { | |
var objHead = document.getElementsByTagName('head')[0] | |
, oEmbed = document.createElement('script') | |
; | |
oEmbed.type = 'text/javascript'; | |
oEmbed.src = strJS; | |
oEmbed.async = false; // force to load in order | |
// listener for when file is done loading | |
oEmbed.onload = oEmbed.onreadystatechange = function() { | |
var rs = this.readyState; | |
if ( rs && rs !== 'complete' && rs !== 'loaded' ) return; | |
// debug | |
console.log('finished loading ' + strJS); | |
// oncomplete, fire cb | |
if( cb ) cb(); | |
// avoid memory leak | |
oEmbed.onload = oEmbed.onreadystatechange = null; | |
} | |
objHead.appendChild(oEmbed); // inject into DOM | |
return this; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment