javascript callback after loop
- by RobertPitt
Hey guys,
Iv'e just started a new Wordpress blog and i have started to build the JavaScript base!
the issue im having is funnction a fucntion that loops several variables and includes the required JS libraries, what i need to do is execute the callback when the loop is finished!
Heres my code!
var Utilities = {
Log : function(item)
{
if(console && typeof console.log == 'function')
{
//Chrome
console.log(item);
}
},
LoadLibraries : function(callback)
{
$.each(Wordpress.required,function(i,val){
//Load the JS
$.getScript(Wordpress.theme_root + '/js/plugins/' + val + '/' + val + '.js',function(){ // %/js/plugins/%/%.js
Utilities.Log('library Loaded: ' + val);
});
});
callback();
}
}
And the usage is like so!
Utilities.LoadLibraries(function(){
Utilities.Log('All loaded');
});
Above you see the execution of callback() witch is being executed before the files are in the dom! i need this called at the end of every library inclusion!