Created
January 29, 2013 19:36
-
-
Save kangax/4666999 to your computer and use it in GitHub Desktop.
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
/** | |
* Usage: | |
* | |
* scout() | |
* .when(typeof JSON === 'undefined') | |
* .load('/assets/json2.js') | |
* | |
* .when(typeof G_vmlCanvasManager !== 'undefined') | |
* .load('/assets/fabric/cufon.js') | |
* | |
* .afterAll(function() { | |
* initEditor(); | |
* }); | |
*/ | |
function scout() { | |
var testsToLoad = 0, tests = [ ]; | |
var lastExpression; | |
var afterAllCallback; | |
function checkCompletion() { | |
if (testsToLoad === 0) { | |
afterAllCallback(); | |
} | |
} | |
var self = { | |
when: function(val) { | |
lastExpression = val; | |
return self; | |
}, | |
load: function(str) { | |
if (lastExpression) { | |
testsToLoad++; | |
tests.push(str); | |
} | |
return self; | |
}, | |
afterAll: function(callback) { | |
afterAllCallback = callback; | |
checkCompletion(); | |
for (var i = 0; i < tests.length; i++) { | |
jQuery.getScript(tests[i], function() { | |
testsToLoad--; | |
checkCompletion(); | |
}); | |
} | |
return self; | |
} | |
} | |
return self; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment