!function(n){function o(e,t){var n,i,r;if("string"==typeof e)return a(e);for(n=[],i=e.length,r=0;ra.byteLength);){if(r=f.parsers[n],!t&&r)for(o=0;oe.byteLength)){if(1===r)return h.getValue(e,s,o);for(u=[],c=0;ce.byteLength)p.log("Invalid Exif data: Invalid directory offset.");else{if(!((a=n+2+12*(o=e.getUint16(n,i)))+4>e.byteLength)){for(s=0;se.byteLength)p.log("Invalid Exif data: Invalid segment size.");else if(0===e.getUint16(t+8)){switch(e.getUint16(a)){case 18761:r=!0;break;case 19789:r=!1;break;default:return void p.log("Invalid Exif data: Invalid byte alignment marker.")}42===e.getUint16(a+2,r)?(o=e.getUint32(a+4,r),i.exif=new d.ExifMap,o=d.parseExifTags(e,a,a+o,r,i)):p.log("Invalid Exif data: Missing TIFF marker.")}else p.log("Invalid Exif data: Missing byte alignment offset.")},e.parsers[65505].push(d.parseExifData),d}),t("runtime/html5/image",["base","runtime/html5/runtime","runtime/html5/util"],function(e,t,r){return t.register("Image",{modified:!1,init:function(){var n=this,e=new Image;e.onload=function(){n._info={type:n.type,width:this.width,height:this.height},n._metas||"image/jpeg"!==n.type?n.owner.trigger("load"):r.parseMeta(n._blob,function(e,t){n._metas=t,n.owner.trigger("load")})},e.onerror=function(){n.owner.trigger("error")},n._img=e},loadFromBlob:function(e){var t=this._img;this._blob=e,this.type=e.type,t.src=r.createObjectURL(e.getSource()),this.owner.once("load",function(){r.revokeObjectURL(t.src)})},resize:function(e,t){var n=this._canvas||(this._canvas=document.createElement("canvas"));this._resize(this._img,n,e,t),this._blob=null,this.modified=!0,this.owner.trigger("complete")},getAsBlob:function(e){var t,n=this._blob,i=this.options;if(e=e||this.type,this.modified||this.type!==e){if(t=this._canvas,"image/jpeg"===e){if(n=r.canvasToDataUrl(t,"image/jpeg",i.quality),i.preserveHeaders&&this._metas&&this._metas.imageHead)return n=r.dataURL2ArrayBuffer(n),n=r.updateImageHead(n,this._metas.imageHead),n=r.arrayBufferToBlob(n,e)}else n=r.canvasToDataUrl(t,e);n=r.dataURL2Blob(n)}return n},getAsDataUrl:function(e){var t=this.options;return"image/jpeg"===(e=e||this.type)?r.canvasToDataUrl(this._canvas,e,t.quality):this._canvas.toDataURL(e)},getOrientation:function(){return this._metas&&this._metas.exif&&this._metas.exif.get("Orientation")||1},info:function(e){return e?(this._info=e,this):this._info},meta:function(e){return e?(this._meta=e,this):this._meta},destroy:function(){var e=this._canvas;this._img.onload=null,e&&(e.getContext("2d").clearRect(0,0,e.width,e.height),e.width=e.height=0,this._canvas=null),this._img.src="data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs%3D",this._img=this._blob=null},_resize:function(e,t,n,i){var r,o,a,s,u,c=this.options,l=e.width,f=e.height,h=this.getOrientation();~[5,6,7,8].indexOf(h)&&(n^=i,n^=i^=n),r=Math[c.crop?"max":"min"](n/l,i/f),c.allowMagnify||(r=Math.min(1,r)),o=l*r,a=f*r,c.crop?(t.width=n,t.height=i):(t.width=o,t.height=a),s=(t.width-o)/2,u=(t.height-a)/2,c.preserveHeaders||this._rotate2Orientaion(t,h),this._renderImageToCanvas(t,e,s,u,o,a)},_rotate2Orientaion:function(e,t){var n=e.width,i=e.height,r=e.getContext("2d");switch(t){case 5:case 6:case 7:case 8:e.width=i,e.height=n}switch(t){case 2:r.translate(n,0),r.scale(-1,1);break;case 3:r.translate(n,i),r.rotate(Math.PI);break;case 4:r.translate(0,i),r.scale(1,-1);break;case 5:r.rotate(.5*Math.PI),r.scale(1,-1);break;case 6:r.rotate(.5*Math.PI),r.translate(0,-i);break;case 7:r.rotate(.5*Math.PI),r.translate(n,-i),r.scale(-1,1);break;case 8:r.rotate(-.5*Math.PI),r.translate(-n,0)}},_renderImageToCanvas:function(){if(!e.os.ios)return function(e,t,n,i,r,o){e.getContext("2d").drawImage(t,n,i,r,o)};function E(e,t,n){var i,r,o=document.createElement("canvas"),a=o.getContext("2d"),s=0,u=n,c=n;for(o.width=1,o.height=n,a.drawImage(e,0,0),i=a.getImageData(0,0,1,n).data;s>1;return 0==(r=c/n)?1:r}return 7<=e.os.ios?function(e,t,n,i,r,o){var a=t.naturalWidth,s=t.naturalHeight,u=E(t,0,s);return e.getContext("2d").drawImage(t,0,0,a*u,s*u,n,i,r,o)}:function(e,t,n,i,r,o){var a,s,u,c,l,f,h,p,d,g,m,v=t.naturalWidth,b=t.naturalHeight,y=e.getContext("2d"),_=1048576<(m=(p=t).naturalWidth)*p.naturalHeight&&((d=document.createElement("canvas")).width=d.height=1,(g=d.getContext("2d")).drawImage(p,1-m,0),0===g.getImageData(0,0,1,1).data[3]),w="image/jpeg"===this.type,x=1024,R=0,k=0;for(_&&(v/=2,b/=2),y.save(),(a=document.createElement("canvas")).width=a.height=x,s=a.getContext("2d"),u=w?E(t,0,b):1,c=Math.ceil(x*r/v),l=Math.ceil(x*o/b/u);R>8&255),W(255&e)}function J(e,t,n,i,r){for(var o,a=r[0],s=r[240],u=function(e,t){var n,i,r,o,a,s,u,c,l,f,h=0;for(l=0;l<8;++l){n=e[h],i=e[h+1],r=e[h+2],o=e[h+3],a=e[h+4],s=e[h+5],u=e[h+6];var p=n+(c=e[h+7]),d=n-c,g=i+u,m=i-u,v=r+s,b=r-s,y=o+a,_=o-a,w=p+y,x=p-y,R=g+v,k=g-v;e[h]=w+R,e[h+4]=w-R;var E=.707106781*(k+x);e[h+2]=x+E,e[h+6]=x-E;var S=.382683433*((w=_+b)-(k=m+d)),U=.5411961*w+S,O=1.306562965*k+S,F=.707106781*(R=b+m),A=d+F,T=d-F;e[h+5]=T+U,e[h+3]=T-U,e[h+1]=A+O,e[h+7]=A-O,h+=8}for(l=h=0;l<8;++l){n=e[h],i=e[h+8],r=e[h+16],o=e[h+24],a=e[h+32],s=e[h+40],u=e[h+48];var D=n+(c=e[h+56]),C=n-c,I=i+u,q=i-u,M=r+s,B=r-s,L=o+a,P=o-a,j=D+L,z=D-L,H=I+M,N=I-M;e[h]=j+H,e[h+32]=j-H;var $=.707106781*(N+z);e[h+16]=z+$,e[h+48]=z-$;var V=.382683433*((j=P+B)-(N=q+C)),Q=.5411961*j+V,W=1.306562965*N+V,G=.707106781*(H=B+q),J=C+G,K=C-G;e[h+40]=K+Q,e[h+24]=K-Q,e[h+8]=J+W,e[h+56]=J-W,h++}for(l=0;l<64;++l)f=e[l]*t[l],X[l]=0>4;for(var m=1;m<=h;++m)Q(s);g&=15}o=32767+y[p],Q(r[(g<<4)+b[o]]),Q(v[o]),p++}return 63!=f&&Q(a),n}function K(e){e<=0&&(e=1),100>3)*y+(p=4*(7&g)),b<=_+d&&(h-=y*(_+1+d-b)),y<=s+p&&(h-=s+p-y+4),u=m[h++],c=m[h++],l=m[h++],I[g]=(B[u]+B[c+256>>0]+B[l+512>>0]>>16)-128,q[g]=(B[u+768>>0]+B[c+1024>>0]+B[l+1280>>0]>>16)-128,M[g]=(B[u+1280>>0]+B[c+1536>>0]+B[l+1792>>0]>>16)-128;r=J(I,F,r,R,E),o=J(q,A,o,k,S),a=J(M,A,a,k,S),s+=32}_+=8}if(0<=C){var w=[];w[1]=C+1,w[0]=(1<>0]=38470*e,B[e+512>>0]=7471*e+32768,B[e+768>>0]=-11059*e,B[e+1024>>0]=-21709*e,B[e+1280>>0]=32768*e+8421375,B[e+1536>>0]=-27439*e,B[e+1792>>0]=-5329*e}(),K(e)}return i.encode=function(e,t){return new i(t).encode(e)},i}),t("runtime/html5/androidpatch",["runtime/html5/util","runtime/html5/jpegencoder","base"],function(e,u,c){var l,f=e.canvasToDataUrl;e.canvasToDataUrl=function(e,t,n){var i,r,o,a,s;return c.os.android?("image/jpeg"===t&&void 0===l&&(a=(a=(~(s=(a=f.apply(null,arguments)).split(","))[0].indexOf("base64")?atob:decodeURIComponent)(s[1])).substring(0,2),l=255===a.charCodeAt(0)&&216===a.charCodeAt(1)),"image/jpeg"!==t||l?f.apply(null,arguments):(r=e.width,o=e.height,i=e.getContext("2d"),u.encode(i.getImageData(0,0,r,o),n))):f.apply(null,arguments)}}),t("runtime/html5/transport",["base","runtime/html5/runtime"],function(u,e){var t=u.noop,c=u.$;return e.register("Transport",{init:function(){this._status=0,this._response=null},send:function(){var n,e,t,i=this.owner,r=this.options,o=this._initAjax(),a=i._blob,s=r.server;r.sendAsBinary?(s+=(/\?/.test(s)?"&":"?")+c.param(i._formData),e=a.getSource()):(n=new FormData,c.each(i._formData,function(e,t){n.append(e,t)}),n.append(r.fileVal,a.getSource(),r.filename||i._formData.name||"")),r.withCredentials&&"withCredentials"in o?(o.open(r.method,s,!0),o.withCredentials=!0):o.open(r.method,s),this._setRequestHeader(o,r.headers),e?(o.overrideMimeType("application/octet-stream"),u.os.android?((t=new FileReader).onload=function(){o.send(this.result),t=t.onload=null},t.readAsArrayBuffer(e)):o.send(e)):o.send(n)},getResponse:function(){return this._response},getResponseAsJson:function(){return this._parseJson(this._response)},getStatus:function(){return this._status},abort:function(){var e=this._xhr;e&&(e.upload.onprogress=t,e.onreadystatechange=t,e.abort(),this._xhr=e=null)},destroy:function(){this.abort()},_initAjax:function(){var n=this,e=new XMLHttpRequest;return!this.options.withCredentials||"withCredentials"in e||"undefined"==typeof XDomainRequest||(e=new XDomainRequest),e.upload.onprogress=function(e){var t=0;return e.lengthComputable&&(t=e.loaded/e.total),n.trigger("progress",t)},e.onreadystatechange=function(){if(4===e.readyState)return e.upload.onprogress=t,e.onreadystatechange=t,n._xhr=null,n._status=e.status,200<=e.status&&e.status<300?(n._response=e.responseText,n.trigger("load")):500<=e.status&&e.status<600?(n._response=e.responseText,n.trigger("error","server")):n.trigger("error",n._status?"http":"abort")},n._xhr=e},_setRequestHeader:function(n,e){c.each(e,function(e,t){n.setRequestHeader(e,t)})},_parseJson:function(e){var t;try{t=JSON.parse(e)}catch(e){t={}}return t}})}),t("webuploader",["base","widgets/filepicker","widgets/image","widgets/queue","widgets/runtime","widgets/upload","runtime/html5/blob","runtime/html5/filepicker","runtime/html5/imagemeta/exif","runtime/html5/image","runtime/html5/androidpatch","runtime/html5/transport"],function(e){return e}),i("webuploader"));!function(e){var t,n,i,r,o,a;for(t in a=function(e){return e&&e.charAt(0).toUpperCase()+e.substr(1)},s)if(n=e,s.hasOwnProperty(t)){for(o=a((i=t.split("/")).pop());r=a(i.shift());)n[r]=n[r]||{},n=n[r];n[o]=s[t]}}(u),"object"==typeof module&&"object"==typeof module.exports?module.exports=u:"function"==typeof define&&define.amd?define([],u):(e=n.WebUploader,n.WebUploader=u,n.WebUploader.noConflict=function(){n.WebUploader=e})}(this);