description and source-codefunction define(name, deps, factory) {
if (typeof name !== 'string') {
factory = deps;
deps = name;
name = null;
}
if (!(deps instanceof Array)) {
factory = deps;
deps = ['require', 'exports', 'module'].splice(0, factory.length);
}
if (typeof factory !== 'function')
factory = (function (factory) {
return function() { return factory; }
})(factory);
if (!name) {
if (curMetaDeps) {
deps = deps.concat(curMetaDeps);
curMetaDeps = undefined;
}
}
// remove system dependencies
var requireIndex, exportsIndex, moduleIndex;
if ((requireIndex = deps.indexOf('require')) !== -1) {
deps.splice(requireIndex, 1);
// only trace cjs requires for non-named
// named defines assume the trace has already been done
if (!name)
deps = deps.concat(amdGetCJSDeps(factory.toString(), requireIndex));
}
if ((exportsIndex = deps.indexOf('exports')) !== -1)
deps.splice(exportsIndex, 1);
if ((moduleIndex = deps.indexOf('module')) !== -1)
deps.splice(moduleIndex, 1);
function execute (req, exports, module) {
var depValues = [];
for (var i = 0; i < deps.length; i++)
depValues.push(req(deps[i]));
module.uri = module.id;
module.config = noop;
// add back in system dependencies
if (moduleIndex !== -1)
depValues.splice(moduleIndex, 0, module);
if (exportsIndex !== -1)
depValues.splice(exportsIndex, 0, exports);
if (requireIndex !== -1) {
var contextualRequire = function (names, callback, errback) {
if (typeof names === 'string' && typeof callback !== 'function')
return req(names);
return require.call(loader, names, callback, errback, module.id);
};
contextualRequire.toUrl = function (name) {
return loader.normalizeSync(name, module.id);
};
depValues.splice(requireIndex, 0, contextualRequire);
}
// set global require to AMD require
var curRequire = envGlobal.require;
envGlobal.require = require;
var output = factory.apply(exportsIndex === -1 ? envGlobal : exports, depValues);
envGlobal.require = curRequire;
if (typeof output !== 'undefined')
module.exports = output;
}
// anonymous define
if (!name) {
loader.registerDynamic(deps, false, curEsModule ? wrapEsModuleExecute(execute) : execute);
}
else {
loader.registerDynamic(name, deps, false, execute);
// if we don't have any other defines,
// then let this be an anonymous define
// this is just to support single modules of the form:
// define('jquery')
// still loading anonymously
// because it is done widely enough to be useful
// as soon as there is more than one define, this gets removed though
if (lastNamedDefine) {
lastNamedDefine = undefined;
multipleNamedDefines = true;
}
else if (!multipleNamedDefines) {
lastNamedDefine = [deps, execute];
}
}
}