171 lines
No EOL
5.2 KiB
JavaScript
171 lines
No EOL
5.2 KiB
JavaScript
/* ***** BEGIN LICENSE BLOCK *****
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
*
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
* the License. You may obtain a copy of the License at
|
|
* http://www.mozilla.org/MPL/
|
|
*
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
* for the specific language governing rights and limitations under the
|
|
* License.
|
|
*
|
|
* The Original Code is Ajax.org Code Editor (ACE).
|
|
*
|
|
* The Initial Developer of the Original Code is
|
|
* Ajax.org B.V.
|
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
|
* the Initial Developer. All Rights Reserved.
|
|
*
|
|
* Contributor(s):
|
|
* Fabian Jakobs <fabian AT ajax DOT org>
|
|
* Julian Viereck <julian.viereck@gmail.com>
|
|
*
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
* the provisions above, a recipient may use your version of this file under
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
*
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
/**
|
|
* Define a module along with a payload
|
|
* @param module a name for the payload
|
|
* @param payload a function to call with (require, exports, module) params
|
|
*/
|
|
|
|
(function() {
|
|
|
|
var _define = function(module, deps, payload) {
|
|
if (typeof module !== 'string') {
|
|
if (_define.original)
|
|
_define.original.apply(window, arguments);
|
|
else {
|
|
console.error('dropping module because define wasn\'t a string.');
|
|
console.trace();
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (arguments.length == 2)
|
|
payload = deps;
|
|
|
|
if (!_define.modules)
|
|
_define.modules = {};
|
|
|
|
_define.modules[module] = payload;
|
|
};
|
|
|
|
/**
|
|
* Get at functionality define()ed using the function above
|
|
*/
|
|
var _require = function(parentId, 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(parentId, module[i]);
|
|
if (!dep && _require.original)
|
|
return _require.original.apply(window, arguments);
|
|
params.push(dep);
|
|
}
|
|
if (callback) {
|
|
callback.apply(null, params);
|
|
}
|
|
}
|
|
else if (typeof module === 'string') {
|
|
var payload = lookup(parentId, module);
|
|
if (!payload && _require.original)
|
|
return _require.original.apply(window, arguments);
|
|
|
|
if (callback) {
|
|
callback();
|
|
}
|
|
|
|
return payload;
|
|
}
|
|
else {
|
|
if (_require.original)
|
|
return _require.original.apply(window, arguments);
|
|
}
|
|
};
|
|
|
|
_require.packaged = true;
|
|
_require.noWorker = true;
|
|
|
|
var normalizeModule = function(parentId, moduleName) {
|
|
// normalize plugin requires
|
|
if (moduleName.indexOf("!") !== -1) {
|
|
var chunks = moduleName.split("!");
|
|
return normalizeModule(parentId, chunks[0]) + "!" + normalizeModule(parentId, chunks[1]);
|
|
}
|
|
// normalize relative requires
|
|
if (moduleName.charAt(0) == ".") {
|
|
var base = parentId.split("/").slice(0, -1).join("/");
|
|
moduleName = base + "/" + moduleName;
|
|
|
|
while(moduleName.indexOf(".") !== -1 && previous != moduleName) {
|
|
var previous = moduleName;
|
|
moduleName = moduleName.replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, "");
|
|
}
|
|
}
|
|
|
|
return moduleName;
|
|
};
|
|
|
|
/**
|
|
* Internal function to lookup moduleNames and resolve them by calling the
|
|
* definition function if needed.
|
|
*/
|
|
var lookup = function(parentId, moduleName) {
|
|
|
|
moduleName = normalizeModule(parentId, moduleName);
|
|
|
|
var module = _define.modules[moduleName];
|
|
if (!module) {
|
|
return null;
|
|
}
|
|
|
|
if (typeof module === 'function') {
|
|
var exports = {};
|
|
var mod = {
|
|
id: moduleName,
|
|
uri: '',
|
|
exports: exports
|
|
};
|
|
|
|
var req = function(module, callback) {
|
|
return _require(moduleName, module, callback);
|
|
};
|
|
|
|
var returnValue = module(req, exports, mod);
|
|
exports = returnValue || mod.exports;
|
|
|
|
// cache the resulting module object for next time
|
|
_define.modules[moduleName] = exports;
|
|
return exports;
|
|
}
|
|
|
|
return module;
|
|
};
|
|
|
|
|
|
/**
|
|
* Expose as "shadowed" object to the outside world.
|
|
*/
|
|
|
|
window.__ace_shadowed__ = {
|
|
require: function(module, callback) {
|
|
return _require("", module, callback);
|
|
},
|
|
define: _define
|
|
};
|
|
|
|
})(); |