Skip to content

Commit 24ceb34

Browse files
committed
Removing dependency on script-name
1 parent f7e1c97 commit 24ceb34

File tree

3 files changed

+46
-48
lines changed

3 files changed

+46
-48
lines changed

build/start.frag

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
(function (root, factory) {
2-
if (typeof define === 'function' && define.amd) {
3-
//Allow using this built library as an AMD module
4-
//in another project. That other project will only
5-
//see this AMD call, not the internal modules in
6-
//the closure below.
7-
define([], factory);
8-
} else if (typeof module !== 'undefined') {
9-
module.exports = factory();
2+
var factorySource = factory.toString();
3+
4+
if (typeof module !== 'undefined') {
5+
module.exports = factory(factorySource);
106
} else {
117
//Browser globals case. Just assign the
128
//result to a property on the global.
13-
root.Quagga = factory();
9+
root.Quagga = factory(factorySource);
1410
}
15-
}(this, function () {
11+
}(this, function (__factorySource__) {

dist/quagga.js

+23-24
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
(function (root, factory) {
2-
if (typeof define === 'function' && define.amd) {
3-
//Allow using this built library as an AMD module
4-
//in another project. That other project will only
5-
//see this AMD call, not the internal modules in
6-
//the closure below.
7-
define([], factory);
8-
} else if (typeof module !== 'undefined') {
9-
module.exports = factory();
2+
var factorySource = factory.toString();
3+
4+
if (typeof module !== 'undefined') {
5+
module.exports = factory(factorySource);
106
} else {
117
//Browser globals case. Just assign the
128
//result to a property on the global.
13-
root.Quagga = factory();
9+
root.Quagga = factory(factorySource);
1410
}
15-
}(this, function () {/**
11+
}(this, function (__factorySource__) {/**
1612
* @license almond 0.2.9 Copyright (c) 2011-2014, The Dojo Foundation All Rights Reserved.
1713
* Available via the MIT or new BSD license.
1814
* see: http://github.com/jrburke/almond for details
@@ -7300,8 +7296,9 @@ define('camera_access',["html_utils"], function(HtmlUtils) {
73007296
}
73017297
};
73027298
});
7303-
/* jshint undef: true, unused: true, browser:true, devel: true */
7304-
/* global define, vec2, importScripts */
7299+
/* jshint undef: true, unused: true, browser:true, devel: true, evil: true */
7300+
/* global define, vec2 */
7301+
73057302

73067303
define('quagga',["code_128_reader", "ean_reader", "input_stream", "image_wrapper", "barcode_locator", "barcode_decoder", "frame_grabber", "html_utils", "config", "events", "camera_access", "image_debug"],
73077304
function(Code128Reader, EANReader, InputStream, ImageWrapper, BarcodeLocator, BarcodeDecoder, FrameGrabber, HtmlUtils, _config, Events, CameraAccess, ImageDebug) {
@@ -7580,8 +7577,13 @@ function(Code128Reader, EANReader, InputStream, ImageWrapper, BarcodeLocator, Ba
75807577
}
75817578

75827579

7583-
function workerInterface(scriptUrl) {
7584-
importScripts(scriptUrl);
7580+
function workerInterface(factory) {
7581+
if (factory) {
7582+
var Quagga = factory();
7583+
if (!Quagga) {
7584+
return;
7585+
}
7586+
}
75857587
/* jshint ignore:start */
75867588
var imageWrapper;
75877589

@@ -7615,18 +7617,15 @@ function(Code128Reader, EANReader, InputStream, ImageWrapper, BarcodeLocator, Ba
76157617

76167618
function generateWorkerBlob() {
76177619
var blob,
7618-
quaggaAbsoluteUrl,
7619-
scripts = document.getElementsByTagName('script'),
7620-
regex = new RegExp('\/' + _config.scriptName + '$');
7621-
7622-
quaggaAbsoluteUrl = Array.prototype.slice.apply(scripts).filter(function(script) {
7623-
return script.src && script.src.match(regex);
7624-
}).map(function(script) {
7625-
return script.src;
7626-
})[0];
7620+
factorySource;
76277621

7622+
/* jshint ignore:start */
7623+
if (typeof __factorySource__ !== 'undefined') {
7624+
factorySource = __factorySource__;
7625+
}
7626+
/* jshint ignore:end */
76287627

7629-
blob = new Blob(['(' + workerInterface.toString() + ')("' + quaggaAbsoluteUrl + '");'],
7628+
blob = new Blob(['(' + workerInterface.toString() + ')(' + factorySource + ');'],
76307629
{type : 'text/javascript'});
76317630

76327631
return window.URL.createObjectURL(blob);

src/quagga.js

+17-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
/* jshint undef: true, unused: true, browser:true, devel: true */
2-
/* global define, vec2, importScripts */
1+
/* jshint undef: true, unused: true, browser:true, devel: true, evil: true */
2+
/* global define, vec2 */
3+
34

45
define(["code_128_reader", "ean_reader", "input_stream", "image_wrapper", "barcode_locator", "barcode_decoder", "frame_grabber", "html_utils", "config", "events", "camera_access", "image_debug"],
56
function(Code128Reader, EANReader, InputStream, ImageWrapper, BarcodeLocator, BarcodeDecoder, FrameGrabber, HtmlUtils, _config, Events, CameraAccess, ImageDebug) {
@@ -278,8 +279,13 @@ function(Code128Reader, EANReader, InputStream, ImageWrapper, BarcodeLocator, Ba
278279
}
279280

280281

281-
function workerInterface(scriptUrl) {
282-
importScripts(scriptUrl);
282+
function workerInterface(factory) {
283+
if (factory) {
284+
var Quagga = factory();
285+
if (!Quagga) {
286+
return;
287+
}
288+
}
283289
/* jshint ignore:start */
284290
var imageWrapper;
285291

@@ -313,18 +319,15 @@ function(Code128Reader, EANReader, InputStream, ImageWrapper, BarcodeLocator, Ba
313319

314320
function generateWorkerBlob() {
315321
var blob,
316-
quaggaAbsoluteUrl,
317-
scripts = document.getElementsByTagName('script'),
318-
regex = new RegExp('\/' + _config.scriptName + '$');
319-
320-
quaggaAbsoluteUrl = Array.prototype.slice.apply(scripts).filter(function(script) {
321-
return script.src && script.src.match(regex);
322-
}).map(function(script) {
323-
return script.src;
324-
})[0];
322+
factorySource;
325323

324+
/* jshint ignore:start */
325+
if (typeof __factorySource__ !== 'undefined') {
326+
factorySource = __factorySource__;
327+
}
328+
/* jshint ignore:end */
326329

327-
blob = new Blob(['(' + workerInterface.toString() + ')("' + quaggaAbsoluteUrl + '");'],
330+
blob = new Blob(['(' + workerInterface.toString() + ')(' + factorySource + ');'],
328331
{type : 'text/javascript'});
329332

330333
return window.URL.createObjectURL(blob);

0 commit comments

Comments
 (0)