change the semantics of Ox.load to call back once the DOM is ready - which wasn't the case when calling Ox.load(callback) in the built version

This commit is contained in:
rolux 2012-06-22 15:02:38 +02:00
parent 260f826282
commit f15d6cad0f

View file

@ -118,6 +118,11 @@ Ox.load = function() {
var callback = arguments[arguments.length - 1], var callback = arguments[arguments.length - 1],
length, loaded = 0, modules = {}, succeeded = 0, length, loaded = 0, modules = {}, succeeded = 0,
type = Ox.typeOf(arguments[0]); type = Ox.typeOf(arguments[0]);
function done(success) {
Ox.documentReady(function() {
callback(success);
});
}
if (type == 'string') { if (type == 'string') {
modules = Ox.extend( modules = Ox.extend(
{}, arguments[0], Ox.isObject(arguments[1]) ? arguments[1] : {} {}, arguments[0], Ox.isObject(arguments[1]) ? arguments[1] : {}
@ -134,16 +139,22 @@ Ox.load = function() {
modules = arguments[0]; modules = arguments[0];
} }
length = Ox.len(modules); length = Ox.len(modules);
Ox.forEach(modules, function(options, module) { Ox.documentReady(function() {
Ox.getFile( if (!length) {
Ox.PATH + 'Ox.' + module + '/Ox.' + module + '.js', callback(true);
function() { } else {
Ox.load[module](options, function(success) { Ox.forEach(modules, function(options, module) {
succeeded += success; Ox.getFile(
++loaded == length && callback(succeeded == length); Ox.PATH + 'Ox.' + module + '/Ox.' + module + '.js',
}); function() {
} Ox.load[module](options, function(success) {
); succeeded += success;
++loaded == length && callback(succeeded == length);
});
}
);
});
}
}); });
}; };