revert: No need to fallback to existing requireJS.
This commit is contained in:
parent
91f4ab4f6c
commit
de438858a9
1 changed files with 27 additions and 5 deletions
|
|
@ -48,15 +48,19 @@ var global = (function() {
|
|||
})();
|
||||
|
||||
// if we find an existing require function use it.
|
||||
if (global.require) {
|
||||
if (global.require && global.define) {
|
||||
require.packaged = true;
|
||||
return;
|
||||
}
|
||||
|
||||
global.define = function(module, deps, payload) {
|
||||
var _define = function(module, deps, payload) {
|
||||
if (typeof module !== 'string') {
|
||||
console.error('dropping module because define wasn\'t a string.');
|
||||
console.trace();
|
||||
if (_define.original)
|
||||
_define.original.apply(window, arguments);
|
||||
else {
|
||||
console.error('dropping module because define wasn\'t a string.');
|
||||
console.trace();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -68,15 +72,22 @@ global.define = function(module, deps, payload) {
|
|||
|
||||
define.modules[module] = payload;
|
||||
};
|
||||
if (global.define)
|
||||
_define.original = global.define;
|
||||
|
||||
global.define = _define;
|
||||
|
||||
|
||||
/**
|
||||
* Get at functionality define()ed using the function above
|
||||
*/
|
||||
global.require = function(module, callback) {
|
||||
var _require = function(module, callback) {
|
||||
if (Object.prototype.toString.call(module) === "[object Array]") {
|
||||
var params = [];
|
||||
for (var i = 0, l = module.length; i < l; ++i) {
|
||||
var dep = lookup(module[i]);
|
||||
if (!dep && _require.original)
|
||||
return _require.original.apply(window, arguments);
|
||||
params.push(dep);
|
||||
}
|
||||
if (callback) {
|
||||
|
|
@ -85,6 +96,8 @@ global.require = function(module, callback) {
|
|||
}
|
||||
else if (typeof module === 'string') {
|
||||
var payload = lookup(module);
|
||||
if (!payload && _require.original)
|
||||
return _require.original.apply(window, arguments);
|
||||
|
||||
if (callback) {
|
||||
callback();
|
||||
|
|
@ -92,7 +105,16 @@ global.require = function(module, callback) {
|
|||
|
||||
return payload;
|
||||
}
|
||||
else {
|
||||
if (_require.original)
|
||||
return _require.original.apply(window, arguments);
|
||||
}
|
||||
};
|
||||
|
||||
if (global.require)
|
||||
_require.original = global.require;
|
||||
|
||||
global.require = _require;
|
||||
require.packaged = true;
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue