Extract packaged module loading

This commit is contained in:
Joshua Peek 2012-07-02 14:28:33 -05:00
commit b8a7b8ec90
4 changed files with 21 additions and 9 deletions

View file

@ -71,6 +71,22 @@ exports.all = function() {
return lang.copyObject(options);
};
exports.moduleUrl = function(name) {
var parts = name.split("/");
if (parts[0] !== "ace") return;
var component = parts[1];
var base = parts[2];
if (component == "mode") {
return this.get("modePath") + "/mode-" + base + this.get("suffix");
} else if (component === "theme") {
return this.get("themePath") + "/theme-" + base + this.get("suffix");
} else if (component == "worker") {
return this.get("workerPath") + "/" + base + this.get("suffix");
}
};
exports.init = function() {
options.packaged = require.packaged || module.packaged || (global.define && define.packaged);

View file

@ -835,7 +835,7 @@ var EditSession = function(text, mode) {
if (!this.$mode)
this.$setModePlaceholder();
fetch(function() {
fetch(mode, function() {
require([mode], done);
});
@ -852,13 +852,11 @@ var EditSession = function(text, mode) {
callback(_self.$modes[mode]);
}
function fetch(callback) {
function fetch(name, callback) {
if (!config.get("packaged"))
return callback();
var base = mode.split("/").pop();
var filename = config.get("modePath") + "/mode-" + base + ".js";
net.loadScript(filename, callback);
net.loadScript(config.moduleUrl(name), callback);
}
};

View file

@ -1288,9 +1288,7 @@ var VirtualRenderer = function(container, theme) {
if (!config.get("packaged"))
return callback();
var base = name.split("/").pop();
var filename = config.get("themePath") + "/theme-" + base + config.get("suffix");
net.loadScript(filename, callback);
net.loadScript(config.moduleUrl(name), callback);
};
/**

View file

@ -47,7 +47,7 @@ var WorkerClient = function(topLevelNamespaces, packagedJs, mod, classname) {
this.changeListener = this.changeListener.bind(this);
if (config.get("packaged")) {
this.$worker = new Worker(config.get("workerPath") + "/" + packagedJs);
this.$worker = new Worker(config.moduleUrl(mod));
}
else {
var workerUrl;