update geo module; make Ox.load accept multiple modules
This commit is contained in:
parent
cbd6a1dea8
commit
3c419d3ee7
4 changed files with 108 additions and 83 deletions
30
source/Ox.js
30
source/Ox.js
|
|
@ -178,22 +178,32 @@ Ox = function(val) {
|
|||
Ox.load <f> Loads a module
|
||||
(module, callback) -> <u> undefined
|
||||
(module, options, callback) -> <u> undefined
|
||||
(modules, callback) -> <u> undefined
|
||||
module <s> Module name
|
||||
modules <o> Multiple modules {name: options}
|
||||
options <o> Module options
|
||||
callback <f> Callback function
|
||||
success <b> If true, the module has been loaded successfully
|
||||
@*/
|
||||
|
||||
Ox.load = function(/*module[[, options], callback]*/) {
|
||||
// fixme: no way to load multiple modules
|
||||
// problem: where do multiple options go?
|
||||
// [{name: "", options: {}}, {name: "", options: {}}] isn't pretty
|
||||
var len = arguments.length,
|
||||
module = arguments[0],
|
||||
options = len == 3 ? arguments[1] : {},
|
||||
callback = arguments[len - 1];
|
||||
Ox.loadFile(Ox.PATH + 'Ox.' + module + '/Ox.' + module + '.js', function() {
|
||||
Ox.load[module](options, callback);
|
||||
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] : {};
|
||||
}
|
||||
length = Ox.len(modules)
|
||||
Ox.forEach(modules, function(options, module) {
|
||||
Ox.loadFile(Ox.PATH + 'Ox.' + module + '/Ox.' + module + '.js', function() {
|
||||
Ox.load[module](options, function(s) {
|
||||
success += s;
|
||||
++counter == length && callback(success == counter);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue