;(function(root) {
var S = root.KISSY;
var Env = S.Env,
Config = S.Config,
config = S.config,
log = S.log;
var mix = S.mix,
map = S.map,
each = S.each,
isObject = S.isObject,
isArray = S.isArray,
isString = S.isString,
isFunction = S.isFunction,
startsWith = S.startsWith,
endsWith = S.endsWith,
getScript = S.getScript;
var doc = root.document,
ua = root.navigator.userAgent,
loc = root.location,
href = loc.href,
protocol = loc.protocol;
var substring = function(str, start, end) {
return str.substring(start, end);
}, indexOf = function(str, value, index) {
return str.indexOf(value, index);
}, slice = function(str, start, end) {
return str.slice(start, end);
}, charAt = function(str, index) {
return str.charAt(index);
}, split = function(str, flag) {
return str.split(flag);
}, replace = function(str, reg, val) {
return str.replace(reg, val);
}, toLowerCase = function(str) {
return str.toLowerCase();
};
var now = Date.now,
keys = Object.keys,
reduce = function(arr, fn, initialVal) {
return arr.reduce(fn, initialVal);
},
filter = function(arr, fn) {
return arr.filter(fn);
},
indexOf = function(arr, val) {
return arr.indexOf(val);
},
setImmediate = function(fn) {
setTimeout(fn, 0);
};
var noop = function() {},
TRUE = !0,
FALSE = !1;
function normalizeArray(parts, allowAboveRoot) {
var up = 0,
i = parts.length - 1,
newParts = [],
last;
for (; i >= 0; i--) {
last = parts[i];
if (last !== '.') {
if (last === '..') {
up++;
} else if (up) {
up--;
} else {
newParts[newParts.length] = last;
}
}
}
if (allowAboveRoot) {
for (; up--; up) {
newParts[newParts.length] = '..';
}
}
newParts = newParts.reverse();
return newParts;
}
var RE_DIRNAME = /[^?#]*\//;
function pathGetDirName(path) {
var mat = path.match(RE_DIRNAME);
return mat ? mat[0] : '.';
}
function pathRemoveExt(path) {
return path.replace(/\.[^\/]+$/, '');
}
var RE_DOT = /\/\.\//g,
RE_DOUBLE_DOT = /\/[^/]+\/\.\.\//,
RE_DOUBLE_SLASH = /([^:/])\/\//g;
function pathParseRelative(path) {
path = path.replace(RE_DOT, "/");
while (path.match(RE_DOUBLE_DOT)) {
path = path.replace(RE_DOUBLE_DOT, "/");
}
path = path.replace(RE_DOUBLE_SLASH, "$1/");
return path;
}
function pathResolveRelative(from, to) {
var resolvedPath = '',
resolvedPathStr,
i,
args = (arguments),
path,
absolute = 0;
for (i = args.length - 1; i >= 0 && !absolute; i--) {
path = args[i];
if (!isString(path) || !path) {
continue;
}
resolvedPath = path + '/' + resolvedPath;
absolute = charAt(path, 0) === '/';
}
resolvedPathStr = normalizeArray(filter(split(resolvedPath, '/'), function (p) {
return !!p;
}), !absolute).join('/');
return ((absolute ? '/' : '') + resolvedPathStr) || '.';
}
function pathGetRelative(from, to) {
from = pathParseRelative(from);
to = pathParseRelative(to);
var fromParts = filter(split(from, '/'), function (p) {
return !!p;
}),
path = [],
sameIndex,
sameIndex2,
toParts = filter(split(to, '/'), function (p) {
return !!p;
}), commonLength = Math.min(fromParts.length, toParts.length);
for (sameIndex = 0; sameIndex < commonLength; sameIndex++) {
if (fromParts[sameIndex] !== toParts[sameIndex]) {
break;
}
}
sameIndex2 = sameIndex;
while (sameIndex < fromParts.length) {
path.push('..');
sameIndex++;
}
path = path.concat(slice(toParts, sameIndex2));
path = path.join('/');
return path;
}
function pathNormalizeName(id) {
var last = id.length - 1,
lastC = charAt(id, last);
if (lastC === "#") {
return id.substring(0, last);
}
return (endsWith(id, '.js') ||
endsWith(id, '.css') ||
indexOf(id, '?') > 0 ||
lastC === '/' ) ? id :
id + '.js';
}
var RE_ABSOLUTE = /^\/\/.|:\//,
RE_ROOT_DIR = /^.*?\/\/.*?\//;
function pathNormalizeBase(base) {
if (!base) { return loaderDir; }
base = base.replace(/\\/g, '/');
if (!endsWith(base, '/')) {
base += '/';
}
return pathAddBase(base);
}
function pathAddBase(id, base) {
var result, baseDir, mat;
firstC = charAt(id, 0);
baseDir = base ? pathGetDirName(base) : workDir;
if (RE_ABSOLUTE.test(id)) {
result = id;
}
else if (firstC === ".") {
result = pathParseRelative(baseDir + id);
}
else if (firstC === "/") {
mat = baseDir.match(RE_ROOT_DIR);
result = mat ? mat[0] + substring(id, 1) : id;
}
else {
result = baseDir + id;
}
if (startsWith(result, '//')) {
result = protocol + result;
}
return result;
}
function pathAddQuery(path, key, value) {
return path + ( indexOf(path, '?') > -1 ? '&' : '?' ) + key + '=' + value;
}
var workDir = pathGetDirName(doc.URL);
var loaderDir = (function() {
var src = getMiniSrc();
return src ? pathGetDirName(src) : workDir;
}());
var Loader = S.Loader = {};
var ERROR = -1,
INIT = 0,
LOADING = 1,
LOADED = 2,
READY_TO_ATTACH = 3,
ATTACHING = 4,
ATTACHED = 5;
Loader.Status = {
ERROR: ERROR,
INIT: INIT,
LOADING: LOADING,
LOADED: LOADED,
READY_TO_ATTACH: READY_TO_ATTACH,
ATTACHING: ATTACHING,
ATTACHED: ATTACHED
};
function addIndexAndRemoveJsExt(s) {
if (isString(s)) {
return addIndexAndRemoveJsExtFromName(s);
} else {
var ret = [],
i = 0,
l = s.length;
for (; i < l; i++) {
ret[i] = addIndexAndRemoveJsExtFromName(s[i]);
}
return ret;
}
}
function addIndexAndRemoveJsExtFromName(name) {
if (charAt(name, name.length - 1) === '/') {
name += 'index';
}
if (endsWith(name, '.js')) {
name = slice(name, 0, -3);
}
return name;
}
function pluginAlias(runtime, name) {
var index = indexOf(name, '!');
if (index !== -1) {
var pluginName = substring(name, 0, index);
name = substring(name, index + 1);
S.use(pluginName, {
sync: true,
success: function (S, Plugin) {
if (Plugin.alias) {
name = Plugin.alias(runtime, name, pluginName);
}
}
});
}
return name;
}
function normalDepModuleName(moduleName, depName) {
var i = 0, l;
if (!depName) {
return depName;
}
if (isString(depName)) {
if (startsWith(depName, '../') || startsWith(depName, './')) {
return pathResolveRelative(pathGetDirName(moduleName), depName);
}
return pathParseRelative(depName);
}
for (l = depName.length; i < l; i++) {
depName[i] = normalDepModuleName(moduleName, depName[i]);
}
return depName;
}
function createModulesInfo(runtime, modNames) {
each(modNames, function (m) {
createModuleInfo(runtime, m);
});
}
function createModuleInfo(runtime, modName, cfg) {
modName = addIndexAndRemoveJsExtFromName(modName);
var mods = runtime.Env.mods,
module = mods[modName];
if (module) {
return module;
}
mods[modName] = module = new Module(mix({
name: modName,
runtime: runtime
}, cfg));
return module;
}
function getModules(runtime, modNames) {
var mods = [runtime], module,
unaliasArr,
allOk,
m,
runtimeMods = runtime.Env.mods;
each(modNames, function (modName) {
module = runtimeMods[modName];
if (!module || module.getType() !== 'css') {
unaliasArr = unalias(runtime, modName);
allOk = reduce(unaliasArr, function (a, n) {
m = runtimeMods[n];
return a && m && m.status >= ATTACHING;
}, true);
if (allOk) {
mods.push(runtimeMods[unaliasArr[0]].exports);
} else {
mods.push(null);
}
} else {
mods.push(undefined);
}
});
return mods;
}
function attachModsRecursively(modNames, runtime) {
var i,
l = modNames.length;
for (i = 0; i < l; i++) {
attachModRecursively(modNames[i], runtime);
}
}
function checkModsLoadRecursively(modNames, runtime, stack, errorList, cache) {
stack = stack || [];
cache = cache || {};
var i,
s = 1,
l = modNames.length,
stackDepth = stack.length;
for (i = 0; i < l; i++) {
s = s && checkModLoadRecursively(modNames[i], runtime, stack, errorList, cache);
stack.length = stackDepth;
}
return !!s;
}
function checkModLoadRecursively(modName, runtime, stack, errorList, cache) {
var mods = runtime.Env.mods,
status,
m = mods[modName];
if (modName in cache) {
return cache[modName];
}
if (!m) {
cache[modName] = FALSE;
return FALSE;
}
status = m.status;
if (status === ERROR) {
errorList.push(m);
cache[modName] = FALSE;
return FALSE;
}
if (status >= READY_TO_ATTACH) {
cache[modName] = TRUE;
return TRUE;
}
if (status !== LOADED) {
cache[modName] = FALSE;
return FALSE;
}
if (indexOf(stack, modName) > -1) {
cache[modName] = TRUE;
return TRUE;
}
stack.push(modName);
if (checkModsLoadRecursively(m.getNormalizedRequires(),
runtime, stack, errorList, cache)) {
m.status = READY_TO_ATTACH;
cache[modName] = TRUE;
return TRUE;
}
cache[modName] = FALSE;
return FALSE;
}
function attachModRecursively(modName, runtime) {
var mods = runtime.Env.mods,
status,
m = mods[modName];
status = m.status;
if (status >= ATTACHING) {
return;
}
m.status = ATTACHING;
if (m.cjs) {
attachMod(runtime, m);
} else {
attachModsRecursively(m.getNormalizedRequires(), runtime);
attachMod(runtime, m);
}
}
function attachMod(runtime, module) {
var factory = module.factory,
exports;
if (isFunction(factory)) {
var require;
if (module.requires && module.requires.length) {
require = function() {
return module.require.apply(module, arguments);
};
}
exports = factory.apply(module,
(module.cjs ? [runtime, require, module.exports, module] : getModules(runtime, module.getRequiresWithAlias())));
if (exports !== undefined) {
module.exports = exports;
}
} else {
module.exports = factory;
}
module.status = ATTACHED;
}
function getModNamesAsArray(modNames) {
if (isString(modNames)) {
modNames = split(replace(modNames, /\s+/g, ''), ',');
}
return modNames;
}
function normalizeModNames(runtime, modNames, refModName) {
return unalias(runtime,
normalizeModNamesWithAlias(runtime, modNames, refModName));
}
function unalias(runtime, names) {
var ret = [].concat(names),
i,
m,
alias,
ok = 0,
j;
while (!ok) {
ok = 1;
for (i = ret.length - 1; i >= 0; i--) {
if ((m = createModuleInfo(runtime, ret[i])) && ((alias = m.getAlias()) !== undefined)) {
ok = 0;
if (typeof alias === 'string') {
alias = [alias];
}
for (j = alias.length - 1; j >= 0; j--) {
if (!alias[j]) {
alias.splice(j, 1);
}
}
ret.splice.apply(ret, [i, 1].concat(addIndexAndRemoveJsExt(alias)));
}
}
}
return ret;
}
function normalizeModNamesWithAlias(runtime, modNames, refModName) {
var ret = [], i, l;
if (modNames) {
for (i = 0, l = modNames.length; i < l; i++) {
if (modNames[i]) {
ret.push(pluginAlias(runtime, addIndexAndRemoveJsExt(modNames[i])));
}
}
}
if (refModName) {
ret = normalDepModuleName(refModName, ret);
}
return ret;
}
function registerModule(runtime, name, factory, config) {
name = addIndexAndRemoveJsExtFromName(name);
var mods = runtime.Env.mods,
module = mods[name];
if (module && module.factory !== undefined) {
return;
}
createModuleInfo(runtime, name);
module = mods[name];
mix(module, {
name : name,
status : LOADED,
factory : factory
});
mix(module, config);
}
function getHash(str) {
var hash = 5381,
i;
for (i = str.length; --i > -1;) {
hash = ((hash << 5) + hash) + str.charCodeAt(i);
}
return hash + '';
}
function getRequiresFromFn(fn) {
var requires = [];
fn.toString()
.replace(commentRegExp, '')
.replace(requireRegExp, function (match, dep) {
requires.push(getRequireVal(dep));
});
return requires;
}
var commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,
requireRegExp = /[^.'"]\s*require\s*\(([^)]+)\)/g;
function getRequireVal(str) {
var m = str.match(/^\s*["']([^'"\s]+)["']\s*$/);
return m ? m[1] : '';
}
function forwardSystemPackage(self, property) {
return property in self ?
self[property] :
self.runtime.Config[property];
}
function Package(cfg) {
mix(this, cfg);
}
Package.prototype = {
constructor: Package,
reset: function (cfg) {
mix(this, cfg);
},
getTag: function () {
return forwardSystemPackage(this, 'tag');
},
getName: function () {
return this.name;
},
getPath: function () {
return this.path || (this.path = this.getUri());
},
getUri: function () {
return this.uri;
},
getCharset: function () {
return forwardSystemPackage(this, 'charset');
},
getGroup: function () {
return forwardSystemPackage(this, 'group');
}
};
Loader.Package = Package;
var systemPackage = new Package({
name: '',
runtime: S
});
systemPackage.getUri = function () {
return this.runtime.Config.baseUri;
};
function getPackage(self, modName) {
var packages = self.Config.packages || {},
modNameSlash = modName + '/',
pName = '',
p;
for (p in packages) {
if (startsWith(modNameSlash, p + '/') && p.length > pName.length) {
pName = p;
}
}
return packages[pName] || systemPackage;
}
function Module(cfg) {
this.exports = {};
this.status = INIT;
this.name = undefined;
this.factory = undefined;
this.cjs = 1;
mix(this, cfg);
this.waitedCallbacks = [];
}
Module.prototype = {
kissy: 1,
constructor: Module,
use: function (relativeName, fn) {
relativeName = getModNamesAsArray(relativeName);
return S.use(normalDepModuleName(this.name, relativeName), fn);
},
resolve: function (relativePath) {
return pathAddBase(relativePath, this.getUri());
},
resolveByName: function (relativeName) {
return normalDepModuleName(this.name, relativeName);
},
require: function (moduleName) {
return S.require(moduleName, this.name);
},
wait: function (callback) {
this.waitedCallbacks.push(callback);
},
notifyAll: function () {
var callback;
var len = this.waitedCallbacks.length,
i = 0;
for (; i < len; i++) {
callback = this.waitedCallbacks[i];
try {
callback(this);
} catch (e) {
setTimeout(function () {
throw e;
}, 0);
}
}
this.waitedCallbacks = [];
},
getType: function () {
var v = this.type;
if (!v) {
if (endsWith(toLowerCase(this.name), '.css')) {
v = 'css';
} else {
v = 'js';
}
this.type = v;
}
return v;
},
getAlias: function () {
var name = this.name,
aliasFn,
packageInfo,
alias = this.alias;
if (!('alias' in this)) {
packageInfo = this.getPackage();
if (packageInfo.alias) {
alias = packageInfo.alias(name);
}
if (!alias && (aliasFn = this.runtime.Config.alias)) {
alias = aliasFn(name);
}
}
return alias;
},
getUri: function () {
var uri;
if (!this.uri) {
if (this.path) {
uri = this.path;
} else {
var name = this.name,
packageInfo = this.getPackage(),
packageUri = packageInfo.getUri(),
packageName = packageInfo.getName(),
extname = '.' + this.getType(),
tag = this.getTag(),
subPath;
subPath = pathRemoveExt(name) + extname;
if (packageName) {
subPath = pathGetRelative(packageName, subPath);
}
uri = pathAddBase(subPath, packageUri);
if (tag) {
uri = pathAddQuery(uri, 't', tag + extname);
}
}
this.uri = uri;
}
return this.uri;
},
getPath: function () {
return this.path || (this.path = this.getUri());
},
getName: function () {
return this.name;
},
getPackage: function () {
return this.packageInfo ||
(this.packageInfo = getPackage(this.runtime, this.name));
},
getTag: function () {
return this.tag || this.getPackage().getTag();
},
getCharset: function () {
return this.charset || this.getPackage().getCharset();
},
getRequiresWithAlias: function () {
var requiresWithAlias = this.requiresWithAlias,
requires = this.requires;
if (!requires || !requires.length) {
return requires || [];
} else if (!requiresWithAlias) {
this.requiresWithAlias = requiresWithAlias =
normalizeModNamesWithAlias(this.runtime, requires, this.name);
}
return requiresWithAlias;
},
getRequiredMods: function () {
var runtime = this.runtime;
return map(this.getNormalizedRequires(), function (r) {
return createModuleInfo(runtime, r);
});
},
getNormalizedRequires: function () {
var normalizedRequires,
normalizedRequiresStatus = this.normalizedRequiresStatus,
status = this.status,
requires = this.requires;
if (!requires || !requires.length) {
return requires || [];
} else if ((normalizedRequires = this.normalizedRequires) &&
(normalizedRequiresStatus === status)) {
return normalizedRequires;
} else {
this.normalizedRequiresStatus = status;
this.normalizedRequires = normalizeModNames(this.runtime, requires, this.name);
return this.normalizedRequires;
}
}
};
Loader.Module = Module;
var PACKAGE_MEMBERS = ['alias', 'tag', 'group', 'charset'];
mix(Config.fns, {
packages : function (config) {
var name,
Config = this.Config,
ps = Config.packages = Config.packages || {};
if (config) {
each(config, function (cfg, key) {
name = cfg.name || key;
var path = cfg.base || cfg.path;
var newConfig = {
runtime: S,
name: name
};
each(PACKAGE_MEMBERS, function (m) {
if (m in cfg) {
newConfig[m] = cfg[m];
}
});
if (path) {
if (!endsWith(path, '/')) {
path += '/';
}
newConfig.uri = normalizeBase(path);
}
if (ps[name]) {
ps[name].reset(newConfig);
} else {
ps[name] = new Package(newConfig);
}
});
return undefined;
} else if (config === false) {
Config.packages = {};
return undefined;
} else {
return ps;
}
},
modules: function (modules) {
var self = this;
if (modules) {
each(modules, function (modCfg, modName) {
var mod = createModuleInfo(self, modName, modCfg);
if (mod.status === INIT) {
mix(mod, modCfg);
}
});
}
},
base: function (base) {
if (!base) {
return Config.baseUri;
} else {
Config.baseUri = normalizeBase(base);
return undefined;
}
}
});
function normalizeBase(base) {
base = replace(base, /\\/g, '/');
if (charAt(base, base.length - 1) !== '/') {
base += '/';
}
return pathAddBase(base);
}
function loadScripts(runtime, rss, callback, charset, timeout) {
var count = rss && rss.length,
errorList = [],
successList = [];
function complete() {
if (!(--count)) {
callback(successList, errorList);
}
}
each(rss, function (rs) {
var mod;
var config = {
timeout: timeout,
success: function () {
successList.push(rs);
if (mod && currentMod) {
registerModule(runtime, mod.name, currentMod.factory, currentMod.config);
currentMod = undefined;
}
complete();
},
error: function () {
errorList.push(rs);
complete();
},
charset: charset
};
if (!rs.combine) {
mod = rs.mods[0];
if (mod.getType() === 'css') {
mod = undefined;
}
}
getScript(rs.path, config);
});
}
function ComboLoader(runtime, waitingModules) {
this.runtime = runtime;
this.waitingModules = waitingModules;
}
var currentMod,
startLoadModName,
startLoadModTime,
groupTag = now();
ComboLoader.groupTag = groupTag;
function checkKISSYRequire(config, factory) {
if (!config && isFunction(factory) && factory.length > 1) {
var requires = getRequiresFromFn(factory);
if (requires.length) {
config = config || {};
config.requires = requires;
}
} else {
if (config && config.requires && !config.cjs) {
config.cjs = 0;
}
}
return config;
}
ComboLoader.add = function (name, factory, config, runtime, argsLen) {
if (argsLen === 3 && isArray(factory)) {
var tmp = factory;
factory = config;
config = {
requires: tmp,
cjs: 1
};
}
if (isFunction(name) || argsLen === 1) {
config = factory;
factory = name;
config = checkKISSYRequire(config, factory);
currentMod = {
factory: factory,
config: config
};
} else {
currentMod = undefined;
config = checkKISSYRequire(config, factory);
registerModule(runtime, name, factory, config);
}
};
function getCommonPrefix(str1, str2) {
str1 = split(str1, /\//);
str2 = split(str2, /\//);
var l = Math.min(str1.length, str2.length);
for (var i = 0; i < l; i++) {
if (str1[i] !== str2[i]) {
break;
}
}
return slice(str1, 0, i).join('/') + '/';
}
ComboLoader.prototype = {
use: function (normalizedModNames) {
var self = this,
allModNames,
comboUrls,
timeout = Config.timeout,
runtime = self.runtime;
allModNames = keys(self.calculate(normalizedModNames));
createModulesInfo(runtime, allModNames);
comboUrls = self.getComboUrls(allModNames);
each(comboUrls.css, function (cssOne) {
loadScripts(runtime, cssOne, function (success, error) {
each(success, function (one) {
each(one.mods, function (mod) {
registerModule(runtime, mod.name, noop);
mod.notifyAll();
});
});
each(error, function (one) {
each(one.mods, function (mod) {
mod.status = ERROR;
mod.notifyAll();
});
});
}, cssOne.charset, timeout);
});
each(comboUrls.js, function (jsOne) {
loadScripts(runtime, jsOne, function (success) {
each(jsOne, function (one) {
each(one.mods, function (mod) {
if (!mod.factory) {
mod.status = ERROR;
}
mod.notifyAll();
});
});
}, jsOne.charset, timeout);
});
},
calculate: function (modNames, cache, ret) {
var i,
m,
mod,
modStatus,
self = this,
waitingModules = self.waitingModules,
runtime = self.runtime;
ret = ret || {};
cache = cache || {};
for (i = 0; i < modNames.length; i++) {
m = modNames[i];
if (cache[m]) {
continue;
}
cache[m] = 1;
mod = createModuleInfo(runtime, m);
modStatus = mod.status;
if (modStatus >= READY_TO_ATTACH) {
continue;
}
if (modStatus !== LOADED) {
if (!waitingModules.contains(m)) {
if (modStatus !== LOADING) {
mod.status = LOADING;
ret[m] = 1;
}
mod.wait(function (mod) {
waitingModules.remove(mod.name);
waitingModules.notifyAll();
});
waitingModules.add(m);
}
}
self.calculate(mod.getNormalizedRequires(), cache, ret);
}
return ret;
},
getComboMods: function (modNames, comboPrefixes) {
var comboMods = {},
runtime = this.runtime,
packageUri, mod, packageInfo, type, typedCombos, mods,
tag, charset, comboName, packageName;
each(modNames, function(modName) {
mod = createModuleInfo(runtime, modName);
type = mod.getType();
packageInfo = mod.getPackage();
packageName = packageInfo.name;
charset = packageInfo.getCharset();
tag = packageInfo.getTag();
packageUri = packageInfo.getUri();
comboName = packageName;
mod.canBeCombined = 0;
comboPrefixes[packageName] = packageUri;
typedCombos = comboMods[type] = comboMods[type] || {};
if (!(mods = typedCombos[comboName])) {
mods = typedCombos[comboName] = [];
mods.charset = charset;
mods.tags = [tag];
} else {
if (!(mods.tags.length === 1 && mods.tags[0] === tag)) {
mods.tags.push(tag);
}
}
mods.push(mod);
});
return comboMods;
},
getComboUrls: function (modNames) {
var runtime = this.runtime,
Config = runtime.Config,
comboPrefix = Config.comboPrefix,
comboSep = Config.comboSep,
maxFileNum = Config.comboMaxFileNum,
maxUrlLength = Config.comboMaxUrlLength;
var comboPrefixes = {};
var comboMods = this.getComboMods(modNames, comboPrefixes);
var comboRes = {};
for (var type in comboMods) {
comboRes[type] = {};
for (var comboName in comboMods[type]) {
var currentComboMods = [];
var mods = comboMods[type][comboName];
var tags = mods.tags;
var tag = tags.length > 1 ? getHash(tags.join('')) : tags[0];
var suffix = (tag ? '?t=' + encodeURIComponent(tag) + '.' + type : ''),
suffixLength = suffix.length,
basePrefix = comboPrefixes[comboName].toString(),
baseLen = basePrefix.length,
prefix = basePrefix + comboPrefix,
res = comboRes[type][comboName] = [];
var l = prefix.length;
res.charset = mods.charset;
res.mods = [];
for (var i = 0; i < mods.length; i++) {
var currentMod = mods[i];
res.mods.push(currentMod);
var path = currentMod.getPath();
res.push({
combine: 0,
path: path,
mods: [currentMod]
});
}
}
}
return comboRes;
}
};
Loader.ComboLoader = ComboLoader;
function WaitingModules(fn) {
this.fn = fn;
this.waitMods = {};
this.waitModsNum = 0;
}
WaitingModules.prototype = {
constructor: WaitingModules,
notifyAll: function () {
var fn = this.fn;
if (fn && !this.waitModsNum) {
this.fn = null;
fn();
}
},
add: function (modName) {
this.waitMods[modName] = 1;
this.waitModsNum++;
},
remove: function (modName) {
delete this.waitMods[modName];
this.waitModsNum--;
},
contains: function (modName) {
return this.waitMods[modName];
}
};
Loader.WaitingModules = WaitingModules;
mix(S, {
add: function (name, factory, cfg) {
ComboLoader.add(name, factory, cfg, S, arguments.length);
},
use: function (modNames, success) {
var normalizedModNames,
loader,
error,
sync,
tryCount = 0,
finalSuccess,
waitingModules = new WaitingModules(loadReady);
if (isObject(success)) {
sync = success.sync;
error = success.error;
success = success.success;
}
finalSuccess = function () {
success.apply(S, getModules(S, modNames));
};
modNames = getModNamesAsArray(modNames);
modNames = normalizeModNamesWithAlias(S, modNames);
normalizedModNames = unalias(S, modNames);
function loadReady() {
++tryCount;
var errorList = [],
start = now(),
ret;
ret = checkModsLoadRecursively(normalizedModNames, S, undefined, errorList);
if (ret) {
attachModsRecursively(normalizedModNames, S);
if (success) {
if (sync) {
finalSuccess();
} else {
setImmediate(finalSuccess);
}
}
} else if (errorList.length) {
if (error) {
if (sync) {
error.apply(S, errorList);
} else {
setImmediate(function () {
error.apply(S, errorList);
});
}
}
} else {
waitingModules.fn = loadReady;
loader.use(normalizedModNames);
}
}
loader = new ComboLoader(S, waitingModules);
if (sync) {
waitingModules.notifyAll();
} else {
setImmediate(function () {
waitingModules.notifyAll();
});
}
return S;
},
require: function (moduleName, refName) {
if (moduleName) {
var moduleNames = unalias(S, normalizeModNamesWithAlias(S, [moduleName], refName));
attachModsRecursively(moduleNames, S);
return getModules(S, moduleNames)[1];
}
}
});
Env.mods = {};