guess worker base path

This commit is contained in:
Fabian Jakobs 2011-02-07 10:54:18 +01:00
commit d6d9a7329d

View file

@ -16,7 +16,8 @@ var WorkerClient = function(topLevelNamespaces, packagedJs, module, classname) {
this.callbacks = [];
if (require.packaged) {
var worker = this.$worker = new Worker(packagedJs);
var base = this.$guessBasePath();
var worker = this.$worker = new Worker(base + packagedJs);
}
else {
var workerUrl = require.nameToUrl("ace/worker/worker", null, "_");
@ -70,6 +71,16 @@ var WorkerClient = function(topLevelNamespaces, packagedJs, module, classname) {
oop.implement(this, EventEmitter);
this.$guessBasePath = function() {
var scripts = document.getElementsByTagName("script");
for (var i=0; i<scripts.length; i++) {
var m = scripts[i].src.match(/^(.*\/)ace\.js$/);
if (m)
return m[1];
}
return "";
};
this.terminate = function() {
this._dispatchEvent("terminate", {});
this.$worker.terminate();