mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
refactor(client) loadModule
This commit is contained in:
parent
5329af7366
commit
933f90e271
1 changed files with 28 additions and 27 deletions
|
|
@ -82,50 +82,51 @@ var Util, DOM, CloudFunc;
|
|||
* function load modules
|
||||
* @pParams = {name, path, func, dobefore, arg}
|
||||
*/
|
||||
function loadModule(pParams) {
|
||||
var lName, lPath, lFunc, lDoBefore, lSlash, lAfterSlash,
|
||||
function loadModule(params) {
|
||||
var name, path, func, doBefore, slash, afterSlash,
|
||||
isContain;
|
||||
|
||||
if (pParams) {
|
||||
lName = pParams.name,
|
||||
lPath = pParams.path,
|
||||
lFunc = pParams.func,
|
||||
lDoBefore = pParams.dobefore;
|
||||
if (params) {
|
||||
name = params.name,
|
||||
path = params.path,
|
||||
func = params.func,
|
||||
doBefore = params.dobefore;
|
||||
|
||||
if (Util.isString(pParams))
|
||||
lPath = pParams;
|
||||
if (Util.isString(params))
|
||||
path = params;
|
||||
|
||||
if (lPath && !lName) {
|
||||
lName = Util.getStrBigFirst(lPath);
|
||||
lName = Util.removeStr(lName, '.js');
|
||||
if (path && !name) {
|
||||
name = Util.getStrBigFirst(path);
|
||||
name = Util.removeStr(name, '.js');
|
||||
|
||||
lSlash = lName.indexOf('/');
|
||||
if (lSlash > 0) {
|
||||
lAfterSlash = lName.substr(lSlash);
|
||||
lName = Util.removeStr(lName, lAfterSlash);
|
||||
slash = name.indexOf('/');
|
||||
if (slash > 0) {
|
||||
afterSlash = name.substr(slash);
|
||||
name = Util.removeStr(name, afterSlash);
|
||||
}
|
||||
}
|
||||
|
||||
isContain = Util.isContainStr(lPath, '.js');
|
||||
if (!isContain)
|
||||
lPath += '.js';
|
||||
isContain = Util.isContainStr(path, '.js');
|
||||
|
||||
if (!CloudCmd[lName]) {
|
||||
CloudCmd[lName] = function(pArg) {
|
||||
var path = CloudCmd.LIBDIRCLIENT + lPath;
|
||||
if (!isContain)
|
||||
path += '.js';
|
||||
|
||||
if (!CloudCmd[name]) {
|
||||
CloudCmd[name] = function(arg) {
|
||||
path = CloudCmd.LIBDIRCLIENT + path;
|
||||
|
||||
Util.exec(lDoBefore);
|
||||
Util.exec(doBefore);
|
||||
|
||||
return DOM.jsload(path, lFunc ||
|
||||
return DOM.jsload(path, func ||
|
||||
function() {
|
||||
var Proto = CloudCmd[lName];
|
||||
var Proto = CloudCmd[name];
|
||||
|
||||
if (Util.isFunction(Proto))
|
||||
CloudCmd[lName] = new Proto(pArg);
|
||||
CloudCmd[name] = new Proto(arg);
|
||||
});
|
||||
};
|
||||
|
||||
CloudCmd[lName].show = CloudCmd[lName];
|
||||
CloudCmd[name].show = CloudCmd[name];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue