Created
November 30, 2012 12:32
-
-
Save manix84/4175508 to your computer and use it in GitHub Desktop.
Checking for dependancies and sending a callback when they have loaded. For use when you're expecting a library to load and you don't know when it'll appear.
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
(function () { | |
var utils = window.utils || {}; | |
utils.dependancyCheck = function (dependancies, callback) { | |
dependancies = !(dependancies instanceof Array) ? [dependancies] : dependancies; | |
var checkForDependancies = function () { | |
var i = 0; | |
for (; i < dependancies.length; ++i) { | |
if (dependancies[i] !== undefined) { | |
// Remove current item from array, then step backwards. Yes I know --VAR and VAR-- differences. | |
dependancies.splice(i--, 1); | |
} | |
if (dependancies.length !== 0) { | |
window.setTimeout(checkForDependancies, 50); | |
} else { | |
callback(); | |
} | |
} | |
}; | |
checkForDependancies(); | |
}; | |
window.utils = utils; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment