Created
June 12, 2013 22:33
-
-
Save makbeta/5769721 to your computer and use it in GitHub Desktop.
JS: Add/execute Scripts after jQuery is asynchronosly loaded
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
function addScriptsWhenJQueryIsLoaded(myScripts) { | |
var numScripts = myScripts.length; | |
if (window.jQuery){ | |
//possibly some other JQuery checks to make sure that everything is loaded here | |
console.log('Debug: jQuery loaded, loading scripts, number of script is '+numScripts); | |
window.$ = jQuery.noConflict(); | |
var $anchor = jQuery('#overlay'); | |
if(numScripts > 0) { | |
for(var i=0; i < numScripts; i++) { | |
var $newScript = jQuery('<script>').attr('type', 'text/javascript').attr('src', myCloScripts[i]); | |
console.log($newScript); | |
$anchor.after($newScript); | |
} | |
} | |
} else { | |
setTimeout(function() { addScriptsWhenJQueryIsLoaded(myScripts); }, 500); | |
} | |
} | |
var myScripts = new Array(); | |
myScripts.push("/js/scripts.js"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment