Created
August 30, 2011 16:09
-
-
Save ritch/1181254 to your computer and use it in GitHub Desktop.
Simple jQuery method dependency loader
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
// 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