uploadcare-widget
Version:
Uploadcare Widget: file uploader.
14 lines (13 loc) • 68.5 kB
JavaScript
/**
* uploadcare-widget 3.9.1
* Date: 2020-04-13
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("jquery")):"function"==typeof define&&define.amd?define(["jquery"],t):(e=e||self).uploadcare=t(e.$)}(this,(function(e){"use strict";function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function o(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function s(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");var n,i;e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&(n=e,i=t,(Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(n,i))}function c(e){return(c=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function f(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function p(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?f(e):t}function h(e,t,n){return(h="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,n){var i=function(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=c(e)););return e}(e,t);if(i){var r=Object.getOwnPropertyDescriptor(i,t);return r.get?r.get.call(n):r.value}})(e,t,n||e)}function d(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)){var n=[],i=!0,r=!1,o=void 0;try{for(var a,s=e[Symbol.iterator]();!(i=(a=s.next()).done)&&(n.push(a.value),!t||n.length!==t);i=!0);}catch(e){r=!0,o=e}finally{try{i||null==s.return||s.return()}finally{if(r)throw o}}return n}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function g(e){return function(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t<e.length;t++)n[t]=e[t];return n}}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}e=e&&e.hasOwnProperty("default")?e.default:e;var m=function(){return"object"===("undefined"==typeof window?"undefined":t(window))},_=Object.freeze({__proto__:null,isWindowDefined:m});m()&&window.XDomainRequest&&e.ajaxTransport((function(e){var t;if(e.crossDomain&&e.async)return e.timeout&&(e.xdrTimeout=e.timeout,delete e.timeout),{send:function(n,i){function r(e,n,r,o){t.onload=t.onerror=t.ontimeout=function(){},t=void 0,i(e,n,r,o)}(t=new XDomainRequest).onload=function(){r(200,"OK",{text:t.responseText},"Content-Type: "+t.contentType)},t.onerror=function(){r(404,"Not Found")},t.onprogress=function(){},t.ontimeout=function(){r(0,"timeout")},t.timeout=e.xdrTimeout||Number.MAX_VALUE,t.open(e.type,e.url.replace(/^https?:/,"")),t.send(e.hasContent&&e.data||null)},abort:function(){t&&(t.onerror=function(){},t.abort())}}}));var v,y=m()&&!!(window.File&&window.FileList&&window.FileReader),b=m()&&!(!window.FormData||!y),w=m()&&("draggable"in(v=document.createElement("div"))||"ondragstart"in v&&"ondrop"in v),k=m()&&function(){var e;return!(!(e=document.createElement("canvas")).getContext||!e.getContext("2d"))}(),x=y&&w,S=null,A=m()&&/^[^(]+\(iP(?:hone|od|ad);\s*(.+?)\)/.exec(navigator.userAgent);if(A){var C=/OS (\d)_(\d)/.exec(A[1]);C&&(S=+C[1]+C[2]/10)}var U=!1;try{m()&&new window.Blob&&(U=window.Blob)}catch(e){}var T,O,P,D,j,I,E,z,R,F,L,M,N,B,W,K,G,q,X,J=m()&&(window.URL||window.webkitURL||!1),V=J&&J.createObjectURL&&J,Y=m()&&(null!=window.FileReader?window.FileReader.prototype.readAsArrayBuffer:void 0)&&window.FileReader,$=function(){var e;try{var t;return null!=(e=window.console)&&"function"==typeof e.log?(t=e).log.apply(t,arguments):void 0}catch(e){}},H=function(){var e;if(null==(e=window.console)||!e.debug)return $.apply(void 0,["Debug:"].concat(Array.prototype.slice.call(arguments)));try{var t;return(t=window.console).debug.apply(t,arguments)}catch(e){}},Q=function(){var e;if(null==(e=window.console)||!e.warn)return $.apply(void 0,["Warning:"].concat(Array.prototype.slice.call(arguments)));try{var t;return(t=window.console).warn.apply(t,arguments)}catch(e){}},Z={},ee=function(e){if(null==Z[e])return Z[e]=!0,Q(e)},te=[].indexOf,ne=function(e){var t,n,i,r;for(r=[],n=0,i=e.length;n<i;n++)t=e[n],te.call(r,t)<0&&r.push(t);return r},ie=function(e){return setTimeout(e,0)},re=function(e){var t,n;return t=!1,n=null,function(){return t||(n=e.apply(this,arguments),t=!0),n}},oe=function(t){return e.Deferred().resolve(t).promise()},ae=function(t,n){var i;return i={},e.each(n,(function(n,r){var o=t[r];e.isFunction(o)?i[r]=function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];var a=o.apply(t,n);return a===t?i:a}:i[r]=o})),i},se=function(e){return e.replace(/([A-Z])/g,"_$1").toUpperCase()},ue=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)}))},ce=/^(?:([^:/?#]+):)?(?:\/\/([^/?#]*))?([^?#]*)\??([^#]*)#?(.*)$/,le=/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/i,fe=new RegExp("".concat(le.source,"~[0-9]+"),"i"),pe=new RegExp("^/?(".concat(le.source,")(?:/(-/(?:[^/]+/)+)?([^/]*))?$"),"i"),he=function(e){return pe.exec(ce.exec(e)[3])},de=function(e){return e.replace(/[\\-\\[]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},ge=function(e){var t;return"http:"!==(t=document.location.protocol)&&(t="https:"),e.replace(/^\/\//,t+"//").replace(/\/+$/,"")},me=function(e,t,n){var i,r;return e[0]>t[0]||e[1]>t[1]||n?(r=t[0]/e[0],i=t[1]/e[1],!t[0]||t[1]&&r>i?[Math.round(i*e[0]),t[1]]:[t[0],Math.round(r*e[1])]):e.slice()},_e="B KB MB GB TB PB EB ZB YB".split(" "),ve={dataType:"json",crossDomain:!0,cache:!1},ye=function(t,n,i){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};return e.ajax(e.extend({url:t,type:n,data:i},r,ve)).then((function(t){var n;return t.error?(n=t.error.content||t.error,e.Deferred().reject(n)):t}),(function(e,n,i){var r;return r="".concat(n," (").concat(i,")"),Q("JSONP unexpected error: ".concat(r," while loading ").concat(t)),r}))},be=function(e,t,n,i){var r,o,a,s,u,c;if(window.HTMLCanvasElement.prototype.toBlob)return e.toBlob(i,t,n);for(a=(a=e.toDataURL(t,n)).split(","),o=window.atob(a[1]),r=new Uint8Array(o.length),s=u=0,c=o.length;u<c;s=u+=1)r[s]=o.charCodeAt(s);return i(new window.Blob([r],{type:/:(.+\/.+);/.exec(a[0])[1]}))},we=function(e){var t,n,i;return i=0,t=[],n=function(){var e;return t.length?(e=t.shift(),ie((function(){return e(n)}))):i-=1},function(r){return!e||i<e?(i+=1,ie((function(){return r(n)}))):t.push(r)}},ke=[["notify","progress",2],["resolve","done",0],["reject","fail",1]],xe=function(t){for(var n=arguments.length,i=new Array(n>1?n-1:0),r=1;r<n;r++)i[r-1]=arguments[r];return e.Deferred((function(n){return e.each(ke,(function(r,o){var a;return a=e.isFunction(i[o[2]])&&i[o[2]],t[o[1]]((function(){var i;return(i=a&&a.apply(this,arguments))&&e.isFunction(i.promise)?i.promise().progress(n.notify).done(n.resolve).fail(n.reject):n[o[0]+"With"](this===t?n.promise():this,a?[i]:arguments)}))}))})).promise()},Se=[].indexOf;j={live:!0,manualStart:!1,locale:null,localePluralize:null,localeTranslations:null,systemDialog:!1,crop:!1,previewStep:!1,imagesOnly:!1,clearable:!1,multiple:!1,multipleMax:1e3,multipleMin:1,multipleMaxStrict:!1,imageShrink:!1,pathValue:!0,tabs:"file camera url facebook gdrive gphotos dropbox instagram evernote flickr onedrive",preferredTypes:"",inputAcceptTypes:"",doNotStore:!1,publicKey:null,secureSignature:"",secureExpire:"",pusherKey:"79ae88bd931ea68464d9",cdnBase:"https://ucarecdn.com",urlBase:"https://upload.uploadcare.com",socialBase:"https://social.uploadcare.com",previewProxy:null,previewUrlCallback:null,imagePreviewMaxSize:26214400,multipartMinSize:10485760,multipartPartSize:5242880,multipartMinLastPartSize:1048576,multipartConcurrency:4,multipartMaxAttempts:3,parallelDirectUploads:10,passWindowOpen:!1,videoPreferredMimeTypes:null,audioBitsPerSecond:null,videoBitsPerSecond:null,scriptBase:"//ucarecdn.com/widget/".concat("3.9.1","/uploadcare/"),debugUploads:!1,integration:""},G={multipleMax:{from:0,to:1e3}},P={multipleMax:{min:1,max:1e3}},N={tabs:{all:"file camera url facebook gdrive gphotos dropbox instagram evernote flickr onedrive box vk huddle",default:j.tabs}},B=m()&&(document.currentScript||(X=document.getElementsByTagName("script"))[X.length-1]),(z=m()&&e(B).data("integration"))&&null!=z&&(j=e.extend(j,{integration:z})),W=function(t){return e.isArray(t)||(t=(t=e.trim(t))?t.split(" "):[]),t},T=function(e,t){var n,i,r,o,a,s,u,c,l=Object.prototype.hasOwnProperty;for(n=0,a=t.length;n<a;n++){if(o=t[n],c=u=W(e[o]),l.apply(N,[o]))for(c=[],r=0,s=u.length;r<s;r++)i=u[r],l.apply(N[o],[i])?c=c.concat(W(N[o][i])):c.push(i);e[o]=ne(c)}return e},q=function(e,t){var n,i,r;for(n=0,r=t.length;n<r;n++)null!=e[i=t[n]]&&(e[i]=ge(e[i]));return e},I=function(t,n){var i,r,o,a;for(i=0,o=n.length;i<o;i++)null!=t[r=n[i]]&&("string"==typeof(a=t[r])?(a=e.trim(a).toLowerCase(),t[r]=!("false"===a||"disabled"===a)):t[r]=!!a);return t},E=function(e,t){var n,i,r;for(n=0,r=t.length;n<r;n++)null!=e[i=t[n]]&&(e[i]=parseInt(e[i]));return e},R=function(e){return e._userAgent="UploadcareWidget/".concat("3.9.1","/").concat(e.publicKey," (JavaScript").concat(e.integration?"; ".concat(e.integration):"",")"),e},K=function(e,t){var n,i;for(n in t)i=t[n],null!=e[n]&&e[n]===i.from&&(e[n]=i.to);return e},O=function(e,t){var n,i,r;for(n in t){var o=t[n];r=o.min,i=o.max,null!=e[n]&&(e[n]=Math.min(Math.max(e[n],r),i))}return e},L=function(t){var n;return{downscale:"x"===(n=/^([0-9]+)([x:])([0-9]+)\s*(|upscale|minimum)$/i.exec(e.trim(t.toLowerCase()))||[])[2],upscale:!!n[4],notLess:"minimum"===n[4],preferedSize:n.length?[+n[1],+n[3]]:void 0}},M=function(t){var n,i;return!!(n=/^([0-9]+)x([0-9]+)(?:\s+(\d{1,2}|100)%)?$/i.exec(e.trim(t.toLowerCase()))||[]).length&&((i=n[1]*n[2])>5e6?(ee("Shrinked size can not be larger than 5MP. "+"You have set ".concat(n[1],"x").concat(n[2]," (")+"".concat(Math.ceil(i/1e3/100)/10,"MP).")),!1):{quality:n[3]?n[3]/100:void 0,size:i})},D=function(e,t){var n,i,r,o;return this.previewProxy?(i=(r=!/\?/.test(this.previewProxy))||!/=$/.test(this.previewProxy),n=!r&&!/[&?=]$/.test(this.previewProxy),o=encodeURIComponent(e),i&&(o="url="+o),n&&(o="&"+o),r&&(o="?"+o),this.previewProxy+o):e},F=function(t){var n;return T(t,["tabs","preferredTypes","videoPreferredMimeTypes"]),q(t,["cdnBase","socialBase","urlBase","scriptBase"]),I(t,["doNotStore","imagesOnly","multiple","clearable","pathValue","previewStep","systemDialog","debugUploads","multipleMaxStrict"]),E(t,["multipleMax","multipleMin","multipartMinSize","multipartPartSize","multipartMinLastPartSize","multipartConcurrency","multipartMaxAttempts","parallelDirectUploads"]),K(t,G),O(t,P),R(t),!1===t.crop||e.isArray(t.crop)||(/^(disabled?|false|null)$/i.test(t.crop)?t.crop=!1:e.isPlainObject(t.crop)?t.crop=[t.crop]:t.crop=e.map((""+t.crop).split(","),L)),t.imageShrink&&!e.isPlainObject(t.imageShrink)&&(t.imageShrink=M(t.imageShrink)),(t.crop||t.multiple)&&(t.previewStep=!0),b||(t.systemDialog=!1),t.validators&&(t.validators=t.validators.slice()),t.previewProxy&&!t.previewUrlCallback&&(t.previewUrlCallback=D),-1!==(n=t.tabs.indexOf("skydrive"))&&(t.tabs[n]="onedrive"),t};var Ae=function(){var e,t,n;for(e in t={},j)null!=(n=window["UPLOADCARE_".concat(se(e))])&&(t[e]=n);return t},Ce=re((function(t,n){var i;return n||(j=e.extend(j,Ae())),i=F(e.extend(j,t||{})),Te.fire(i),i})),Ue=function(t){var n;return n=e.extend({},Ce()),e.isEmptyObject(t)||(n=F(e.extend(n,t))),n},Te=m()&&e.Callbacks("once memory"),Oe=function(){function e(){n(this,e),this.urls=[],this.styles=[]}return o(e,[{key:"addUrl",value:function(e){if(!/^https?:\/\//i.test(e))throw new Error("Embedded urls should be absolute. "+e);if(!(Se.call(this.urls,e)>=0))return this.urls.push(e)}},{key:"addStyle",value:function(e){return this.styles.push(e)}}]),e}(),Pe=function(t,n){var i;return i=e.Deferred(),n&&(t.src=n),t.complete?i.resolve(t):(e(t).one("load",(function(){return i.resolve(t)})),e(t).one("error",(function(){return i.reject(t)}))),i.promise()},De=function t(n){return e.isArray(n)?e.when.apply(null,e.map(n,t)):n.src?Pe(n):Pe(new window.Image,n)},je=m()&&window.DataView,Ie=we(1),Ee=function(t,n){var i;return i=e.Deferred(),V&&je&&U?(Ie((function(e){var r;return i.always(e),(r=De(V.createObjectURL(t))).always((function(e){return V.revokeObjectURL(e.src)})),r.fail((function(){return i.reject("not image")})),r.done((function(e){i.notify(.1);var o=Le(t).always((function(t){var a;return i.notify(.2),a="resolved"===o.state(),(r=ze(e,n)).progress((function(e){return i.notify(.2+.6*e)})),r.fail(i.reject),r.done((function(e){var o,s;return o="image/jpeg",s=n.quality||.8,!a&&Ne(e)&&(o="image/png",s=void 0),be(e,o,s,(function(n){return e.width=e.height=1,i.notify(.9),t?((r=Fe(n,225,[t.buffer])).done(i.resolve),r.fail((function(){return i.resolve(n)}))):i.resolve(n)}))})),null}));return o}))})),i.promise()):i.reject("support")},ze=function(t,n){var i,r,o,a,s,u,c,l,f;return i=e.Deferred(),.71*t.width*t.height*.71<n.size?i.reject("not required"):(l=o=t.width,c=t.height,a=l/c,f=Math.floor(Math.sqrt(n.size*a)),r=Math.floor(n.size/Math.sqrt(n.size*a)),s=function(){if(!(l<=f))return ie((function(){var e;return l=Math.round(.71*l),c=Math.round(.71*c),.71*l<f&&(l=f,c=r),l*c>5e6&&(l=Math.floor(Math.sqrt(5e6*a)),c=Math.floor(5e6/Math.sqrt(5e6*a))),l>4096&&(l=4096,c=Math.round(l/a)),c>4096&&(c=4096,l=Math.round(a*c)),(e=document.createElement("canvas")).width=l,e.height=c,e.getContext("2d").drawImage(t,0,0,l,c),t.src="//:0",t.width=t.height=1,t=e,i.notify((o-l)/(o-f)),s()}));i.resolve(t)},u=function(){var e,n;return(e=document.createElement("canvas")).width=f,e.height=r,(n=e.getContext("2d")).imageSmoothingQuality="high",n.drawImage(t,0,0,f,r),t.src="//:0",t.width=t.height=1,i.resolve(e)},"imageSmoothingQuality"in document.createElement("canvas").getContext("2d")?u():s(),i.promise())},Re=function(t){var n,i,r,o,a;return a=function(e,t){var i;return(i=new Y).onload=function(){return t(new je(i.result))},i.onerror=function(e){return n.reject("reader",e)},i.readAsArrayBuffer(e)},r=function(){return a(t.slice(i,i+128),(function(e){var t,n,r;for(t=n=0,r=e.byteLength;r>=0?n<r:n>r;t=r>=0?++n:--n)if(255===e.getUint8(t)){i+=t;break}return o()}))},o=function(){var e;return e=i,a(t.slice(i,i+=4),(function(o){var s,u;return 4!==o.byteLength||255!==o.getUint8(0)?n.reject("corrupted"):218===(u=o.getUint8(1))?n.resolve():(s=o.getUint16(2)-2,a(t.slice(i,i+=s),(function(t){return t.byteLength!==s?n.reject("corrupted"):(n.notify(e,s,u,t),r())})))}))},n=e.Deferred(),Y&&je?(i=2,a(t.slice(0,2),(function(e){return 65496!==e.getUint16(0)?n.reject("not jpeg"):r()})),n.promise()):n.reject("support")},Fe=function(t,n,i){var r,o,a,s;return r=e.Deferred(),a=[],o=[],(s=Re(t)).fail(r.reject),s.progress((function(e,t,i){if(i===n)return a.push(e),o.push(t)})),s.done((function(){var e,s,u,c,l,f,p,h,d;for(p=[t.slice(0,2)],c=0,f=i.length;c<f;c++)e=i[c],(u=new je(new ArrayBuffer(4))).setUint16(0,65280+n),u.setUint16(2,e.byteLength+2),p.push(u.buffer),p.push(e);for(h=2,s=l=0,d=a.length;d>=0?l<d:l>d;s=d>=0?++l:--l)a[s]>h&&p.push(t.slice(h,a[s])),h=a[s]+o[s]+4;return p.push(t.slice(h,t.size)),r.resolve(new U(p,{type:t.type}))})),r.promise()},Le=function(t){var n,i;return n=null,(i=Re(t)).progress((function(e,t,i,r){if(!n&&225===i&&r.byteLength>=14&&1165519206===r.getUint32(0)&&0===r.getUint16(4))return n=r})),i.then((function(){return n}),(function(t){return e.Deferred().reject(n,t)}))},Me=function(e){var t,n,i,r;if(!e||e.byteLength<14||1165519206!==e.getUint32(0)||0!==e.getUint16(4))return null;if(18761===e.getUint16(6))n=!0;else{if(19789!==e.getUint16(6))return null;n=!1}if(42!==e.getUint16(8,n))return null;for(i=8+e.getUint32(10,n),t=0,r=e.getUint16(i-2,n);r>=0?t<r:t>r;r>=0?++t:--t){if(e.byteLength<i+10)return null;if(274===e.getUint16(i,n))return e.getUint16(i+8,n);i+=12}return null},Ne=function(e){var t,n,i,r,o,a;for((t=document.createElement("canvas")).width=t.height=50,(n=t.getContext("2d")).drawImage(e,0,0,50,50),i=n.getImageData(0,0,50,50).data,t.width=t.height=1,r=o=3,a=i.length;o<a;r=o+=4)if(i[r]<254)return!0;return!1},Be=function(){function t(e,i){var r,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};n(this,t),this.settings=i,this.sourceInfo=o,this.fileId=null,this.fileName=null,this.sanitizedName=null,this.fileSize=null,this.isStored=null,this.cdnUrlModifiers=null,this.isImage=null,this.imageInfo=null,this.mimeType=null,this.s3Bucket=null,(r=this.sourceInfo).source||(r.source=this.sourceName),this.__setupValidation(),this.__initApi()}return o(t,[{key:"__startUpload",value:function(){return e.Deferred().resolve()}},{key:"__completeUpload",value:function(){var e,t,n,i,r=this;return n=0,this.settings.debugUploads&&(H("Load file info.",this.fileId,this.settings.publicKey),t=setInterval((function(){return H("Still waiting for file ready.",n,r.fileId,r.settings.publicKey)}),5e3),this.apiDeferred.done((function(){return H("File uploaded.",n,r.fileId,r.settings.publicKey)})).always((function(){return clearInterval(t)}))),i=100,(e=function(){if("pending"===r.apiDeferred.state())return n+=1,r.__updateInfo().done((function(){return setTimeout(e,i),i+=50}))})()}},{key:"__updateInfo",value:function(){var e=this;return ye("".concat(this.settings.urlBase,"/info/"),"GET",{jsonerrors:1,file_id:this.fileId,pub_key:this.settings.publicKey,wait_is_ready:+(null===this.isImage)},{headers:{"X-UC-User-Agent":this.settings._userAgent}}).fail((function(t){return e.settings.debugUploads&&$("Can't load file info. Probably removed.",e.fileId,e.settings.publicKey,t),e.__rejectApi("info")})).done(this.__handleFileData.bind(this))}},{key:"__handleFileData",value:function(e){if(this.fileName=e.original_filename,this.sanitizedName=e.filename,this.fileSize=e.size,this.isImage=e.is_image,this.imageInfo=e.image_info,this.mimeType=e.mime_type,this.isStored=e.is_stored,this.s3Bucket=e.s3_bucket,e.default_effects&&(this.cdnUrlModifiers="-/"+e.default_effects),this.s3Bucket&&this.cdnUrlModifiers&&this.__rejectApi("baddata"),this.__runValidators(),e.is_ready)return this.__resolveApi()}},{key:"__progressInfo",value:function(){var e;return{state:this.__progressState,uploadProgress:this.__progress,progress:"ready"===(e=this.__progressState)||"error"===e?1:.9*this.__progress,incompleteFileInfo:this.__fileInfo()}}},{key:"__fileInfo",value:function(){var e;return e=this.s3Bucket?"https://".concat(this.s3Bucket,".s3.amazonaws.com/").concat(this.fileId,"/").concat(this.sanitizedName):"".concat(this.settings.cdnBase,"/").concat(this.fileId,"/"),{uuid:this.fileId,name:this.fileName,size:this.fileSize,isStored:this.isStored,isImage:!this.s3Bucket&&this.isImage,originalImageInfo:this.imageInfo,mimeType:this.mimeType,originalUrl:this.fileId?e:null,cdnUrl:this.fileId?"".concat(e).concat(this.cdnUrlModifiers||""):null,cdnUrlModifiers:this.cdnUrlModifiers,sourceInfo:this.sourceInfo}}},{key:"__setupValidation",value:function(){if(this.validators=this.settings.validators||this.settings.__validators||[],this.settings.imagesOnly)return this.validators.push((function(e){if(!1===e.isImage)throw new Error("image")}))}},{key:"__runValidators",value:function(){var e,t,n,i,r,o,a;n=this.__fileInfo();try{for(r=this.validators,o=[],t=0,i=r.length;t<i;t++)a=r[t],o.push(a(n));return o}catch(t){return e=t,this.__rejectApi(e.message)}}},{key:"__initApi",value:function(){return this.apiDeferred=e.Deferred(),this.__progressState="uploading",this.__progress=0,this.__notifyApi()}},{key:"__notifyApi",value:function(){return this.apiDeferred.notify(this.__progressInfo())}},{key:"__rejectApi",value:function(e){return this.__progressState="error",this.__notifyApi(),this.apiDeferred.reject(e,this.__fileInfo())}},{key:"__resolveApi",value:function(){return this.__progressState="ready",this.__notifyApi(),this.apiDeferred.resolve(this.__fileInfo())}},{key:"__cancel",value:function(){return this.__rejectApi("user")}},{key:"__extendApi",value:function(e){var t=this;return e.cancel=this.__cancel.bind(this),e.pipe=e.then=function(){for(var n=arguments.length,i=new Array(n),r=0;r<n;r++)i[r]=arguments[r];return t.__extendApi(xe.apply(void 0,[e].concat(i)))},e}},{key:"promise",value:function(){var e,t=this;return this.__apiPromise||(this.__apiPromise=this.__extendApi(this.apiDeferred.promise()),this.__runValidators(),"pending"===this.apiDeferred.state()&&((e=this.__startUpload()).done((function(){return t.__progressState="uploaded",t.__progress=1,t.__notifyApi(),t.__completeUpload()})),e.progress((function(e){if(e>t.__progress)return t.__progress=e,t.__notifyApi()})),e.fail((function(){return t.__rejectApi("upload")})),this.apiDeferred.always(e.reject))),this.__apiPromise}}]),t}(),We=null,Ke=function(t){function i(e){var t;return n(this,i),(t=p(this,c(i).apply(this,arguments))).__file=e,t.fileName=t.__file.name||"original",t.__notifyApi(),t}return u(i,t),o(i,[{key:"setFile",value:function(e){if(e&&(this.__file=e),this.sourceInfo.file=this.__file,this.__file)return this.fileSize=this.__file.size,this.fileType=this.__file.type||"application/octet-stream",this.settings.debugUploads&&H("Use local file.",this.fileName,this.fileType,this.fileSize),this.__runValidators(),this.__notifyApi()}},{key:"__startUpload",value:function(){var t,n,i,r=this;return this.apiDeferred.always((function(){return r.__file=null,r.__file})),this.__file.size>=this.settings.multipartMinSize&&U?(this.setFile(),this.multipartUpload()):(n=S,!this.settings.imageShrink||n&&n<8?(this.setFile(),this.directUpload()):(t=e.Deferred(),i=.4,Ee(this.__file,this.settings.imageShrink).progress((function(e){return t.notify(e*i)})).done(this.setFile.bind(this)).fail((function(){return r.setFile(),i*=.1})).always((function(){return t.notify(i),r.directUpload().done(t.resolve).fail(t.reject).progress((function(e){return t.notify(i+e*(1-i))}))})),t))}},{key:"__autoAbort",value:function(e){return this.apiDeferred.fail(e.abort),e}},{key:"directRunner",value:function(e){return We||(We=we(this.settings.parallelDirectUploads)),We(e)}},{key:"directUpload",value:function(){var t,n=this;return t=e.Deferred(),this.__file?this.fileSize>104857600?(this.__rejectApi("size"),t):(this.directRunner((function(i){var r;if(t.always(i),"pending"===n.apiDeferred.state())return(r=new window.FormData).append("UPLOADCARE_PUB_KEY",n.settings.publicKey),r.append("signature",n.settings.secureSignature),r.append("expire",n.settings.secureExpire),r.append("UPLOADCARE_STORE",n.settings.doNotStore?"":"auto"),r.append("file",n.__file,n.fileName),r.append("file_name",n.fileName),r.append("source",n.sourceInfo.source),n.__autoAbort(e.ajax({xhr:function(){var n;return(n=e.ajaxSettings.xhr()).upload&&n.upload.addEventListener("progress",(function(e){return t.notify(e.loaded/e.total)}),!1),n},crossDomain:!0,type:"POST",url:"".concat(n.settings.urlBase,"/base/?jsonerrors=1"),headers:{"X-UC-User-Agent":n.settings._userAgent},contentType:!1,processData:!1,data:r,dataType:"json",error:t.reject,success:function(e){return(null!=e?e.file:void 0)?(n.fileId=e.file,t.resolve()):t.reject()}}))})),t):(this.__rejectApi("baddata"),t)}},{key:"multipartUpload",value:function(){var t,n=this;return t=e.Deferred(),this.__file?(this.multipartStart().done((function(e){return n.uploadParts(e.parts,e.uuid).done((function(){return n.multipartComplete(e.uuid).done((function(e){return n.fileId=e.uuid,n.__handleFileData(e),t.resolve()})).fail(t.reject)})).progress(t.notify).fail(t.reject)})).fail(t.reject),t):t}},{key:"multipartStart",value:function(){var e,t=this;return e={UPLOADCARE_PUB_KEY:this.settings.publicKey,signature:this.settings.secureSignature,expire:this.settings.secureExpire,filename:this.fileName,source:this.sourceInfo.source,size:this.fileSize,content_type:this.fileType,part_size:this.settings.multipartPartSize,UPLOADCARE_STORE:this.settings.doNotStore?"":"auto"},this.__autoAbort(ye("".concat(this.settings.urlBase,"/multipart/start/?jsonerrors=1"),"POST",e,{headers:{"X-UC-User-Agent":this.settings._userAgent}})).fail((function(n){if(t.settings.debugUploads)return $("Can't start multipart upload.",n,e)}))}},{key:"uploadParts",value:function(t,n){var i,r,o,a,s,u,c,l,f,p,h=this;for(s=[],a=Date.now(),p=function(e,t){var n,r,o;if(s[e]=t,!(Date.now()-a<250)){for(a=Date.now(),o=0,n=0,r=s.length;n<r;n++)o+=t=s[n];return i.notify(o/h.fileSize)}},i=e.Deferred(),r=0,f=0,l=0,c=function(){var o,a,u,d,g;if(!(l>=h.fileSize))return u=l+h.settings.multipartPartSize,h.fileSize<u+h.settings.multipartMinLastPartSize&&(u=h.fileSize),a=h.__file.slice(l,u),l=u,d=f,r+=1,f+=1,o=0,(g=function(){if("pending"===h.apiDeferred.state())return s[d]=0,h.__autoAbort(e.ajax({xhr:function(){var t;return(t=e.ajaxSettings.xhr()).responseType="text",t.upload&&t.upload.addEventListener("progress",(function(e){return p(d,e.loaded)}),!1),t},url:t[d],crossDomain:!0,type:"PUT",processData:!1,contentType:h.fileType,data:a,error:function(){return(o+=1)>h.settings.multipartMaxAttempts?(h.settings.debugUploads&&$("Part #".concat(d," and file upload is failed."),n),i.reject()):(h.settings.debugUploads&&H("Part #".concat(d,"(").concat(o,") upload is failed."),n),g())},success:function(){if(r-=1,c(),!r)return i.resolve()}}))})()},o=0,u=this.settings.multipartConcurrency;u>=0?o<u:o>u;u>=0?++o:--o)c();return i}},{key:"multipartComplete",value:function(e){var t,n=this;return t={UPLOADCARE_PUB_KEY:this.settings.publicKey,uuid:e},this.__autoAbort(ye("".concat(this.settings.urlBase,"/multipart/complete/?jsonerrors=1"),"POST",t,{headers:{"X-UC-User-Agent":this.settings._userAgent}})).fail((function(t){if(n.settings.debugUploads)return $("Can't complete multipart upload.",e,n.settings.publicKey,t)}))}}]),i}(Be);Ke.prototype.sourceName="local";var Ge=function(t){function i(t){var r;return n(this,i),(r=p(this,c(i).apply(this,arguments))).__input=t,r.fileId=ue(),r.fileName=e(r.__input).val().split("\\").pop(),r.__notifyApi(),r}return u(i,t),o(i,[{key:"__startUpload",value:function(){var t,n,i,r;return t=e.Deferred(),r="".concat(this.settings.urlBase,"/iframe/"),i="uploadcare--iframe-".concat(this.fileId),this.__iframe=e("<iframe>").attr({id:i,name:i}).css("display","none").appendTo("body").on("load",t.resolve).on("error",t.reject),n=function(t,n){return e("<input/>",{type:"hidden",name:t,value:n})},e(this.__input).attr("name","file"),this.__iframeForm=e("<form>").attr({method:"POST",action:r,enctype:"multipart/form-data",target:i}).append(n("UPLOADCARE_PUB_KEY",this.settings.publicKey)).append(n("UPLOADCARE_SIGNATURE",this.settings.secureSignature)).append(n("UPLOADCARE_EXPIRE",this.settings.secureExpire)).append(n("UPLOADCARE_FILE_ID",this.fileId)).append(n("UPLOADCARE_STORE",this.settings.doNotStore?"":"auto")).append(n("UPLOADCARE_SOURCE",this.sourceInfo.source)).append(this.__input).css("display","none").appendTo("body").submit(),t.always(this.__cleanUp.bind(this))}},{key:"__cleanUp",value:function(){var e,t;return null!=(e=this.__iframe)&&e.off("load error").remove(),null!=(t=this.__iframeForm)&&t.remove(),this.__iframe=null,this.__iframeForm=null,this.__iframeForm}}]),i}(Be);Ge.prototype.sourceName="local-compat";var qe=function(e,t){return function(e,t){
/*!
* Pusher JavaScript Library v1.12.2
* http://pusherapp.com/
*
* Copyright 2011, Pusher
* Released under the MIT licence.
*/
var n=_.isWindowDefined;(function(){var e,t;(e=function(t,n){this.options=n||{},this.key=t,this.channels=new e.Channels,this.global_emitter=new e.EventsDispatcher;var i=this;this.checkAppKey(),this.connection=new e.Connection(this.key,this.options),this.connection.bind("connected",(function(){i.subscribeAll()})).bind("message",(function(e){var t,n=0===e.event.indexOf("pusher_internal:");e.channel&&(t=i.channel(e.channel))&&t.emit(e.event,e.data),n||i.global_emitter.emit(e.event,e.data)})).bind("disconnected",(function(){i.channels.disconnect()})).bind("error",(function(t){e.warn("Error",t)})),e.instances.push(this),e.isReady&&i.connect()}).instances=[],e.prototype={channel:function(e){return this.channels.find(e)},connect:function(){this.connection.connect()},disconnect:function(){this.connection.disconnect()},bind:function(e,t){return this.global_emitter.bind(e,t),this},bind_all:function(e){return this.global_emitter.bind_all(e),this},subscribeAll:function(){var e;for(e in this.channels.channels)this.channels.channels.hasOwnProperty(e)&&this.subscribe(e)},subscribe:function(e){var t=this,n=this.channels.add(e,this);return"connected"===this.connection.state&&n.authorize(this.connection.socket_id,this.options,(function(i,r){i?n.emit("pusher:subscription_error",r):t.send_event("pusher:subscribe",{channel:e,auth:r.auth,channel_data:r.channel_data})})),n},unsubscribe:function(e){this.channels.remove(e),"connected"===this.connection.state&&this.send_event("pusher:unsubscribe",{channel:e})},send_event:function(e,t,n){return this.connection.send_event(e,t,n)},checkAppKey:function(){null!==this.key&&void 0!==this.key||e.warn("Warning","You must pass your app key when you instantiate Pusher.")}},e.Util={extend:function e(t,n){for(var i in n)n[i]&&n[i].constructor&&n[i].constructor===Object?t[i]=e(t[i]||{},n[i]):t[i]=n[i];return t},stringify:function(){for(var e=["Pusher"],t=0;t<arguments.length;t++)"string"==typeof arguments[t]?e.push(arguments[t]):null==window.JSON?e.push(arguments[t].toString()):e.push(JSON.stringify(arguments[t]));return e.join(" : ")},arrayIndexOf:function(e,t){var n=Array.prototype.indexOf;if(null==e)return-1;if(n&&e.indexOf===n)return e.indexOf(t);for(i=0,l=e.length;i<l;i++)if(e[i]===t)return i;return-1}},e.debug=function(){e.log&&e.log(e.Util.stringify.apply(this,arguments))},e.warn=function(){if(window.console&&window.console.warn)window.console.warn(e.Util.stringify.apply(this,arguments));else{if(!e.log)return;e.log(e.Util.stringify.apply(this,arguments))}},e.VERSION="1.12.2",e.host="ws.pusherapp.com",e.ws_port=80,e.wss_port=443,e.channel_auth_endpoint="/pusher/auth",e.cdn_http="http://js.pusher.com/",e.cdn_https="https://d3dy5gmtp8yhk7.cloudfront.net/",e.dependency_suffix=".min",e.channel_auth_transport="ajax",e.activity_timeout=12e4,e.pong_timeout=3e4,e.isReady=!1,e.ready=function(){e.isReady=!0;for(var t=0,n=e.instances.length;t<n;t++)e.instances[t].connect()},function(){function t(){this._callbacks={}}function n(e){this.callbacks=new t,this.global_callbacks=[],this.failThrough=e}t.prototype.get=function(e){return this._callbacks[this._prefix(e)]},t.prototype.add=function(e,t){var n=this._prefix(e);this._callbacks[n]=this._callbacks[n]||[],this._callbacks[n].push(t)},t.prototype.remove=function(t,n){if(this.get(t)){var i=e.Util.arrayIndexOf(this.get(t),n);this._callbacks[this._prefix(t)].splice(i,1)}},t.prototype._prefix=function(e){return"_"+e},n.prototype.bind=function(e,t){return this.callbacks.add(e,t),this},n.prototype.unbind=function(e,t){return this.callbacks.remove(e,t),this},n.prototype.emit=function(e,t){for(var n=0;n<this.global_callbacks.length;n++)this.global_callbacks[n](e,t);var i=this.callbacks.get(e);if(i)for(n=0;n<i.length;n++)i[n](t);else this.failThrough&&this.failThrough(e,t);return this},n.prototype.bind_all=function(e){return this.global_callbacks.push(e),this},e.EventsDispatcher=n}(),function(){function t(e,t,n){void 0!==t[e]&&t[e](n)}function n(t,n,i){e.EventsDispatcher.call(this),this.state=void 0,this.errors=[],this.stateActions=i,this.transitions=n,this.transition(t)}n.prototype.transition=function(n,i){var r,o=this.state,a=this.stateActions;if(o&&-1==e.Util.arrayIndexOf(this.transitions[o],n))throw this.emit("invalid_transition_attempt",{oldState:o,newState:n}),new Error("Invalid transition ["+o+" to "+n+"]");t(o+"Exit",a,i),t(o+"To"+((r=n).substr(0,1).toUpperCase()+r.substr(1)),a,i),t(n+"Pre",a,i),this.state=n,this.emit("state_change",{oldState:o,newState:n}),t(n+"Post",a,i)},n.prototype.is=function(e){return this.state===e},n.prototype.isNot=function(e){return this.state!==e},e.Util.extend(n.prototype,e.EventsDispatcher.prototype),e.Machine=n}(),(t=function(){var t=this;e.EventsDispatcher.call(this),void 0!==window.addEventListener&&(window.addEventListener("online",(function(){t.emit("online",null)}),!1),window.addEventListener("offline",(function(){t.emit("offline",null)}),!1))}).prototype.isOnLine=function(){return void 0===window.navigator.onLine||window.navigator.onLine},e.Util.extend(t.prototype,e.EventsDispatcher.prototype),e.NetInfo=t,function(){var t={initialized:["waiting","failed"],waiting:["connecting","permanentlyClosed"],connecting:["open","permanentlyClosing","impermanentlyClosing","waiting"],open:["connected","permanentlyClosing","impermanentlyClosing","waiting"],connected:["permanentlyClosing","waiting"],impermanentlyClosing:["waiting","permanentlyClosing"],permanentlyClosing:["permanentlyClosed"],permanentlyClosed:["waiting","failed"],failed:["permanentlyClosed"]};function n(t){t.connectionWait=0,"flash"===e.TransportType?t.openTimeout=5e3:t.openTimeout=2e3,t.connectedTimeout=2e3,t.connectionSecure=t.compulsorySecure,t.connectionAttempts=0}function i(i,r){var o=this;function a(){o.connectionWait<1e4&&(o.connectionWait+=2e3),o.openTimeout<1e4&&(o.openTimeout+=2e3),o.connectedTimeout<1e4&&(o.connectedTimeout+=2e3),!0!==o.compulsorySecure&&(o.connectionSecure=!o.connectionSecure),o.connectionAttempts++}function s(){o._machine.transition("impermanentlyClosing")}function u(){o._activityTimer&&clearTimeout(o._activityTimer),o._activityTimer=setTimeout((function(){o.send_event("pusher:ping",{}),o._activityTimer=setTimeout((function(){o.socket.close()}),o.options.pong_timeout||e.pong_timeout)}),o.options.activity_timeout||e.activity_timeout)}function c(){o._machine.transition("open")}function l(e){var t,n,i=p(e);void 0!==i&&("pusher:connection_established"===i.event?o._machine.transition("connected",i.data.socket_id):"pusher:error"===i.event&&(t=i.data.code,n=i.data.message,o.emit("error",{type:"PusherError",data:{code:t,message:n}}),4e3===t?(o.compulsorySecure=!0,o.connectionSecure=!0,o.options.encrypted=!0,s()):t<4100?o._machine.transition("permanentlyClosing"):t<4200?(o.connectionWait=1e3,o._machine.transition("waiting")):t<4300?s():o._machine.transition("permanentlyClosing")))}function f(t){u();var n=p(t);if(void 0!==n){switch(e.debug("Event recd",n),n.event){case"pusher:error":o.emit("error",{type:"PusherError",data:n.data});break;case"pusher:ping":o.send_event("pusher:pong",{})}o.emit("message",n)}}function p(e){try{var t=JSON.parse(e.data);if("string"==typeof t.data)try{t.data=JSON.parse(t.data)}catch(e){if(!(e instanceof SyntaxError))throw e}return t}catch(t){o.emit("error",{type:"MessageParseError",error:t,data:e.data})}}function h(){o._machine.transition("waiting")}function d(e){o.emit("error",{type:"WebSocketError",error:e})}function g(t,n){var i=o.state;o.state=t,i!==t&&(e.debug("State changed",i+" -> "+t),o.emit("state_change",{previous:i,current:t}),o.emit(t,n))}e.EventsDispatcher.call(this),this.options=e.Util.extend({encrypted:!1},r),this.netInfo=new e.NetInfo,this.netInfo.bind("online",(function(){o._machine.is("waiting")&&(o._machine.transition("connecting"),g("connecting"))})),this.netInfo.bind("offline",(function(){o._machine.is("connected")&&(o.socket.onclose=void 0,o.socket.onmessage=void 0,o.socket.onerror=void 0,o.socket.onopen=void 0,o.socket.close(),o.socket=void 0,o._machine.transition("waiting"))})),this._machine=new e.Machine("initialized",t,{initializedPre:function(){o.compulsorySecure=o.options.encrypted,o.key=i,o.socket=null,o.socket_id=null,o.state="initialized"},waitingPre:function(){o.connectionWait>0&&o.emit("connecting_in",o.connectionWait),o.netInfo.isOnLine()&&o.connectionAttempts<=4?g("connecting"):g("unavailable"),o.netInfo.isOnLine()&&(o._waitingTimer=setTimeout((function(){o._machine.transition("connecting")}),function(){var e=o.connectionWait;if(0===e&&o.connectedAt){var t=(new Date).getTime()-o.connectedAt;t<1e3&&(e=1e3-t)}return e}()))},waitingExit:function(){clearTimeout(o._waitingTimer)},connectingPre:function(){if(!1===o.netInfo.isOnLine())return o._machine.transition("waiting"),void g("unavailable");var t=function(t,n){var i=e.ws_port,r="ws://";(n||"https:"===document.location.protocol)&&(i=e.wss_port,r="wss://");var o="flash"===e.TransportType?"true":"false";return r+e.host+":"+i+"/app/"+t+"?protocol=5&client=js&version="+e.VERSION+"&flash="+o}(o.key,o.connectionSecure);e.debug("Connecting",t),o.socket=new e.Transport(t),o.socket.onopen=c,o.socket.onclose=h,o.socket.onerror=d,o._connectingTimer=setTimeout(s,o.openTimeout)},connectingExit:function(){clearTimeout(o._connectingTimer),o.socket.onopen=void 0},connectingToWaiting:function(){a()},connectingToImpermanentlyClosing:function(){a()},openPre:function(){o.socket.onmessage=l,o.socket.onerror=d,o.socket.onclose=h,o._openTimer=setTimeout(s,o.connectedTimeout)},openExit:function(){clearTimeout(o._openTimer),o.socket.onmessage=void 0},openToWaiting:function(){a()},openToImpermanentlyClosing:function(){a()},connectedPre:function(e){o.socket_id=e,o.socket.onmessage=f,o.socket.onerror=d,o.socket.onclose=h,n(o),o.connectedAt=(new Date).getTime(),u()},connectedPost:function(){g("connected")},connectedExit:function(){o._activityTimer&&clearTimeout(o._activityTimer),g("disconnected")},impermanentlyClosingPost:function(){o.socket&&(o.socket.onclose=h,o.socket.close())},permanentlyClosingPost:function(){o.socket?(o.socket.onclose=function(){n(o),o._machine.transition("permanentlyClosed")},o.socket.close()):(n(o),o._machine.transition("permanentlyClosed"))},failedPre:function(){g("failed"),e.debug("WebSockets are not available in this browser.")},permanentlyClosedPost:function(){g("disconnected")}})}i.prototype.connect=function(){this._machine.is("failed")||e.Transport?this._machine.is("initialized")?(n(this),this._machine.transition("waiting")):this._machine.is("waiting")&&!0===this.netInfo.isOnLine()?this._machine.transition("connecting"):this._machine.is("permanentlyClosed")&&(n(this),this._machine.transition("waiting")):this._machine.transition("failed")},i.prototype.send=function(e){if(this._machine.is("connected")){var t=this;return setTimeout((function(){t.socket.send(e)}),0),!0}return!1},i.prototype.send_event=function(t,n,i){var r={event:t,data:n};return i&&(r.channel=i),e.debug("Event sent",r),this.send(JSON.stringify(r))},i.prototype.disconnect=function(){this._machine.is("permanentlyClosed")||(this._machine.is("waiting")||this._machine.is("failed")?this._machine.transition("permanentlyClosed"):this._machine.transition("permanentlyClosing"))},e.Util.extend(i.prototype,e.EventsDispatcher.prototype),e.Connection=i}(),function(){e.Channels=function(){this.channels={}},e.Channels.prototype={add:function(t,n){var i=this.find(t);if(i)return i;var r=e.Channel.factory(t,n);return this.channels[t]=r,r},find:function(e){return this.channels[e]},remove:function(e){delete this.channels[e]},disconnect:function(){for(var e in this.channels)this.channels[e].disconnect()}},e.Channel=function(t,n){var i=this;e.EventsDispatcher.call(this,(function(n,i){e.debug("No callbacks on "+t+" for "+n)})),this.pusher=n,this.name=t,this.subscribed=!1,this.bind("pusher_internal:subscription_succeeded",(function(e){i.onSubscriptionSucceeded(e)}))},e.Channel.prototype={init:function(){},disconnect:function(){this.subscribed=!1,this.emit("pusher_internal:disconnected")},onSubscriptionSucceeded:function(e){this.subscribed=!0,this.emit("pusher:subscription_succeeded")},authorize:function(e,t,n){return n(!1,{})},trigger:function(e,t){return this.pusher.send_event(e,t,this.name)}},e.Util.extend(e.Channel.prototype,e.EventsDispatcher.prototype),e.Channel.PrivateChannel={authorize:function(t,n,i){var r=this;return new e.Channel.Authorizer(this,e.channel_auth_transport,n).authorize(t,(function(e,t){e||r.emit("pusher_internal:authorized",t),i(e,t)}))}},e.Channel.PresenceChannel={init:function(){this.members=new t(this)},onSubscriptionSucceeded:function(e){this.subscribed=!0}};var t=function(e){var t=this,n=function(){this._members_map={},this.count=0,this.me=null};n.call(this),e.bind("pusher_internal:authorized",(function(n){var i=JSON.parse(n.channel_data);e.bind("pusher_internal:subscription_succeeded",(function(n){t._members_map=n.presence.hash,t.count=n.presence.count,t.me=t.get(i.user_id),e.emit("pusher:subscription_succeeded",t)}))})),e.bind("pusher_internal:member_added",(function(n){null===t.get(n.user_id)&&t.count++,t._members_map[n.user_id]=n.user_info,e.emit("pusher:member_added",t.get(n.user_id))})),e.bind("pusher_internal:member_removed",(function(n){var i=t.get(n.user_id);i&&(delete t._members_map[n.user_id],t.count--,e.emit("pusher:member_removed",i))})),e.bind("pusher_internal:disconnected",(function(){n.call(t)}))};t.prototype={each:function(e){for(var t in this._members_map)e(this.get(t))},get:function(e){return this._members_map.hasOwnProperty(e)?{id:e,info:this._members_map[e]}:null}},e.Channel.factory=function(t,n){var i=new e.Channel(t,n);return 0===t.indexOf("private-")?e.Util.extend(i,e.Channel.PrivateChannel):0===t.indexOf("presence-")&&(e.Util.extend(i,e.Channel.PrivateChannel),e.Util.extend(i,e.Channel.PresenceChannel)),i.init(),i}}(),e.Channel.Authorizer=function(e,t,n){this.channel=e,this.type=t,this.authOptions=(n||{}).auth||{}},e.Channel.Authorizer.prototype={composeQuery:function(e){var t="&socket_id="+encodeURIComponent(e)+"&channel_name="+encodeURIComponent(this.channel.name);for(var n in this.authOptions.params)t+="&"+encodeURIComponent(n)+"="+encodeURIComponent(this.authOptions.params[n]);return t},authorize:function(t,n){return e.authorizers[this.type].call(this,t,n)}},e.auth_callbacks={},e.authorizers={ajax:function(t,n){var i;for(var r in(i=e.XHR?new e.XHR:window.XMLHttpRequest?new window.XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP")).open("POST",e.channel_auth_endpoint,!0),i.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),this.authOptions.headers)i.setRequestHeader(r,this.authOptions.headers[r]);return i.onreadystatechange=function(){if(4==i.readyState)if(200==i.status){var t,r=!1;try{t=JSON.parse(i.responseText),r=!0}catch(e){n(!0,"JSON returned from webapp was invalid, yet status code was 200. Data was: "+i.responseText)}r&&n(!1,t)}else e.warn("Couldn't get auth info from your webapp",i.status),n(!0,i.status)},i.send(this.composeQuery(t)),i},jsonp:function(t,n){void 0!==this.authOptions.headers&&e.warn("Warn","To send headers with the auth request, you must use AJAX, rather than JSONP.");var i=document.createElement("script");e.auth_callbacks[this.channel.name]=function(e){n(!1,e)};var r="Pusher.auth_callbacks['"+this.channel.name+"']";i.src=e.channel_auth_endpoint+"?callback="+encodeURIComponent(r)+this.composeQuery(t);var o=document.getElementsByTagName("head")[0]||document.documentElement;o.insertBefore(i,o.firstChild)}};var r=function(){function e(e,t){var n=document.getElementsByTagName("head")[0],i=document.createElement("script");i.setAttribute("src",e),i.setAttribute("type","text/javascript"),i.setAttribute("async",!0),function(e,t){document.addEventListener?e.addEventListener("load",t,!1):e.attachEvent("onreadystatechange",(function(){"loaded"!=e.readyState&&"complete"!=e.readyState||t()}))}(i,(function(){t()})),n.appendChild(i)}return function(t,n){for(var i=0,r=0;r<t.length;r++)e(t[r],(function(){t.length==++i&&setTimeout(n,0)}))}}();!function(){n()&&!window.WebSocket&&window.MozWebSocket&&(window.WebSocket=window.MozWebSocket),n()&&window.WebSocket&&(e.Transport=window.WebSocket,e.TransportType="native");var t=(n()&&("http:"==document.location.protocol?e.cdn_http:e.cdn_https))+e.VERSION,i=[];n()&&!window.JSON&&i.push(t+"/json2"+e.dependency_suffix+".js"),n()&&!window.WebSocket&&(window.WEB_SOCKET_DISABLE_AUTO_INITIALIZATION=!0,i.push(t+"/flashfallback"+e.dependency_suffix+".js"));var o=n()&&window.WebSocket?function(){e.ready()}:function(){window.WebSocket?(e.Transport=window.WebSocket,e.TransportType="flash",window.WEB_SOCKET_SWF_LOCATION="https://s3.amazonaws.com/uploadcare-static/WebSocketMainInsecure.swf",WebSocket.__addTask((function(){e.ready()})),WebSocket.__initialize()):(e.Transport=null,e.TransportType="none",e.ready())},a=function(){var e;e=o,function t(){n()&&(document.body?e():setTimeout(t,0))}()};i.length>0?r(i,a):a()}(),this.Pusher=e}).call(t)}(t={exports:{}},t.exports),t.exports}().Pusher,Xe={};qe.prototype.constructor=qe;var Je=function(t){function i(){return n(this,i),p(this,c(i).apply(this,arguments))}return u(i,t),o(i,[{key:"subscribe",value:function(e){return this.disconnectTimeout&&(clearTimeout(this.disconnectTimeout),this.disconnectTimeout=null),this.connect(),h(c(i.prototype),"subscribe",this).apply(this,arguments)}},{key:"unsubscribe",value:function(t){var n=this;h(c(i.prototype),"unsubscribe",this).apply(this,arguments),e.isEmptyObject(this.channels.channels)&&(this.disconnectTimeout=setTimeout((function(){return n.disconnectTimeout=null,n.disconnect()}),5e3))}}]),i}(qe),Ve=function(e){return null==Xe[e]&&(Xe[e]=new Je(e)),Xe[e].connect(),Xe[e]},Ye=function(t){function i(e){var t,r;if(n(this,i),(t=p(this,c(i).apply(this,arguments))).__url=e,r=ce.exec(t.__url)[3].split("/").pop())try{t.fileName=decodeURIComponent(r)}catch(e){t.fileName=r}return t.__notifyApi(),t}return u(i,t),o(i,[{key:"setName",value:function(e){return this.fileName=e,this.__realFileName=e,this.__notifyApi()}},{key:"setIsImage",value:function(e){return this.isImage=e,this.__notifyApi()}},{key:"__startUpload",value:function(){var t,n,i,r,o=this;return n=e.Deferred(),r=new $e(this.settings),i=new He(this.settings),t={pub_key:this.settings.publicKey,signature:this.settings.secureSignature,expire:this.settings.secureExpire,source_url:this.__url,filename:this.__realFileName||"",source:this.sourceInfo.source,store:this.settings.doNotStore?"":"auto",jsonerrors:1},ie((function(){if("pending"===o.apiDeferred.state())return ye("".concat(o.settings.urlBase,"/from_url/"),"GET",t,{headers:{"X-UC-User-Agent":o.settings._userAgent}}).fail((function(e){return o.settings.debugUploads&&H("Can't start upload from URL.",e,t),n.reject()})).done((function(t){var a;if("pending"===o.apiDeferred.state())return o.settings.debugUploads&&(H("Start watchers.",t.token),a=setInterval((function(){return H("Still watching.",t.token)}),5e3),n.done((function(){return H("Stop watchers.",t.token)})).always((function(){return clearInterval(a)}))),o.__listenWatcher(n,e([r,i])),n.always((function(){return e([r,i]).off(o.allEvents),r.stopWatching(),i.stopWatching()})),e(r).one(o.allEvents,(function(){if(i.interval)return o.settings.debugUploads&&H("Start using pusher.",t.token),i.stopWatching()})),r.watch(t.token),i.watch(t.token)}))})),n}},{key:"__listenWatcher",value:function(t,n){var i=this;return n.on("progress",(function(e,n){return i.fileSize=n.total,t.notify(n.done/n.total)})).on("success",(function(n,r){return e(n.target).trigger("progress",r),i.fileId=r.uuid,i.__handleFileData(r),t.resolve()})).on("error fail",t.reject)}}]),i}(Be);Ye.prototype.sourceName="url",Ye.prototype.allEvents="progress success error fail";var $e=function(){function t(e){n(this,t),this.settings=e;try{this.pusher=Ve(this.settings.pusherKey)}catch(e){this.pusher=null}}return o(t,[{key:"watch",value:function(t){var n=this;if(this.token=t,this.pusher)return this.pusher.subscribe("task-status-".concat(this.token)).bind_all((function(t,i){return e(n).trigger(t,i)}))}},{key:"stopWatching",value:function(){if(this.pusher)return this.pusher.unsubscribe("task-status-".concat(this.token))}}]),t}(),He=function(){function t(e){n(this,t),this.settings=e,this.poolUrl="".concat(this.settings.urlBase,"/from_url/status/")}return o(t,[{key:"watch",value:function(e){var t=this;return this.token=e,function e(){return t.interval=setTimeout((function(){t.__updateStatus().done((function(){t.interval&&e()}))}),333),t.interval}()}},{key:"stopWatching",value:function(){return this.interval&&clearTimeout(this.interval),this.interval=null,this.interval}},{key:"__updateStatus",value:function(){var t=this;return ye(this.poolUrl,"GET",{token:this.token},{headers:{"X-UC-User-Agent":this.settings._userAgent}}).fail((function(n){return e(t).trigger("error")})).done((function(n){return e(t).trigger(n.status,n)}))}}]),t}(),Qe=function(e){function t(e){var i,r;return n(this,t),i=p(this,c(t).apply(this,arguments)),(r=he(e))?(i.fileId=r[1],r[2]&&(i.cdnUrlModifiers=r[2])):i.__rejectApi("baddata"),i}return u(t,e),t}(Be);Qe.prototype.sourceName="uploaded";var Ze=function(e){function t(e){var i;return n(this,t),i=p(this,c(t).apply(this,arguments)),e?(i.fileId=e.uuid,i.__handleFileData(e)):i.__rejectApi("deleted"),i}return u(t,e),t}(Be);Ze.prototype.sourceName="uploaded";var et={object:Ke,input:Ge,url:Ye,uploaded:Qe,ready:Ze},tt=function(e,t,n){return nt(e,[t],n)[0]},nt=function(t,n,i){var r,o,a,s,u;for(i=Ue(i||{}),u=[],r=0,a=n.length;r<a;r++)s=n[r],o=void 0,e.isArray(s)&&(o=s[1],s=s[0]),u.push(new et[t](s,i,o).promise());return u},it=function(e){return e&&e.done&&e.fail&&e.cancel},rt=functi