Skip to content

Commit

Permalink
Do a better job of choosing a base url for worker import scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert D. Vincent committed Nov 25, 2016
1 parent 76afedd commit 33af6b4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
19 changes: 19 additions & 0 deletions src/brainbrowser/lib/utils.js
Expand Up @@ -126,6 +126,25 @@
return window.URL.createObjectURL(new Blob([data], {type : mime_type || "text/plain"}));
},

/**
* @doc function
* @name BrainBrowser.utils:getWorkerImportURL
*
* @description
* Assemble an absolute path for possible script imports within
* a worker.
*/
getWorkerImportURL: function() {
var worker_dir = BrainBrowser.config.get("worker_dir");
var import_url = document.location.origin + '/' + worker_dir;
var doc_href = document.location.href;
var slash_index = doc_href.lastIndexOf('/');
if (slash_index >= 0) {
import_url = doc_href.substring(0, slash_index + 1) + worker_dir;
}
return import_url;
},

/**
* @doc function
* @name BrainBrowser.utils:min
Expand Down
Expand Up @@ -64,6 +64,6 @@ BrainBrowser.SurfaceViewer.parseIntensityData = function(data, type, callback) {
worker.terminate();
});

var url = document.location.protocol + '//' + document.location.host;
var url = BrainBrowser.utils.getWorkerImportURL();
worker.postMessage({ cmd: "parse", data: data, url: url });
};
3 changes: 2 additions & 1 deletion src/brainbrowser/surface-viewer/modules/loading.js
Expand Up @@ -522,10 +522,11 @@ BrainBrowser.SurfaceViewer.modules.loading = function(viewer) {
parse_worker.terminate();
});

var import_url = BrainBrowser.utils.getWorkerImportURL();
parse_worker.postMessage({
data: data,
options: options,
url: document.location.protocol + '//' + document.location.host
url: import_url
});

}
Expand Down
2 changes: 1 addition & 1 deletion src/brainbrowser/workers/gifti.worker.js
Expand Up @@ -53,7 +53,7 @@
* message. This gets around issues with loading a script from
* within a worker blob.
*/
importScripts(input.url + '/js/brainbrowser/workers/gifti-reader.js');
importScripts(input.url + 'gifti-reader.js');

var result = parse(input.data) || {
error: true,
Expand Down

0 comments on commit 33af6b4

Please sign in to comment.