Ox.load: allow for passing array of modules

This commit is contained in:
rolux 2012-06-17 15:56:13 +02:00
parent 8d8e087e3d
commit c9474ee04e

View file

@ -96,30 +96,41 @@ Ox.Break = function() {
Ox.BreakError = new SyntaxError('Illegal Ox.Break() statement');
/*@
Ox.load <f> Loads a module
Ox.load <f> Loads one or more modules
A module named "Foo" provides `Ox.Foo/Ox.Foo.js`, in which it defines one
method, `Ox.load.Foo`, that takes two arguments, `options` and `callback`,
and calls `callback` with one argument, `true` for success or `false` if an
error occurred. Generally, the module should define `Ox.Foo` and attach its
own methods there.
(module, callback) -> <u> undefined
(module, callback) -> <u> undefined
(module, options, callback) -> <u> undefined
(modules, callback) -> <u> undefined
(modules, callback) -> <u> undefined
module <s> Module name
modules <o> Multiple modules {name: options, ...}
options <o> Module options
modules <a|o> Multiple modules
Either `[moduleA, {moduleB: options}, ...]`
or `{moduleA: {}, moduleB: {options}, ...}`
callback <f> Callback function
success <b> If true, the module has been loaded successfully
success <b> If true, all modules have been loaded successfully
@*/
Ox.load = function() {
var callback = arguments[arguments.length - 1],
counter = 0,
isObject = Ox.isObject(arguments[0]),
length,
modules = isObject ? arguments[0] : {},
success = 0;
if (!isObject) {
modules[arguments[0]] = Ox.isObject(arguments[1]) ? arguments[1] : {};
counter = 0, length, modules = {}, success = 0,
type = Ox.typeOf(arguments[0]);
if (type == 'string') {
modules = Ox.extend(
{}, arguments[0], Ox.isObject(arguments[1]) ? arguments[1] : {}
);
} else if (type == 'array') {
arguments[0].forEach(function(value) {
if (Ox.isString(value)) {
modules[value] = {};
} else {
Ox.extend(modules, value)
}
});
} else if (type == 'object') {
modules = arguments[0];
}
length = Ox.len(modules);
Ox.forEach(modules, function(options, module) {