Skip to content

Instantly share code, notes, and snippets.

@TCotton
Created January 21, 2013 17:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save TCotton/4587498 to your computer and use it in GitHub Desktop.
Save TCotton/4587498 to your computer and use it in GitHub Desktop.
Detects browser web worker support
WEB_WORKER = window.WEB_WORKER || {};
WEB_WORKER = (function($, window) {
var _private = {
worker: null,
file: null,
web_worker: function() {
return !!window.Worker;
},
set_url: function(args) {
this.file = args.url;
this.set_web_worker();
},
set_web_worker: function() {
this.worker = new Worker(this.file);
},
get_web_worker: function() {
return this.worker;
}
};
return {
init: function(args) {
if (_private.web_worker()) {
_private.set_url(args);
WEB_WORKER.DETECTION = _private.get_web_worker();
} else {
WEB_WORKER.DETECTION = null;
}
}
};
}(jQuery, window));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment