Skip to content

Instantly share code, notes, and snippets.

@ritch
Created August 30, 2011 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ritch/1181254 to your computer and use it in GitHub Desktop.
Save ritch/1181254 to your computer and use it in GitHub Desktop.
Simple jQuery method dependency loader
// simple script dependency delegation
// built specifically for backbone + jQuery
// loads scripts[] in parallel
var use = function(scripts, fn) {
var complete = 0,
total = scripts.length,
script;
function done() {
if(++complete === total && fn) fn();
}
return function() {
while((script = scripts.shift())) {
$.ajax({
url: 'js/' + script,
dataType: 'script',
success: done,
cache: true
});
}
};
};
var form: {
init: use(['jquery.validate.js', 'ajaxify.js'], function() {
$('#form').ajaxify();
});
}
// dependencies will be loaded in parallel once this is called
form.init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment