(function(e){"use strict";if(typeof define==="function"&&define.amd){define(["jquery","jquery.ui.widget"],e)}else{e(window.jQuery)}})(function(m){"use strict";m.support.fileInput=!(new RegExp("(Android (1\\.[0156]|2\\.[01]))"+"|(Windows Phone (OS 7|8\\.0))|(XBLWP)|(ZuneWP)|(WPDesktop)"+"|(w(eb)?OSBrowser)|(webOS)"+"|(Kindle/(1\\.0|2\\.[05]|3\\.0))").test(window.navigator.userAgent)||m('<input type="file">').prop("disabled"));m.support.xhrFileUpload=!!(window.ProgressEvent&&window.FileReader);m.support.xhrFormDataFileUpload=!!window.FormData;m.support.blobSlice=window.Blob&&(Blob.prototype.slice||Blob.prototype.webkitSlice||Blob.prototype.mozSlice);m.widget("blueimp.fileupload",{options:{dropZone:m(document),pasteZone:m(document),fileInput:undefined,replaceFileInput:true,paramName:undefined,singleFileUploads:true,limitMultiFileUploads:undefined,limitMultiFileUploadSize:undefined,limitMultiFileUploadSizeOverhead:512,sequentialUploads:false,limitConcurrentUploads:undefined,forceIframeTransport:false,redirect:undefined,redirectParamName:undefined,postMessage:undefined,multipart:true,maxChunkSize:undefined,uploadedBytes:undefined,recalculateProgress:true,progressInterval:100,bitrateInterval:500,autoUpload:true,messages:{uploadedBytes:"Uploaded bytes exceed file size"},i18n:function(i,e){i=this.messages[i]||i.toString();if(e){m.each(e,function(e,t){i=i.replace("{"+e+"}",t)})}return i},formData:function(e){return e.serializeArray()},add:function(e,t){if(e.isDefaultPrevented()){return false}if(t.autoUpload||t.autoUpload!==false&&m(this).fileupload("option","autoUpload")){t.process().done(function(){t.submit()})}},processData:false,contentType:false,cache:false},_specialOptions:["fileInput","dropZone","pasteZone","multipart","forceIframeTransport"],_blobSlice:m.support.blobSlice&&function(){var e=this.slice||this.webkitSlice||this.mozSlice;return e.apply(this,arguments)},_BitrateTimer:function(){this.timestamp=Date.now?Date.now():(new Date).getTime();this.loaded=0;this.bitrate=0;this.getBitrate=function(e,t,i){var r=e-this.timestamp;if(!this.bitrate||!i||r>i){this.bitrate=(t-this.loaded)*(1e3/r)*8;this.loaded=t;this.timestamp=e}return this.bitrate}},_isXHRUpload:function(e){return!e.forceIframeTransport&&(!e.multipart&&m.support.xhrFileUpload||m.support.xhrFormDataFileUpload)},_getFormData:function(e){var i;if(m.type(e.formData)==="function"){return e.formData(e.form)}if(m.isArray(e.formData)){return e.formData}if(m.type(e.formData)==="object"){i=[];m.each(e.formData,function(e,t){i.push({name:e,value:t})});return i}return[]},_getTotal:function(e){var i=0;m.each(e,function(e,t){i+=t.size||1});return i},_initProgressObject:function(e){var t={loaded:0,total:0,bitrate:0};if(e._progress){m.extend(e._progress,t)}else{e._progress=t}},_initResponseObject:function(e){var t;if(e._response){for(t in e._response){if(e._response.hasOwnProperty(t)){delete e._response[t]}}}else{e._response={}}},_onProgress:function(e,t){if(e.lengthComputable){var i=Date.now?Date.now():(new Date).getTime(),r;if(t._time&&t.progressInterval&&i-t._time<t.progressInterval&&e.loaded!==e.total){return}t._time=i;r=Math.floor(e.loaded/e.total*(t.chunkSize||t._progress.total))+(t.uploadedBytes||0);this._progress.loaded+=r-t._progress.loaded;this._progress.bitrate=this._bitrateTimer.getBitrate(i,this._progress.loaded,t.bitrateInterval);t._progress.loaded=t.loaded=r;t._progress.bitrate=t.bitrate=t._bitrateTimer.getBitrate(i,r,t.bitrateInterval);this._trigger("progress",m.Event("progress",{delegatedEvent:e}),t);this._trigger("progressall",m.Event("progressall",{delegatedEvent:e}),this._progress)}},_initProgressListener:function(i){var r=this,e=i.xhr?i.xhr():m.ajaxSettings.xhr();if(e.upload){m(e.upload).bind("progress",function(e){var t=e.originalEvent;e.lengthComputable=t.lengthComputable;e.loaded=t.loaded;e.total=t.total;r._onProgress(e,i)});i.xhr=function(){return e}}},_isInstanceOf:function(e,t){return Object.prototype.toString.call(t)==="[object "+e+"]"},_initXHRData:function(i){var r=this,n,e=i.files[0],t=i.multipart||!m.support.xhrFileUpload,s=m.type(i.paramName)==="array"?i.paramName[0]:i.paramName;i.headers=m.extend({},i.headers);if(i.contentRange){i.headers["Content-Range"]=i.contentRange;i.headers["X-Chunk-Size"]=i.chunkSize}if(!t||i.blob||!this._isInstanceOf("File",e)){i.headers["Content-Disposition"]='attachment; filename="'+encodeURI(e.name)+'"'}if(!t){i.contentType=e.type||"application/octet-stream";i.data=i.blob||e}else if(m.support.xhrFormDataFileUpload){if(i.postMessage){n=this._getFormData(i);if(i.blob){n.push({name:s,value:i.blob})}else{m.each(i.files,function(e,t){n.push({name:m.type(i.paramName)==="array"&&i.paramName[e]||s,value:t})})}}else{if(r._isInstanceOf("FormData",i.formData)){n=i.formData}else{n=new FormData;m.each(this._getFormData(i),function(e,t){n.append(t.name,t.value)})}if(i.blob){n.append(s,i.blob,e.name)}else{m.each(i.files,function(e,t){if(r._isInstanceOf("File",t)||r._isInstanceOf("Blob",t)){n.append(m.type(i.paramName)==="array"&&i.paramName[e]||s,t,t.uploadName||t.name)}})}}i.data=n}i.blob=null},_initIframeSettings:function(e){var t=m("<a></a>").prop("href",e.url).prop("host");e.dataType="iframe "+(e.dataType||"");e.formData=this._getFormData(e);if(e.redirect&&t&&t!==location.host){e.formData.push({name:e.redirectParamName||"redirect",value:e.redirect})}},_initDataSettings:function(e){if(this._isXHRUpload(e)){if(!this._chunkedUpload(e,true)){if(!e.data){this._initXHRData(e)}this._initProgressListener(e)}if(e.postMessage){e.dataType="postmessage "+(e.dataType||"")}}else{this._initIframeSettings(e)}},_getParamName:function(e){var t=m(e.fileInput),r=e.paramName;if(!r){r=[];t.each(function(){var e=m(this),t=e.prop("name")||"files[]",i=(e.prop("files")||[1]).length;while(i){r.push(t);i-=1}});if(!r.length){r=[t.prop("name")||"files[]"]}}else if(!m.isArray(r)){r=[r]}return r},_initFormSettings:function(e){if(!e.form||!e.form.length){e.form=m(e.fileInput.prop("form"));if(!e.form.length){e.form=m(this.options.fileInput.prop("form"))}}e.paramName=this._getParamName(e);if(!e.url){e.url=e.form.prop("action")||location.href}e.type=(e.type||m.type(e.form.prop("method"))==="string"&&e.form.prop("method")||"").toUpperCase();if(e.type!=="POST"&&e.type!=="PUT"&&e.type!=="PATCH"){e.type="POST"}if(!e.formAcceptCharset){e.formAcceptCharset=e.form.attr("accept-charset")}},_getAJAXSettings:function(e){var t=m.extend({},this.options,e);this._initFormSettings(t);this._initDataSettings(t);return t},_getDeferredState:function(e){if(e.state){return e.state()}if(e.isResolved()){return"resolved"}if(e.isRejected()){return"rejected"}return"pending"},_enhancePromise:function(e){e.success=e.done;e.error=e.fail;e.complete=e.always;return e},_getXHRPromise:function(e,t,i){var r=m.Deferred(),n=r.promise();t=t||this.options.context||n;if(e===true){r.resolveWith(t,i)}else if(e===false){r.rejectWith(t,i)}n.abort=r.promise;return this._enhancePromise(n)},_addConvenienceMethods:function(e,i){var r=this,n=function(e){return m.Deferred().resolveWith(r,e).promise()};i.process=function(e,t){if(e||t){i._processQueue=this._processQueue=(this._processQueue||n([this])).pipe(function(){if(i.errorThrown){return m.Deferred().rejectWith(r,[i]).promise()}return n(arguments)}).pipe(e,t)}return this._processQueue||n([this])};i.submit=function(){if(this.state()!=="pending"){i.jqXHR=this.jqXHR=r._trigger("submit",m.Event("submit",{delegatedEvent:e}),this)!==false&&r._onSend(e,this)}return this.jqXHR||r._getXHRPromise()};i.abort=function(){if(this.jqXHR){return this.jqXHR.abort()}this.errorThrown="abort";r._trigger("fail",null,this);return r._getXHRPromise(false)};i.state=function(){if(this.jqXHR){return r._getDeferredState(this.jqXHR)}if(this._processQueue){return r._getDeferredState(this._processQueue)}};i.processing=function(){return!this.jqXHR&&this._processQueue&&r._getDeferredState(this._processQueue)==="pending"};i.progress=function(){return this._progress};i.response=function(){return this._response}},_getUploadedBytes:function(e){var t=e.getResponseHeader("Range"),i=t&&t.split("-"),r=i&&i.length>1&&parseInt(i[1],10);return r&&r+1},_chunkedUpload:function(s,e){s.uploadedBytes=s.uploadedBytes||0;var o=this,t=s.files[0],a=t.size,l=s.uploadedBytes,i=s.maxChunkSize||a,p=this._blobSlice,f=m.Deferred(),r=f.promise(),u,d;if(!(this._isXHRUpload(s)&&p&&(l||i<a))||s.data){return false}if(e){return true}if(l>=a){t.error=s.i18n("uploadedBytes");return this._getXHRPromise(false,s.context,[null,"error",t.error])}d=function(){var r=m.extend({},s),n=r._progress.loaded;r.blob=p.call(t,l,l+i,t.type);r.chunkSize=r.blob.size;r.contentRange="bytes "+l+"-"+(l+r.chunkSize-1)+"/"+a;o._initXHRData(r);o._initProgressListener(r);u=(o._trigger("chunksend",null,r)!==false&&m.ajax(r)||o._getXHRPromise(false,r.context)).done(function(e,t,i){l=o._getUploadedBytes(i)||l+r.chunkSize;if(n+r.chunkSize-r._progress.loaded){o._onProgress(m.Event("progress",{lengthComputable:true,loaded:l-r.uploadedBytes,total:l-r.uploadedBytes}),r)}s.uploadedBytes=r.uploadedBytes=l;r.result=e;r.textStatus=t;r.jqXHR=i;o._trigger("chunkdone",null,r);o._trigger("chunkalways",null,r);if(l<a){d()}else{f.resolveWith(r.context,[e,t,i])}}).fail(function(e,t,i){r.jqXHR=e;r.textStatus=t;r.errorThrown=i;o._trigger("chunkfail",null,r);o._trigger("chunkalways",null,r);f.rejectWith(r.context,[e,t,i])})};this._enhancePromise(r);r.abort=function(){return u.abort()};d();return r},_beforeSend:function(e,t){if(this._active===0){this._trigger("start");this._bitrateTimer=new this._BitrateTimer;this._progress.loaded=this._progress.total=0;this._progress.bitrate=0}this._initResponseObject(t);this._initProgressObject(t);t._progress.loaded=t.loaded=t.uploadedBytes||0;t._progress.total=t.total=this._getTotal(t.files)||1;t._progress.bitrate=t.bitrate=0;this._active+=1;this._progress.loaded+=t.loaded;this._progress.total+=t.total},_onDone:function(e,t,i,r){var n=r._progress.total,s=r._response;if(r._progress.loaded<n){this._onProgress(m.Event("progress",{lengthComputable:true,loaded:n,total:n}),r)}s.result=r.result=e;s.textStatus=r.textStatus=t;s.jqXHR=r.jqXHR=i;this._trigger("done",null,r)},_onFail:function(e,t,i,r){var n=r._response;if(r.recalculateProgress){this._progress.loaded-=r._progress.loaded;this._progress.total-=r._progress.total}n.jqXHR=r.jqXHR=e;n.textStatus=r.textStatus=t;n.errorThrown=r.errorThrown=i;this._trigger("fail",null,r)},_onAlways:function(e,t,i,r){this._trigger("always",null,r)},_onSend:function(e,t){if(!t.submit){this._addConvenienceMethods(e,t)}var n=this,i,r,s,o,a=n._getAJAXSettings(t),l=function(){n._sending+=1;a._bitrateTimer=new n._BitrateTimer;i=i||((r||n._trigger("send",m.Event("send",{delegatedEvent:e}),a)===false)&&n._getXHRPromise(false,a.context,r)||n._chunkedUpload(a)||m.ajax(a)).done(function(e,t,i){n._onDone(e,t,i,a)}).fail(function(e,t,i){n._onFail(e,t,i,a)}).always(function(e,t,i){n._onAlways(e,t,i,a);n._sending-=1;n._active-=1;if(a.limitConcurrentUploads&&a.limitConcurrentUploads>n._sending){var r=n._slots.shift();while(r){if(n._getDeferredState(r)==="pending"){r.resolve();break}r=n._slots.shift()}}if(n._active===0){n._trigger("stop")}});return i};this._beforeSend(e,a);if(this.options.sequentialUploads||this.options.limitConcurrentUploads&&this.options.limitConcurrentUploads<=this._sending){if(this.options.limitConcurrentUploads>1){s=m.Deferred();this._slots.push(s);o=s.pipe(l)}else{this._sequence=this._sequence.pipe(l,l);o=this._sequence}o.abort=function(){r=[undefined,"abort","abort"];if(!i){if(s){s.rejectWith(a.context,r)}return l()}return i.abort()};return this._enhancePromise(o)}return l()},_onAdd:function(r,n){var s=this,o=true,e=m.extend({},this.options,n),t=n.files,i=t.length,a=e.limitMultiFileUploads,l=e.limitMultiFileUploadSize,p=e.limitMultiFileUploadSizeOverhead,f=0,u=this._getParamName(e),d,h,c,g,_=0;if(l&&(!i||t[0].size===undefined)){l=undefined}if(!(e.singleFileUploads||a||l)||!this._isXHRUpload(e)){c=[t];d=[u]}else if(!(e.singleFileUploads||l)&&a){c=[];d=[];for(g=0;g<i;g+=a){c.push(t.slice(g,g+a));h=u.slice(g,g+a);if(!h.length){h=u}d.push(h)}}else if(!e.singleFileUploads&&l){c=[];d=[];for(g=0;g<i;g=g+1){f+=t[g].size+p;if(g+1===i||f+t[g+1].size+p>l||a&&g+1-_>=a){c.push(t.slice(_,g+1));h=u.slice(_,g+1);if(!h.length){h=u}d.push(h);_=g+1;f=0}}}else{d=u}n.originalFiles=t;m.each(c||t,function(e,t){var i=m.extend({},n);i.files=c?t:[t];i.paramName=d[e];s._initResponseObject(i);s._initProgressObject(i);s._addConvenienceMethods(r,i);o=s._trigger("add",m.Event("add",{delegatedEvent:r}),i);return o});return o},_replaceFileInput:function(i){var r=i.clone(true);m("<form></form>").append(r)[0].reset();i.after(r).detach();m.cleanData(i.unbind("remove"));this.options.fileInput=this.options.fileInput.map(function(e,t){if(t===i[0]){return r[0]}return t});if(i[0]===this.element[0]){this.element=r}},_handleFileTreeEntry:function(t,i){var r=this,n=m.Deferred(),s=function(e){if(e&&!e.entry){e.entry=t}n.resolve([e])},e;i=i||"";if(t.isFile){if(t._file){t._file.relativePath=i;n.resolve(t._file)}else{t.file(function(e){e.relativePath=i;n.resolve(e)},s)}}else if(t.isDirectory){e=t.createReader();e.readEntries(function(e){r._handleFileTreeEntries(e,i+t.name+"/").done(function(e){n.resolve(e)}).fail(s)},s)}else{n.resolve([])}return n.promise()},_handleFileTreeEntries:function(e,t){var i=this;return m.when.apply(m,m.map(e,function(e){return i._handleFileTreeEntry(e,t)})).pipe(function(){return Array.prototype.concat.apply([],arguments)})},_getDroppedFiles:function(e){e=e||{};var t=e.items;if(t&&t.length&&(t[0].webkitGetAsEntry||t[0].getAsEntry)){return this._handleFileTreeEntries(m.map(t,function(e){var t;if(e.webkitGetAsEntry){t=e.webkitGetAsEntry();if(t){t._file=e.getAsFile()}return t}return e.getAsEntry()}))}return m.Deferred().resolve(m.makeArray(e.files)).promise()},_getSingleFileInputFiles:function(e){e=m(e);var t=e.prop("webkitEntries")||e.prop("entries"),i,r;if(t&&t.length){return this._handleFileTreeEntries(t)}i=m.makeArray(e.prop("files"));if(!i.length){r=e.prop("value");if(!r){return m.Deferred().resolve([]).promise()}i=[{name:r.replace(/^.*\\/,"")}]}else if(i[0].name===undefined&&i[0].fileName){m.each(i,function(e,t){t.name=t.fileName;t.size=t.fileSize})}return m.Deferred().resolve(i).promise()},_getFileInputFiles:function(e){if(!(e instanceof m)||e.length===1){return this._getSingleFileInputFiles(e)}return m.when.apply(m,m.map(e,this._getSingleFileInputFiles)).pipe(function(){return Array.prototype.concat.apply([],arguments)})},_onChange:function(t){var i=this,r={fileInput:m(t.target),form:m(t.target.form)};this._getFileInputFiles(r.fileInput).always(function(e){r.files=e;if(i.options.replaceFileInput){i._replaceFileInput(r.fileInput)}if(i._trigger("change",m.Event("change",{delegatedEvent:t}),r)!==false){i._onAdd(t,r)}})},_onPaste:function(e){var t=e.originalEvent&&e.originalEvent.clipboardData&&e.originalEvent.clipboardData.items,r={files:[]};if(t&&t.length){m.each(t,function(e,t){var i=t.getAsFile&&t.getAsFile();if(i){r.files.push(i)}});if(this._trigger("paste",m.Event("paste",{delegatedEvent:e}),r)!==false){this._onAdd(e,r)}}},_onDrop:function(t){t.dataTransfer=t.originalEvent&&t.originalEvent.dataTransfer;var i=this,e=t.dataTransfer,r={};if(e&&e.files&&e.files.length){t.preventDefault();this._getDroppedFiles(e).always(function(e){r.files=e;if(i._trigger("drop",m.Event("drop",{delegatedEvent:t}),r)!==false){i._onAdd(t,r)}})}},_onDragOver:function(e){e.dataTransfer=e.originalEvent&&e.originalEvent.dataTransfer;var t=e.dataTransfer;if(t&&m.inArray("Files",t.types)!==-1&&this._trigger("dragover",m.Event("dragover",{delegatedEvent:e}))!==false){e.preventDefault();t.dropEffect="copy"}},_initEventHandlers:function(){if(this._isXHRUpload(this.options)){this._on(this.options.dropZone,{dragover:this._onDragOver,drop:this._onDrop});this._on(this.options.pasteZone,{paste:this._onPaste})}if(m.support.fileInput){this._on(this.options.fileInput,{change:this._onChange})}},_destroyEventHandlers:function(){this._off(this.options.dropZone,"dragover drop");this._off(this.options.pasteZone,"paste");this._off(this.options.fileInput,"change")},_setOption:function(e,t){var i=m.inArray(e,this._specialOptions)!==-1;if(i){this._destroyEventHandlers()}this._super(e,t);if(i){this._initSpecialOptions();this._initEventHandlers()}},_initSpecialOptions:function(){var e=this.options;if(e.fileInput===undefined){e.fileInput=this.element.is('input[type="file"]')?this.element:this.element.find('input[type="file"]')}else if(!(e.fileInput instanceof m)){e.fileInput=m(e.fileInput)}if(!(e.dropZone instanceof m)){e.dropZone=m(e.dropZone)}if(!(e.pasteZone instanceof m)){e.pasteZone=m(e.pasteZone)}},_getRegExp:function(e){var t=e.split("/"),i=t.pop();t.shift();return new RegExp(t.join("/"),i)},_isRegExpOption:function(e,t){return e!=="url"&&m.type(t)==="string"&&/^\/.*\/[igm]{0,3}$/.test(t)},_initDataAttributes:function(){var i=this,r=this.options;m.each(m(this.element[0].cloneNode(false)).data(),function(e,t){if(i._isRegExpOption(e,t)){t=i._getRegExp(t)}r[e]=t})},_create:function(){this._initDataAttributes();this._initSpecialOptions();this._slots=[];this._sequence=this._getXHRPromise(true);this._sending=this._active=0;this._initProgressObject(this);this._initEventHandlers()},active:function(){return this._active},progress:function(){return this._progress},add:function(t){var i=this;if(!t||this.options.disabled){return}if(t.fileInput&&!t.files){this._getFileInputFiles(t.fileInput).always(function(e){t.files=e;i._onAdd(null,t)})}else{t.files=m.makeArray(t.files);this._onAdd(null,t)}},send:function(t){if(t&&!this.options.disabled){if(t.fileInput&&!t.files){var i=this,r=m.Deferred(),e=r.promise(),n,s;e.abort=function(){s=true;if(n){return n.abort()}r.reject(null,"abort","abort");return e};this._getFileInputFiles(t.fileInput).always(function(e){if(s){return}if(!e.length){r.reject();return}t.files=e;n=i._onSend(null,t).then(function(e,t,i){r.resolve(e,t,i)},function(e,t,i){r.reject(e,t,i)})});return this._enhancePromise(e)}t.files=m.makeArray(t.files);if(t.files.length){return this._onSend(null,t)}}return this._getXHRPromise(false,t&&t.context)}})});