/** * spawn! event-driven web workers for modern browsers * @version v1.1.0 - 2015-11-19 * @author Kevin James * Copyright (c) 2015 Kevin James * Licensed under the MIT license. * https://github.com/kevinjamesus86/spawn */ !function(a,b){"function"==typeof define&&define.amd?define([],b):"object"==typeof exports?module.exports=b():a.Spawn=b()}(this,function(){"use strict";function a(b,c){if(!(this instanceof a))return new a(b,c);c=h({},a.config,c);var e,f="";"string"==typeof b?e=b:"function"==typeof b&&(f=k(b)),this.isMainThread=!0,this.file=l('importScripts("'+n+'");\nspawn.exportAs("'+c.workerAs+'");\n'+f),this.worker=new d(this.file),this._init(),e&&this.importScripts(e)}var b,c=window,d=c.Worker,e=c.URL||c.webkitURL,f=Object.prototype.hasOwnProperty,g=c.Blob;g||(b=c.BlobBuilder||c.WebKitBlobBuilder||c.MozBlobBuilder||c.MSBlobBuilder);var h=function(a){var b=Array.prototype.slice.call(arguments,1);return b.forEach(function(b){if(b)for(var c in b)f.call(b,c)&&(a[c]=b[c])}),a},i=/((['"`])(|[\s\S]*?[^\\])\2)|\/\/.*$|\/\*[\s\S]*?\*\//gm,j=/^function\s*[^{]*\{([\s\S]*)\}$/m,k=function(a){return a.toString().replace(i,"$1").replace(j,"$1")},l=function(a){var c,d="application/javascript";return g?c=new g([a],{type:d}):(c=new b,c.append(a),c=c.getBlob(d)),e.createObjectURL(c)},m={workerAs:"spawn"};a.fn=a.prototype,a.config=h(m),a.fn.uuid=function(){var a=this.isMainThread?"spawn_":"worker_";return a+Date.now().toString(32)+Math.random().toString(32)},a.fn.location={origin:location.origin||location.protocol+"//"+location.host,originPath:location.href.match(/^(.*\/)?(?:$|(.+?)(?:(\.[^.]*$)|$))/)[1].replace(/\/?$/,"")+"/"},a.fn.on=function(a,b){return this.callbacks[a]=this.callbacks[a]||[],this.callbacks[a].push(b),this},a.fn.emit=function(a,b,c,d){var e=!1;return"function"==typeof b?(c=b,b=null):"string"==typeof c&&(d=c),d=d||this.uuid(),"function"==typeof c&&(this.acks[d]=c,e=!0),this.worker.postMessage({id:d,event:a,data:b,ack:e}),this},a.fn._invoke=function(a,b,c,d){function e(a){d&&g.emit("spawn_ack",a,c)}var f=this.callbacks[a],g=this;if(f)for(var h=f.length,i=-1;++i