From 24ceb3480c0bb08f773f88153384935262a2008f Mon Sep 17 00:00:00 2001 From: Christoph Oberhofer Date: Fri, 13 Mar 2015 20:07:23 +0100 Subject: [PATCH] Removing dependency on script-name --- build/start.frag | 16 ++++++---------- dist/quagga.js | 47 +++++++++++++++++++++++------------------------ src/quagga.js | 31 +++++++++++++++++-------------- 3 files changed, 46 insertions(+), 48 deletions(-) diff --git a/build/start.frag b/build/start.frag index e12082a..7372927 100644 --- a/build/start.frag +++ b/build/start.frag @@ -1,15 +1,11 @@ (function (root, factory) { - if (typeof define === 'function' && define.amd) { - //Allow using this built library as an AMD module - //in another project. That other project will only - //see this AMD call, not the internal modules in - //the closure below. - define([], factory); - } else if (typeof module !== 'undefined') { - module.exports = factory(); + var factorySource = factory.toString(); + + if (typeof module !== 'undefined') { + module.exports = factory(factorySource); } else { //Browser globals case. Just assign the //result to a property on the global. - root.Quagga = factory(); + root.Quagga = factory(factorySource); } -}(this, function () { \ No newline at end of file +}(this, function (__factorySource__) { \ No newline at end of file diff --git a/dist/quagga.js b/dist/quagga.js index 9ef2401..661e7f4 100644 --- a/dist/quagga.js +++ b/dist/quagga.js @@ -1,18 +1,14 @@ (function (root, factory) { - if (typeof define === 'function' && define.amd) { - //Allow using this built library as an AMD module - //in another project. That other project will only - //see this AMD call, not the internal modules in - //the closure below. - define([], factory); - } else if (typeof module !== 'undefined') { - module.exports = factory(); + var factorySource = factory.toString(); + + if (typeof module !== 'undefined') { + module.exports = factory(factorySource); } else { //Browser globals case. Just assign the //result to a property on the global. - root.Quagga = factory(); + root.Quagga = factory(factorySource); } -}(this, function () {/** +}(this, function (__factorySource__) {/** * @license almond 0.2.9 Copyright (c) 2011-2014, The Dojo Foundation All Rights Reserved. * Available via the MIT or new BSD license. * see: http://github.com/jrburke/almond for details @@ -7300,8 +7296,9 @@ define('camera_access',["html_utils"], function(HtmlUtils) { } }; }); -/* 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('quagga',["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) { @@ -7580,8 +7577,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; @@ -7615,18 +7617,15 @@ function(Code128Reader, EANReader, InputStream, ImageWrapper, BarcodeLocator, Ba function generateWorkerBlob() { var blob, - quaggaAbsoluteUrl, - scripts = document.getElementsByTagName('script'), - regex = new RegExp('\/' + _config.scriptName + '$'); - - quaggaAbsoluteUrl = Array.prototype.slice.apply(scripts).filter(function(script) { - return script.src && script.src.match(regex); - }).map(function(script) { - return script.src; - })[0]; + factorySource; + /* 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); diff --git a/src/quagga.js b/src/quagga.js index b93268c..0f42ed6 100644 --- a/src/quagga.js +++ b/src/quagga.js @@ -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 + '$'); - - quaggaAbsoluteUrl = Array.prototype.slice.apply(scripts).filter(function(script) { - return script.src && script.src.match(regex); - }).map(function(script) { - return script.src; - })[0]; + factorySource; + /* 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);