UNPKG

uploadcare-widget

Version:
14 lines (13 loc) 195 kB
/** * 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 a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var a=0;a<t.length;a++){var i=t[a];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function r(e,t,a){return t&&n(e.prototype,t),a&&n(e,a),e}function o(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function s(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,i)}return a}function c(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?s(Object(a),!0).forEach((function(t){o(e,t,a[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):s(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");var a,i;e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&(a=e,i=t,(Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(a,i))}function d(e){return(d=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function p(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function h(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?p(e):t}function f(e,t,a){return(f="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,a){var i=function(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=d(e)););return e}(e,t);if(i){var n=Object.getOwnPropertyDescriptor(i,t);return n.get?n.get.call(a):n.value}})(e,t,a||e)}function _(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 a=[],i=!0,n=!1,r=void 0;try{for(var o,s=e[Symbol.iterator]();!(i=(o=s.next()).done)&&(a.push(o.value),!t||a.length!==t);i=!0);}catch(e){n=!0,r=e}finally{try{i||null==s.return||s.return()}finally{if(n)throw r}}return a}}(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,a=new Array(e.length);t<e.length;t++)a[t]=e[t];return a}}(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))},v=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(a,i){function n(e,a,n,r){t.onload=t.onerror=t.ontimeout=function(){},t=void 0,i(e,a,n,r)}(t=new XDomainRequest).onload=function(){n(200,"OK",{text:t.responseText},"Content-Type: "+t.contentType)},t.onerror=function(){n(404,"Not Found")},t.onprogress=function(){},t.ontimeout=function(){n(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 b,y=m()&&!!(window.File&&window.FileList&&window.FileReader),w=m()&&!(!window.FormData||!y),x=m()&&("draggable"in(b=document.createElement("div"))||"ondragstart"in b&&"ondrop"in b),k=m()&&function(){var e;return!(!(e=document.createElement("canvas")).getContext||!e.getContext("2d"))}(),C=y&&x,S=null,z=m()&&/^[^(]+\(iP(?:hone|od|ad);\s*(.+?)\)/.exec(navigator.userAgent);if(z){var T=/OS (\d)_(\d)/.exec(z[1]);T&&(S=+T[1]+T[2]/10)}var A=!1;try{m()&&new window.Blob&&(A=window.Blob)}catch(e){}var j,O,M,D,I,U,P,E,F,R,B,L,N,V,W,H,q,K,X,G=m()&&(window.URL||window.webkitURL||!1),J=G&&G.createObjectURL&&G,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){}},Q=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){}},Z=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){}},ee={},te=function(e){if(null==ee[e])return ee[e]=!0,Z(e)},ae=[].indexOf,ie=function(e){var t,a,i,n;for(n=[],a=0,i=e.length;a<i;a++)t=e[a],ae.call(n,t)<0&&n.push(t);return n},ne=function(e){return setTimeout(e,0)},re=function(e,t){for(var a;t;)a=e%t,e=t,t=a;return e},oe=function(e){var t,a;return t=!1,a=null,function(){return t||(a=e.apply(this,arguments),t=!0),a}},se=function(t){return e.Deferred().resolve(t).promise()},le=function(t,a,i,n){var r,o;return o=e.Deferred(),r=function(e,t){return e&&t?function(){return t.call(this,e.apply(this,arguments))}:e||t},t.then(r(a,o.resolve),r(i,o.reject),r(n,o.notify)),o.promise()},ce=function(t,a){var i;return i={},e.each(a,(function(a,n){var r=t[n];e.isFunction(r)?i[n]=function(){for(var e=arguments.length,a=new Array(e),n=0;n<e;n++)a[n]=arguments[n];var o=r.apply(t,a);return o===t?i:o}:i[n]=r})),i},ue=function(e){return e.replace(/([A-Z])/g,"_$1").toUpperCase()},de=function(e){var t;return(t=e.add).add=e.add,t.remove=e.remove,t},pe=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)}))},he=/^(?:([^:/?#]+):)?(?:\/\/([^/?#]*))?([^?#]*)\??([^#]*)#?(.*)$/,fe=/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/i,_e=new RegExp("".concat(fe.source,"~[0-9]+"),"i"),ge=new RegExp("^/?(".concat(fe.source,")(?:/(-/(?:[^/]+/)+)?([^/]*))?$"),"i"),me=function(e){return ge.exec(he.exec(e)[3])},ve=function(e){return e.replace(/[\\-\\[]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},be=function(t){var a,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"i";return a=e.map(t.split("*"),ve),new RegExp("^"+a.join(".+")+"$",i)},ye=function(e){var t;return"http:"!==(t=document.location.protocol)&&(t="https:"),e.replace(/^\/\//,t+"//").replace(/\/+$/,"")},we=function(e,t){if(e.length>t){var a=Math.ceil((t-3)/2),i=Math.floor((t-3)/2);return e.slice(0,a)+"..."+e.slice(-i)}return e},xe=function(e,t,a){var i,n;return e[0]>t[0]||e[1]>t[1]||a?(n=t[0]/e[0],i=t[1]/e[1],!t[0]||t[1]&&n>i?[Math.round(i*e[0]),t[1]]:[t[0],Math.round(n*e[1])]):e.slice()},ke=function(t,a,i,n){var r,o,s,l,c,u,d;if(u=n.width,o=n.height,l=a.preferedSize,s="",(d=u===i[0]&&o===i[1])||(s+="-/crop/".concat(u,"x").concat(o,"/").concat(n.left,",").concat(n.top,"/")),r=a.downscale&&(u>l[0]||o>l[1]),c=a.upscale&&(u<l[0]||o<l[1]),r||c){var p=_(l,2);n.sw=p[0],n.sh=p[1],s+="-/resize/".concat(l.join("x"),"/")}else d||(s+="-/preview/");return(t=e.extend({},t)).cdnUrlModifiers=s,t.cdnUrl="".concat(t.originalUrl).concat(s||""),t.crop=n,t},Ce=function(t,a,i){var n,r,o;return r=null,""===(n=a.inputAcceptTypes)&&(n=a.imagesOnly?"image/*":null),(o=function(){return r=(a.multiple?e('<input type="file" multiple>'):e('<input type="file">')).attr("accept",n).css({position:"absolute",top:0,opacity:0,margin:0,padding:0,width:"auto",height:"auto",cursor:t.css("cursor")}).on("change",(function(){return i(this),e(this).hide(),o()})),t.append(r)})(),t.css({position:"relative",overflow:"hidden"}).mousemove((function(t){var a,i,n,o=e(this).offset();return a=o.left,i=o.top,n=r.width(),r.css({left:t.pageX-a-n+10,top:t.pageY-i-10})}))},Se=function(t,a,i){var n,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};return""===(n=a.inputAcceptTypes)&&(n=a.imagesOnly?"image/*":null),e(a.multiple?'<input type="file" multiple>':'<input type="file">').attr("accept",n).attr(r).css({position:"fixed",bottom:0,opacity:0}).on("change",(function(){return i(this),e(this).remove()})).appendTo(t).focus().click().hide()},ze="B KB MB GB TB PB EB ZB YB".split(" "),Te=function(e){var t,a,i,n,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"";if(e=parseInt(e,10),isNaN(e))return r;for(t=2,i=0,n=1e3-5*Math.pow(10,2-Math.max(t,3));e>n&&i<ze.length-1;)i++,e/=1024;return e+=1e-15,a=Math.max(0,t-Math.floor(e).toFixed(0).length),e=Number(e.toFixed(a)),"".concat(o).concat(e," ").concat(ze[i]).concat(s)},Ae={dataType:"json",crossDomain:!0,cache:!1},je=function(t,a,i){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};return e.ajax(e.extend({url:t,type:a,data:i},n,Ae)).then((function(t){var a;return t.error?(a=t.error.content||t.error,e.Deferred().reject(a)):t}),(function(e,a,i){var n;return n="".concat(a," (").concat(i,")"),Z("JSONP unexpected error: ".concat(n," while loading ").concat(t)),n}))},Oe=function(e,t,a,i){var n,r,o,s,l,c;if(window.HTMLCanvasElement.prototype.toBlob)return e.toBlob(i,t,a);for(o=(o=e.toDataURL(t,a)).split(","),r=window.atob(o[1]),n=new Uint8Array(r.length),s=l=0,c=r.length;l<c;s=l+=1)n[s]=r.charCodeAt(s);return i(new window.Blob([n],{type:/:(.+\/.+);/.exec(o[0])[1]}))},Me=function(e){var t,a,i;return i=0,t=[],a=function(){var e;return t.length?(e=t.shift(),ne((function(){return e(a)}))):i-=1},function(n){return!e||i<e?(i+=1,ne((function(){return n(a)}))):t.push(n)}},De=[["notify","progress",2],["resolve","done",0],["reject","fail",1]],Ie=function(t){for(var a=arguments.length,i=new Array(a>1?a-1:0),n=1;n<a;n++)i[n-1]=arguments[n];return e.Deferred((function(a){return e.each(De,(function(n,r){var o;return o=e.isFunction(i[r[2]])&&i[r[2]],t[r[1]]((function(){var i;return(i=o&&o.apply(this,arguments))&&e.isFunction(i.promise)?i.promise().progress(a.notify).done(a.resolve).fail(a.reject):a[r[0]+"With"](this===t?a.promise():this,o?[i]:arguments)}))}))})).promise()},Ue=[].indexOf;I={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:""},q={multipleMax:{from:0,to:1e3}},M={multipleMax:{min:1,max:1e3}},N={tabs:{all:"file camera url facebook gdrive gphotos dropbox instagram evernote flickr onedrive box vk huddle",default:I.tabs}},V=m()&&(document.currentScript||(X=document.getElementsByTagName("script"))[X.length-1]),(E=m()&&e(V).data("integration"))&&null!=E&&(I=e.extend(I,{integration:E})),W=function(t){return e.isArray(t)||(t=(t=e.trim(t))?t.split(" "):[]),t},j=function(e,t){var a,i,n,r,o,s,l,c,u=Object.prototype.hasOwnProperty;for(a=0,o=t.length;a<o;a++){if(r=t[a],c=l=W(e[r]),u.apply(N,[r]))for(c=[],n=0,s=l.length;n<s;n++)i=l[n],u.apply(N[r],[i])?c=c.concat(W(N[r][i])):c.push(i);e[r]=ie(c)}return e},K=function(e,t){var a,i,n;for(a=0,n=t.length;a<n;a++)null!=e[i=t[a]]&&(e[i]=ye(e[i]));return e},U=function(t,a){var i,n,r,o;for(i=0,r=a.length;i<r;i++)null!=t[n=a[i]]&&("string"==typeof(o=t[n])?(o=e.trim(o).toLowerCase(),t[n]=!("false"===o||"disabled"===o)):t[n]=!!o);return t},P=function(e,t){var a,i,n;for(a=0,n=t.length;a<n;a++)null!=e[i=t[a]]&&(e[i]=parseInt(e[i]));return e},F=function(e){return e._userAgent="UploadcareWidget/".concat("3.9.1","/").concat(e.publicKey," (JavaScript").concat(e.integration?"; ".concat(e.integration):"",")"),e},H=function(e,t){var a,i;for(a in t)i=t[a],null!=e[a]&&e[a]===i.from&&(e[a]=i.to);return e},O=function(e,t){var a,i,n;for(a in t){var r=t[a];n=r.min,i=r.max,null!=e[a]&&(e[a]=Math.min(Math.max(e[a],n),i))}return e},B=function(t){var a;return{downscale:"x"===(a=/^([0-9]+)([x:])([0-9]+)\s*(|upscale|minimum)$/i.exec(e.trim(t.toLowerCase()))||[])[2],upscale:!!a[4],notLess:"minimum"===a[4],preferedSize:a.length?[+a[1],+a[3]]:void 0}},L=function(t){var a,i;return!!(a=/^([0-9]+)x([0-9]+)(?:\s+(\d{1,2}|100)%)?$/i.exec(e.trim(t.toLowerCase()))||[]).length&&((i=a[1]*a[2])>5e6?(te("Shrinked size can not be larger than 5MP. "+"You have set ".concat(a[1],"x").concat(a[2]," (")+"".concat(Math.ceil(i/1e3/100)/10,"MP).")),!1):{quality:a[3]?a[3]/100:void 0,size:i})},D=function(e,t){var a,i,n,r;return this.previewProxy?(i=(n=!/\?/.test(this.previewProxy))||!/=$/.test(this.previewProxy),a=!n&&!/[&?=]$/.test(this.previewProxy),r=encodeURIComponent(e),i&&(r="url="+r),a&&(r="&"+r),n&&(r="?"+r),this.previewProxy+r):e},R=function(t){var a;return j(t,["tabs","preferredTypes","videoPreferredMimeTypes"]),K(t,["cdnBase","socialBase","urlBase","scriptBase"]),U(t,["doNotStore","imagesOnly","multiple","clearable","pathValue","previewStep","systemDialog","debugUploads","multipleMaxStrict"]),P(t,["multipleMax","multipleMin","multipartMinSize","multipartPartSize","multipartMinLastPartSize","multipartConcurrency","multipartMaxAttempts","parallelDirectUploads"]),H(t,q),O(t,M),F(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(","),B)),t.imageShrink&&!e.isPlainObject(t.imageShrink)&&(t.imageShrink=L(t.imageShrink)),(t.crop||t.multiple)&&(t.previewStep=!0),w||(t.systemDialog=!1),t.validators&&(t.validators=t.validators.slice()),t.previewProxy&&!t.previewUrlCallback&&(t.previewUrlCallback=D),-1!==(a=t.tabs.indexOf("skydrive"))&&(t.tabs[a]="onedrive"),t};var Pe=function(){var e,t,a;for(e in t={},I)null!=(a=window["UPLOADCARE_".concat(ue(e))])&&(t[e]=a);return t},Ee=oe((function(t,a){var i;return a||(I=e.extend(I,Pe())),i=R(e.extend(I,t||{})),Re.fire(i),i})),Fe=function(t){var a;return a=e.extend({},Ee()),e.isEmptyObject(t)||(a=R(e.extend(a,t))),a},Re=m()&&e.Callbacks("once memory"),Be=function(){function e(){a(this,e),this.urls=[],this.styles=[]}return r(e,[{key:"addUrl",value:function(e){if(!/^https?:\/\//i.test(e))throw new Error("Embedded urls should be absolute. "+e);if(!(Ue.call(this.urls,e)>=0))return this.urls.push(e)}},{key:"addStyle",value:function(e){return this.styles.push(e)}}]),e}(),Le=function(t,a){var i;return i=e.Deferred(),a&&(t.src=a),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()},Ne=function t(a){return e.isArray(a)?e.when.apply(null,e.map(a,t)):a.src?Le(a):Le(new window.Image,a)},Ve=function(t){var a=e.Deferred();return e("<video/>").on("loadeddata",a.resolve).on("error",a.reject).attr("src",t).get(0).load(),a.promise()},We=m()&&window.DataView,He=Me(1),qe=function(t,a){var i;return i=e.Deferred(),J&&We&&A?(He((function(e){var n;return i.always(e),(n=Ne(J.createObjectURL(t))).always((function(e){return J.revokeObjectURL(e.src)})),n.fail((function(){return i.reject("not image")})),n.done((function(e){i.notify(.1);var r=Ye(t).always((function(t){var o;return i.notify(.2),o="resolved"===r.state(),(n=Ke(e,a)).progress((function(e){return i.notify(.2+.6*e)})),n.fail(i.reject),n.done((function(e){var r,s;return r="image/jpeg",s=a.quality||.8,!o&&Qe(e)&&(r="image/png",s=void 0),Oe(e,r,s,(function(a){return e.width=e.height=1,i.notify(.9),t?((n=Je(a,225,[t.buffer])).done(i.resolve),n.fail((function(){return i.resolve(a)}))):i.resolve(a)}))})),null}));return r}))})),i.promise()):i.reject("support")},Ke=function(t,a){var i,n,r,o,s,l,c,u,d;return i=e.Deferred(),.71*t.width*t.height*.71<a.size?i.reject("not required"):(u=r=t.width,c=t.height,o=u/c,d=Math.floor(Math.sqrt(a.size*o)),n=Math.floor(a.size/Math.sqrt(a.size*o)),s=function(){if(!(u<=d))return ne((function(){var e;return u=Math.round(.71*u),c=Math.round(.71*c),.71*u<d&&(u=d,c=n),u*c>5e6&&(u=Math.floor(Math.sqrt(5e6*o)),c=Math.floor(5e6/Math.sqrt(5e6*o))),u>4096&&(u=4096,c=Math.round(u/o)),c>4096&&(c=4096,u=Math.round(o*c)),(e=document.createElement("canvas")).width=u,e.height=c,e.getContext("2d").drawImage(t,0,0,u,c),t.src="//:0",t.width=t.height=1,t=e,i.notify((r-u)/(r-d)),s()}));i.resolve(t)},l=function(){var e,a;return(e=document.createElement("canvas")).width=d,e.height=n,(a=e.getContext("2d")).imageSmoothingQuality="high",a.drawImage(t,0,0,d,n),t.src="//:0",t.width=t.height=1,i.resolve(e)},"imageSmoothingQuality"in document.createElement("canvas").getContext("2d")?l():s(),i.promise())},Xe=function(t,a,i,n,r){var o,s;return o=e.Deferred(),J?((s=Ne(J.createObjectURL(t))).always((function(e){return J.revokeObjectURL(e.src)})),s.fail((function(){return o.reject("not image")})),s.done((function(e){return o.always((function(){e.src="//:0"})),r&&e.width*e.height>r?o.reject("max source"):Ye(t).always((function(t){var r,s,l,c,u,d,p,h;d=(p=(u=$e(t)||1)>4)?[e.height,e.width]:[e.width,e.height];var f=_(xe(d,[a,i]),2);if(!(h=[[1,0,0,1,0,0],[-1,0,0,1,c=f[0],0],[-1,0,0,-1,c,l=f[1]],[1,0,0,-1,0,l],[0,1,1,0,0,0],[0,1,-1,0,c,0],[0,-1,-1,0,c,l],[0,-1,1,0,0,l]][u-1]))return o.reject("bad image");if((r=document.createElement("canvas")).width=c,r.height=l,(s=r.getContext("2d")).transform.apply(s,h),p){var g=[l,c];c=g[0],l=g[1]}return n&&(s.fillStyle=n,s.fillRect(0,0,c,l)),s.drawImage(e,0,0,c,l),o.resolve(r,d)}))})),o.promise()):o.reject("support")},Ge=function(t){var a,i,n,r,o;return o=function(e,t){var i;return(i=new Y).onload=function(){return t(new We(i.result))},i.onerror=function(e){return a.reject("reader",e)},i.readAsArrayBuffer(e)},n=function(){return o(t.slice(i,i+128),(function(e){var t,a,n;for(t=a=0,n=e.byteLength;n>=0?a<n:a>n;t=n>=0?++a:--a)if(255===e.getUint8(t)){i+=t;break}return r()}))},r=function(){var e;return e=i,o(t.slice(i,i+=4),(function(r){var s,l;return 4!==r.byteLength||255!==r.getUint8(0)?a.reject("corrupted"):218===(l=r.getUint8(1))?a.resolve():(s=r.getUint16(2)-2,o(t.slice(i,i+=s),(function(t){return t.byteLength!==s?a.reject("corrupted"):(a.notify(e,s,l,t),n())})))}))},a=e.Deferred(),Y&&We?(i=2,o(t.slice(0,2),(function(e){return 65496!==e.getUint16(0)?a.reject("not jpeg"):n()})),a.promise()):a.reject("support")},Je=function(t,a,i){var n,r,o,s;return n=e.Deferred(),o=[],r=[],(s=Ge(t)).fail(n.reject),s.progress((function(e,t,i){if(i===a)return o.push(e),r.push(t)})),s.done((function(){var e,s,l,c,u,d,p,h,f;for(p=[t.slice(0,2)],c=0,d=i.length;c<d;c++)e=i[c],(l=new We(new ArrayBuffer(4))).setUint16(0,65280+a),l.setUint16(2,e.byteLength+2),p.push(l.buffer),p.push(e);for(h=2,s=u=0,f=o.length;f>=0?u<f:u>f;s=f>=0?++u:--u)o[s]>h&&p.push(t.slice(h,o[s])),h=o[s]+r[s]+4;return p.push(t.slice(h,t.size)),n.resolve(new A(p,{type:t.type}))})),n.promise()},Ye=function(t){var a,i;return a=null,(i=Ge(t)).progress((function(e,t,i,n){if(!a&&225===i&&n.byteLength>=14&&1165519206===n.getUint32(0)&&0===n.getUint16(4))return a=n})),i.then((function(){return a}),(function(t){return e.Deferred().reject(a,t)}))},$e=function(e){var t,a,i,n;if(!e||e.byteLength<14||1165519206!==e.getUint32(0)||0!==e.getUint16(4))return null;if(18761===e.getUint16(6))a=!0;else{if(19789!==e.getUint16(6))return null;a=!1}if(42!==e.getUint16(8,a))return null;for(i=8+e.getUint32(10,a),t=0,n=e.getUint16(i-2,a);n>=0?t<n:t>n;n>=0?++t:--t){if(e.byteLength<i+10)return null;if(274===e.getUint16(i,a))return e.getUint16(i+8,a);i+=12}return null},Qe=function(e){var t,a,i,n,r,o;for((t=document.createElement("canvas")).width=t.height=50,(a=t.getContext("2d")).drawImage(e,0,0,50,50),i=a.getImageData(0,0,50,50).data,t.width=t.height=1,n=r=3,o=i.length;r<o;n=r+=4)if(i[n]<254)return!0;return!1},Ze=function(){function t(e,i){var n,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};a(this,t),this.settings=i,this.sourceInfo=r,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,(n=this.sourceInfo).source||(n.source=this.sourceName),this.__setupValidation(),this.__initApi()}return r(t,[{key:"__startUpload",value:function(){return e.Deferred().resolve()}},{key:"__completeUpload",value:function(){var e,t,a,i,n=this;return a=0,this.settings.debugUploads&&(Q("Load file info.",this.fileId,this.settings.publicKey),t=setInterval((function(){return Q("Still waiting for file ready.",a,n.fileId,n.settings.publicKey)}),5e3),this.apiDeferred.done((function(){return Q("File uploaded.",a,n.fileId,n.settings.publicKey)})).always((function(){return clearInterval(t)}))),i=100,(e=function(){if("pending"===n.apiDeferred.state())return a+=1,n.__updateInfo().done((function(){return setTimeout(e,i),i+=50}))})()}},{key:"__updateInfo",value:function(){var e=this;return je("".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,a,i,n,r,o;a=this.__fileInfo();try{for(n=this.validators,r=[],t=0,i=n.length;t<i;t++)o=n[t],r.push(o(a));return r}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 a=arguments.length,i=new Array(a),n=0;n<a;n++)i[n]=arguments[n];return t.__extendApi(Ie.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}(),et=null,tt=function(t){function i(e){var t;return a(this,i),(t=h(this,d(i).apply(this,arguments))).__file=e,t.fileName=t.__file.name||"original",t.__notifyApi(),t}return u(i,t),r(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&&Q("Use local file.",this.fileName,this.fileType,this.fileSize),this.__runValidators(),this.__notifyApi()}},{key:"__startUpload",value:function(){var t,a,i,n=this;return this.apiDeferred.always((function(){return n.__file=null,n.__file})),this.__file.size>=this.settings.multipartMinSize&&A?(this.setFile(),this.multipartUpload()):(a=S,!this.settings.imageShrink||a&&a<8?(this.setFile(),this.directUpload()):(t=e.Deferred(),i=.4,qe(this.__file,this.settings.imageShrink).progress((function(e){return t.notify(e*i)})).done(this.setFile.bind(this)).fail((function(){return n.setFile(),i*=.1})).always((function(){return t.notify(i),n.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 et||(et=Me(this.settings.parallelDirectUploads)),et(e)}},{key:"directUpload",value:function(){var t,a=this;return t=e.Deferred(),this.__file?this.fileSize>104857600?(this.__rejectApi("size"),t):(this.directRunner((function(i){var n;if(t.always(i),"pending"===a.apiDeferred.state())return(n=new window.FormData).append("UPLOADCARE_PUB_KEY",a.settings.publicKey),n.append("signature",a.settings.secureSignature),n.append("expire",a.settings.secureExpire),n.append("UPLOADCARE_STORE",a.settings.doNotStore?"":"auto"),n.append("file",a.__file,a.fileName),n.append("file_name",a.fileName),n.append("source",a.sourceInfo.source),a.__autoAbort(e.ajax({xhr:function(){var a;return(a=e.ajaxSettings.xhr()).upload&&a.upload.addEventListener("progress",(function(e){return t.notify(e.loaded/e.total)}),!1),a},crossDomain:!0,type:"POST",url:"".concat(a.settings.urlBase,"/base/?jsonerrors=1"),headers:{"X-UC-User-Agent":a.settings._userAgent},contentType:!1,processData:!1,data:n,dataType:"json",error:t.reject,success:function(e){return(null!=e?e.file:void 0)?(a.fileId=e.file,t.resolve()):t.reject()}}))})),t):(this.__rejectApi("baddata"),t)}},{key:"multipartUpload",value:function(){var t,a=this;return t=e.Deferred(),this.__file?(this.multipartStart().done((function(e){return a.uploadParts(e.parts,e.uuid).done((function(){return a.multipartComplete(e.uuid).done((function(e){return a.fileId=e.uuid,a.__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(je("".concat(this.settings.urlBase,"/multipart/start/?jsonerrors=1"),"POST",e,{headers:{"X-UC-User-Agent":this.settings._userAgent}})).fail((function(a){if(t.settings.debugUploads)return $("Can't start multipart upload.",a,e)}))}},{key:"uploadParts",value:function(t,a){var i,n,r,o,s,l,c,u,d,p,h=this;for(s=[],o=Date.now(),p=function(e,t){var a,n,r;if(s[e]=t,!(Date.now()-o<250)){for(o=Date.now(),r=0,a=0,n=s.length;a<n;a++)r+=t=s[a];return i.notify(r/h.fileSize)}},i=e.Deferred(),n=0,d=0,u=0,c=function(){var r,o,l,f,_;if(!(u>=h.fileSize))return l=u+h.settings.multipartPartSize,h.fileSize<l+h.settings.multipartMinLastPartSize&&(l=h.fileSize),o=h.__file.slice(u,l),u=l,f=d,n+=1,d+=1,r=0,(_=function(){if("pending"===h.apiDeferred.state())return s[f]=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(f,e.loaded)}),!1),t},url:t[f],crossDomain:!0,type:"PUT",processData:!1,contentType:h.fileType,data:o,error:function(){return(r+=1)>h.settings.multipartMaxAttempts?(h.settings.debugUploads&&$("Part #".concat(f," and file upload is failed."),a),i.reject()):(h.settings.debugUploads&&Q("Part #".concat(f,"(").concat(r,") upload is failed."),a),_())},success:function(){if(n-=1,c(),!n)return i.resolve()}}))})()},r=0,l=this.settings.multipartConcurrency;l>=0?r<l:r>l;l>=0?++r:--r)c();return i}},{key:"multipartComplete",value:function(e){var t,a=this;return t={UPLOADCARE_PUB_KEY:this.settings.publicKey,uuid:e},this.__autoAbort(je("".concat(this.settings.urlBase,"/multipart/complete/?jsonerrors=1"),"POST",t,{headers:{"X-UC-User-Agent":this.settings._userAgent}})).fail((function(t){if(a.settings.debugUploads)return $("Can't complete multipart upload.",e,a.settings.publicKey,t)}))}}]),i}(Ze);tt.prototype.sourceName="local";var at=function(t){function i(t){var n;return a(this,i),(n=h(this,d(i).apply(this,arguments))).__input=t,n.fileId=pe(),n.fileName=e(n.__input).val().split("\\").pop(),n.__notifyApi(),n}return u(i,t),r(i,[{key:"__startUpload",value:function(){var t,a,i,n;return t=e.Deferred(),n="".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),a=function(t,a){return e("<input/>",{type:"hidden",name:t,value:a})},e(this.__input).attr("name","file"),this.__iframeForm=e("<form>").attr({method:"POST",action:n,enctype:"multipart/form-data",target:i}).append(a("UPLOADCARE_PUB_KEY",this.settings.publicKey)).append(a("UPLOADCARE_SIGNATURE",this.settings.secureSignature)).append(a("UPLOADCARE_EXPIRE",this.settings.secureExpire)).append(a("UPLOADCARE_FILE_ID",this.fileId)).append(a("UPLOADCARE_STORE",this.settings.doNotStore?"":"auto")).append(a("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}(Ze);at.prototype.sourceName="local-compat";var it=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 a=v.isWindowDefined;(function(){var e,t;(e=function(t,a){this.options=a||{},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,a=0===e.event.indexOf("pusher_internal:");e.channel&&(t=i.channel(e.channel))&&t.emit(e.event,e.data),a||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,a=this.channels.add(e,this);return"connected"===this.connection.state&&a.authorize(this.connection.socket_id,this.options,(function(i,n){i?a.emit("pusher:subscription_error",n):t.send_event("pusher:subscribe",{channel:e,auth:n.auth,channel_data:n.channel_data})})),a},unsubscribe:function(e){this.channels.remove(e),"connected"===this.connection.state&&this.send_event("pusher:unsubscribe",{channel:e})},send_event:function(e,t,a){return this.connection.send_event(e,t,a)},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,a){for(var i in a)a[i]&&a[i].constructor&&a[i].constructor===Object?t[i]=e(t[i]||{},a[i]):t[i]=a[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 a=Array.prototype.indexOf;if(null==e)return-1;if(a&&e.indexOf===a)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,a=e.instances.length;t<a;t++)e.instances[t].connect()},function(){function t(){this._callbacks={}}function a(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 a=this._prefix(e);this._callbacks[a]=this._callbacks[a]||[],this._callbacks[a].push(t)},t.prototype.remove=function(t,a){if(this.get(t)){var i=e.Util.arrayIndexOf(this.get(t),a);this._callbacks[this._prefix(t)].splice(i,1)}},t.prototype._prefix=function(e){return"_"+e},a.prototype.bind=function(e,t){return this.callbacks.add(e,t),this},a.prototype.unbind=function(e,t){return this.callbacks.remove(e,t),this},a.prototype.emit=function(e,t){for(var a=0;a<this.global_callbacks.length;a++)this.global_callbacks[a](e,t);var i=this.callbacks.get(e);if(i)for(a=0;a<i.length;a++)i[a](t);else this.failThrough&&this.failThrough(e,t);return this},a.prototype.bind_all=function(e){return this.global_callbacks.push(e),this},e.EventsDispatcher=a}(),function(){function t(e,t,a){void 0!==t[e]&&t[e](a)}function a(t,a,i){e.EventsDispatcher.call(this),this.state=void 0,this.errors=[],this.stateActions=i,this.transitions=a,this.transition(t)}a.prototype.transition=function(a,i){var n,r=this.state,o=this.stateActions;if(r&&-1==e.Util.arrayIndexOf(this.transitions[r],a))throw this.emit("invalid_transition_attempt",{oldState:r,newState:a}),new Error("Invalid transition ["+r+" to "+a+"]");t(r+"Exit",o,i),t(r+"To"+((n=a).substr(0,1).toUpperCase()+n.substr(1)),o,i),t(a+"Pre",o,i),this.state=a,this.emit("state_change",{oldState:r,newState:a}),t(a+"Post",o,i)},a.prototype.is=function(e){return this.state===e},a.prototype.isNot=function(e){return this.state!==e},e.Util.extend(a.prototype,e.EventsDispatcher.prototype),e.Machine=a}(),(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 a(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,n){var r=this;function o(){r.connectionWait<1e4&&(r.connectionWait+=2e3),r.openTimeout<1e4&&(r.openTimeout+=2e3),r.connectedTimeout<1e4&&(r.connectedTimeout+=2e3),!0!==r.compulsorySecure&&(r.connectionSecure=!r.connectionSecure),r.connectionAttempts++}function s(){r._machine.transition("impermanentlyClosing")}function l(){r._activityTimer&&clearTimeout(r._activityTimer),r._activityTimer=setTimeout((function(){r.send_event("pusher:ping",{}),r._activityTimer=setTimeout((function(){r.socket.close()}),r.options.pong_timeout||e.pong_timeout)}),r.options.activity_timeout||e.activity_timeout)}function c(){r._machine.transition("open")}function u(e){var t,a,i=p(e);void 0!==i&&("pusher:connection_established"===i.event?r._machine.transition("connected",i.data.socket_id):"pusher:error"===i.event&&(t=i.data.code,a=i.data.message,r.emit("error",{type:"PusherError",data:{code:t,message:a}}),4e3===t?(r.compulsorySecure=!0,r.connectionSecure=!0,r.options.encrypted=!0,s()):t<4100?r._machine.transition("permanentlyClosing"):t<4200?(r.connectionWait=1e3,r._machine.transition("waiting")):t<4300?s():r._machine.transition("permanentlyClosing")))}function d(t){l();var a=p(t);if(void 0!==a){switch(e.debug("Event recd",a),a.event){case"pusher:error":r.emit("error",{type:"PusherError",data:a.data});break;case"pusher:ping":r.send_event("pusher:pong",{})}r.emit("message",a)}}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){r.emit("error",{type:"MessageParseError",error:t,data:e.data})}}function h(){r._machine.transition("waiting")}function f(e){r.emit("error",{type:"WebSocketError",error:e})}function _(t,a){var i=r.state;r.state=t,i!==t&&(e.debug("State changed",i+" -> "+t),r.emit("state_change",{previous:i,current:t}),r.emit(t,a))}e.EventsDispatcher.call(this),this.options=e.Util.extend({encrypted:!1},n),this.netInfo=new e.NetInfo,this.netInfo.bind("online",(function(){r._machine.is("waiting")&&(r._machine.transition("connecting"),_("connecting"))})),this.netInfo.bind("offline",(function(){r._machine.is("connected")&&(r.socket.onclose=void 0,r.socket.onmessage=void 0,r.socket.onerror=void 0,r.socket.onopen=void 0,r.socket.close(),r.socket=void 0,r._machine.transition("waiting"))})),this._machine=new e.Machine("initialized",t,{initializedPre:function(){r.compulsorySecure=r.options.encrypted,r.key=i,r.socket=null,r.socket_id=null,r.state="initialized"},waitingPre:function(){r.connectionWait>0&&r.emit("connecting_in",r.connectionWait),r.netInfo.isOnLine()&&r.connectionAttempts<=4?_("connecting"):_("unavailable"),r.netInfo.isOnLine()&&(r._waitingTimer=setTimeout((function(){r._machine.transition("connecting")}),function(){var e=r.connectionWait;if(0===e&&r.connectedAt){var t=(new Date).getTime()-r.connectedAt;t<1e3&&(e=1e3-t)}return e}()))},waitingExit:function(){clearTimeout(r._waitingTimer)},connectingPre:function(){if(!1===r.netInfo.isOnLine())return r._machine.transition("waiting"),void _("unavailable");var t=function(t,a){var i=e.ws_port,n="ws://";(a||"https:"===document.location.protocol)&&(i=e.wss_port,n="wss://");var r="flash"===e.TransportType?"true":"false";return n+e.host+":"+i+"/app/"+t+"?protocol=5&client=js&version="+e.VERSION+"&flash="+r}(r.key,r.connectionSecure);e.debug("Connecting",t),r.socket=new e.Transport(t),r.socket.onopen=c,r.socket.onclose=h,r.socket.onerror=f,r._connectingTimer=setTimeout(s,r.openTimeout)},connectingExit:function(){clearTimeout(r._connectingTimer),r.socket.onopen=void 0},connectingToWaiting:function(){o()},connectingToImpermanentlyClosing:function(){o()},openPre:function(){r.socket.onmessage=u,r.socket.onerror=f,r.socket.onclose=h,r._openTimer=setTimeout(s,r.connectedTimeout)},openExit:function(){clearTimeout(r._openTimer),r.socket.onmessage=void 0},openToWaiting:function(){o()},openToImpermanentlyClosing:function(){o()},connectedPre:function(e){r.socket_id=e,r.socket.onmessage=d,r.socket.onerror=f,r.socket.onclose=h,a(r),r.connectedAt=(new Date).getTime(),l()},connectedPost:function(){_("connected")},connectedExit:function(){r._activityTimer&&clearTimeout(r._activityTimer),_("disconnected")},impermanentlyClosingPost:function(){r.socket&&(r.socket.onclose=h,r.socket.close())},permanentlyClosingPost:function(){r.socket?(r.socket.onclose=function(){a(r),r._machine.transition("permanentlyClosed")},r.socket.close()):(a(r),r._machine.transition("permanentlyClosed"))},failedPre:function(){_("failed"),e.debug("WebSockets are not available in this browser.")},permanentlyClosedPost:function(){_("disconnected")}})}i.prototype.connect=function(){this._machine.is("failed")||e.Transport?this._machine.is("initialized")?(a(this),this._machine.transition("waiting")):this._machine.is("waiting")&&!0===this.netInfo.isOnLine()?this._machine.transition("connecting"):this._machine.is("permanentlyClosed")&&(a(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,a,i){var n={event:t,data:a};return i&&(n.channel=i),e.debug("Event sent",n),this.send(JSON.stringify(n))},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,a){var i=this.find(t);if(i)return i;var n=e.Channel.factory(t,a);return this.channels[t]=n,n},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,a){var i=this;e.EventsDispatcher.call(this,(function(a,i){e.debug("No callbacks on "+t+" for "+a)})),this.pusher=a,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,a){return a(!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,a,i){var n=this;return new e.Channel.Authorizer(this,e.channel_auth_transport,a).authorize(t,(function(e,t){e||n.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,a=function(){this._members_map={},this.count=0,this.me=null};a.call(this),e.bind("pusher_internal:authorized",(function(a){var i=JSON.parse(a.channel_data);e.bind("pusher_internal:subscription_succeeded",(function(a){t._members_map=a.presence.hash,t.count=a.presence.count,t.me=t.get(i.user_id),e.emit("pusher:subscription_succeeded",t)}))})),e.bind("pusher_internal:member_added",(function(a){null===t.get(a.user_id)&&t.count++,t._members_map[a.user_id]=a.user_info,e.emit("pusher:member_added",t.get(a.user_id))})),e.bind("pusher_internal:member_removed",(function(a){var i=t.get(a.user_id);i&&(delete t._members_map[a.user_id],t.count--,e.emit("pusher:member_removed",i))})),e.bind("pusher_internal:disconnected",(function(){a.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,a){var i=new e.Channel(t,a);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,a){this.channel=e,this.type=t,this.authOptions=(a||{}).auth||{}},e.Channel.Authorizer.prototype={composeQuery:function(e){var t="&socket_id="+encodeURIComponent(e)+"&channel_name="+encodeURIComponent(this.channel.name);for(var a in this.authOptions.params)t+="&"+encodeURIComponent(a)+"="+encodeURIComponent(this.authOptions.params[a]);return t},authorize:function(t,a){return e.authorizers[this.type].call(this,t,a)}},e.auth_callbacks={},e.authorizers={ajax:function(t,a){var i;for(var n 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(n,this.authOptions.headers[n]);return i.onreadystatechange=function(){if(4==i.readyState)if(200==i.status){var t,n=!1;try{t=JSON.parse(i.responseText),n=!0}catch(e){a(!0,"JSON returned from webapp was invalid, yet status code was 200. Data was: "+i.responseText)}n&&a(!1,t)}else e.warn("Couldn't get auth info from your webapp",i.status),a(!0,i.status)},i.send(this.composeQuery(t)),i},jsonp:function(t,a){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){a(!1,e)};var n="Pusher.auth_callbacks['"+this.channel.name+"']";i.src=e.channel_auth_endpoint+"?callback="+encodeURIComponent(n)+this.composeQuery(t);var r=document.getElementsByTagName("head")[0]||document.documentElement;r.insertBefore(i,r.firstChild)}};var n=function(){function e(e,t){var a=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()})),a.appendChild(i)}return function(t,a){for(var i=0,n=0;n<t.length;n++)e(t[n],(function(){t.length==++i&&setTimeout(a,0)}))}}();!function(){a()&&!window.WebSocket&&window.MozWebSocket&&(window.WebSocket=window.MozWebSocket),a()&&window.WebSocket&&(e.Transport=window.WebSocket,e.TransportType="native");var t=(a()&&("http:"==document.location.protocol?e.cdn_http:e.cdn_https))+e.VERSION,i=[];a()&&!window.JSON&&i.push(t+"/json2"+e.dependency_suffix+".js"),a()&&!window.WebSocket&&(window.WEB_SOCKET_DISABLE_AUTO_INITIALIZATION=!0,i.push(t+"/flashfallback"+e.dependency_suffix+".js"));var r=a()&&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())},o=function(){var e;e=r,function t(){a()&&(document.body?e():setTimeout(t,0))}()};i.length>0?n(i,o):o()}(),this.Pusher=e}).call(t)}(t={exports:{}},t.exports),t.exports}().Pusher,nt={};it.prototype.constructor=it;var rt=function(t){function i(){return a(this,i),h(this,d(i).apply(this,arguments))}return u(i,t),r(i,[{key:"subscribe",value:function(e){return this.disconnectTimeout&&(clearTimeout(this.disconnectTimeout),this.disconnectTimeout=null),this.connect(),f(d(i.prototype),"subscribe",this).apply(this,arguments)}},{key:"unsubscribe",value:function(t){var a=this;f(d(i.prototype),"unsubscribe",this).apply(this,arguments),e.isEmptyObject(this.channels.channels)&&(this.disconnectTimeout=setTimeout((function(){return a.disconnectTimeout=null,a.disconnect()}),5e3))}}]),i}(it),ot=function(e){return null==nt[e]&&(nt[e]=new rt(e)),nt[e].connect(),nt[e]},st=function(t){function i(e){var t,n;if(a(this,i),(t=h(this,d(i).apply(this,arguments))).__url=e,n=he.exec(t.__url)[3].split("/").