Removing dependency on script-name

This commit is contained in:
Christoph Oberhofer
2015-03-13 20:07:23 +01:00
parent f7e1c9728c
commit 24ceb3480c
3 changed files with 46 additions and 48 deletions
+17 -14
View File
@@ -1,5 +1,6 @@
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define, vec2, importScripts */
/* jshint undef: true, unused: true, browser:true, devel: true, evil: true */
/* global define, vec2 */
define(["code_128_reader", "ean_reader", "input_stream", "image_wrapper", "barcode_locator", "barcode_decoder", "frame_grabber", "html_utils", "config", "events", "camera_access", "image_debug"],
function(Code128Reader, EANReader, InputStream, ImageWrapper, BarcodeLocator, BarcodeDecoder, FrameGrabber, HtmlUtils, _config, Events, CameraAccess, ImageDebug) {
@@ -278,8 +279,13 @@ function(Code128Reader, EANReader, InputStream, ImageWrapper, BarcodeLocator, Ba
}
function workerInterface(scriptUrl) {
importScripts(scriptUrl);
function workerInterface(factory) {
if (factory) {
var Quagga = factory();
if (!Quagga) {
return;
}
}
/* jshint ignore:start */
var imageWrapper;
@@ -313,18 +319,15 @@ function(Code128Reader, EANReader, InputStream, ImageWrapper, BarcodeLocator, Ba
function generateWorkerBlob() {
var blob,
quaggaAbsoluteUrl,
scripts = document.getElementsByTagName('script'),
regex = new RegExp('\/' + _config.scriptName + '$');
factorySource;
quaggaAbsoluteUrl = Array.prototype.slice.apply(scripts).filter(function(script) {
return script.src && script.src.match(regex);
}).map(function(script) {
return script.src;
})[0];
/* jshint ignore:start */
if (typeof __factorySource__ !== 'undefined') {
factorySource = __factorySource__;
}
/* jshint ignore:end */
blob = new Blob(['(' + workerInterface.toString() + ')("' + quaggaAbsoluteUrl + '");'],
blob = new Blob(['(' + workerInterface.toString() + ')(' + factorySource + ');'],
{type : 'text/javascript'});
return window.URL.createObjectURL(blob);