Ox.load: allow for passing array of modules
This commit is contained in:
parent
8d8e087e3d
commit
c9474ee04e
1 changed files with 23 additions and 12 deletions
|
@ -96,7 +96,7 @@ 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
|
||||
|
@ -106,20 +106,31 @@ Ox.load <f> Loads a module
|
|||
(module, options, 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) {
|
||||
|
|
Loading…
Reference in a new issue