!function(e){void 0==e.fn.ajaxForm;var r={};r.fileapi=void 0!==e("").get(0).files,r.formdata=void 0!==window.FormData,e.fn.uploadFile=function(t){function o(){c.afterUploadAll&&!v&&(v=!0,function e(){0!=f.sCounter&&f.sCounter+f.fCounter==f.tCounter?(c.afterUploadAll(f),v=!1):window.setTimeout(e,100)}())}function a(r,t,o){o.on("dragenter",function(r){r.stopPropagation(),r.preventDefault(),e(this).css("border","2px dashed #ddd")}),o.on("dragover",function(e){e.stopPropagation(),e.preventDefault()}),o.on("drop",function(o){e(this).css("border","2px dashed #ddd"),o.preventDefault(),r.errorLog.html("");var a=o.originalEvent.dataTransfer.files;return!t.multiple&&a.length>1?void(t.showError&&e("
"+t.multiDragErrorStr+"
").appendTo(r.errorLog)):void(0!=t.onSelect(a)&&i(t,r,a))}),e(document).on("dragenter",function(e){e.stopPropagation(),e.preventDefault()}),e(document).on("dragover",function(e){e.stopPropagation(),e.preventDefault(),o.css("border","2px dashed #ddd")}),e(document).on("drop",function(e){e.stopPropagation(),e.preventDefault(),o.css("border","2px dashed #ddd")})}function s(r){var t=[];t="string"==jQuery.type(r)?r.split("&"):e.param(r).split("&");var o,a,s=t.length,i=[];for(o=0;or.maxFileSize)r.showError&&e("
"+r.sizeErrorStr+"
").appendTo(t.errorLog);else if(r.maxFileCount!=-1&&t.selectedFiles>=r.maxFileCount)r.showError&&e("
"+r.maxFileCountErrorStr+"
").appendTo(t.errorLog);else{t.selectedFiles++;var i=r,l=new FormData,d=r.fileName.replace("[]","");l.append(d,o[a]);var c=r.formData;if(c)for(var h=s(c),f=0;f");g.appendTo("body");var b=[];b.push(o[a].name),p(g,i,m,b,t),t.fileCounter++}else r.showError&&e("
"+r.extErrorStr+"
").appendTo(t.errorLog)}function n(e,r,t){var o=r.allowedTypes.toLowerCase().split(","),a=t.split(".").pop().toLowerCase();return!("*"!=r.allowedTypes&&jQuery.inArray(a,o)<0)}function l(r,t){if(r.showFileCounter){var o=e(".upload-filename").length;t.fileCounter=o+1,e(".upload-filename").each(function(t,a){var s=e(this).html().split(r.fileCounterStyle),i=(parseInt(s[0])-1,o+r.fileCounterStyle+s[1]);e(this).html(i),o--})}}function d(t,o,a,s){var c="ajax-upload-id-"+(new Date).getTime(),h=e("
"),f="";a.multiple&&(a.fileName.indexOf("[]")!=a.fileName.length-2&&(a.fileName+="[]"),f="");var m=e(f).appendTo(h);m.change(function(){t.errorLog.html("");var c=(a.allowedTypes.toLowerCase().split(","),[]);if(this.files){for(b=0;b"+a.extErrorStr+"").appendTo(t.errorLog));if(m.push({name:f,size:"NA"}),0==a.onSelect(m))return}if(l(a,t),s.unbind("click"),h.hide(),d(t,o,a,s),h.addClass(o),r.fileapi&&r.formdata){h.removeClass(o);var v=this.files;i(a,t,v)}else{for(var g="",b=0;b":c[b]+"
",t.fileCounter++;if(a.maxFileCount!=-1&&t.selectedFiles+c.length>a.maxFileCount)return void(a.showError&&e("
"+a.maxFileCountErrorStr+"
").appendTo(t.errorLog));t.selectedFiles+=c.length;var w=new u(t,a);w.filename.html(g),p(h,a,w,c,t)}}),h.css({margin:0,padding:0});var v=e(s).width()+10;10==v&&(v=120);var g=s.height()+10;10==g&&(g=35),s.css({position:"relative",overflow:"hidden",cursor:"default"}),m.css({position:"absolute",cursor:"pointer",top:"0px",width:"100%",height:"34px",left:"0px","z-index":"100",opacity:"0.0",filter:"alpha(opacity=0)","-ms-filter":"alpha(opacity=0)","-khtml-opacity":"0.0","-moz-opacity":"0.0"}),h.appendTo(s)}function u(r,t){return this.statusbar=e("
"),this.filename=e("
").appendTo(this.statusbar),this.progressDiv=e("
").appendTo(this.statusbar).hide(),this.progressbar=e("
").appendTo(this.progressDiv),this.abort=e("
"+t.abortStr+"
").appendTo(this.statusbar).hide(),this.cancel=e("
"+t.cancelStr+"
").appendTo(this.statusbar).hide(),this.done=e("
"+t.doneStr+"
").appendTo(this.statusbar).hide(),this.del=e("
"+t.deletelStr+"
").appendTo(this.statusbar).hide(),r.errorLog.after(this.statusbar),this}function p(e,t,a,i,n){var d={cache:!1,contentType:!1,processData:!1,forceSync:!1,data:t.formData,formData:t.fileData,dataType:t.returnType,beforeSubmit:function(r,l,d){if(0!=t.onSubmit.call(this,i)){var u=t.dynamicFormData();if(u){var p=s(u);if(p)for(var c=0;c"+t.uploadErrorStr+"
"),a.cancel.show(),e.remove(),a.cancel.click(function(){a.statusbar.remove()}),!1},beforeSend:function(e,o){a.progressDiv.show(),a.cancel.hide(),a.done.hide(),t.showAbort&&(a.abort.show(),a.abort.click(function(){e.abort(),n.selectedFiles-=i.length})),r.formdata?a.progressbar.width("1%"):a.progressbar.width("5%")},uploadProgress:function(e,r,o,s){s>98&&(s=98);var i=s+"%";s>1&&a.progressbar.width(i),t.showProgress&&(a.progressbar.html(i),a.progressbar.css("text-align","center"))},success:function(r,o,s){n.responses.push(r),a.progressbar.width("100%"),t.showProgress&&(a.progressbar.html("100%"),a.progressbar.css("text-align","center")),a.abort.hide(),t.onSuccess.call(this,i,r,s),t.showStatusAfterSuccess?(t.showDone?(a.done.show(),a.done.click(function(){a.statusbar.hide("slow"),a.statusbar.remove()})):a.done.hide(),t.showDelete?(a.del.show(),a.del.click(function(){a.statusbar.hide().remove(),t.deleteCallback&&t.deleteCallback.call(this,r,a),n.selectedFiles-=i.length,l(t,n)})):a.del.hide()):(a.statusbar.hide("slow"),a.statusbar.remove()),e.remove(),n.sCounter+=i.length},error:function(r,o,s){a.abort.hide(),"abort"==r.statusText?(a.statusbar.hide("slow").remove(),l(t,n)):(t.onError.call(this,i,o,s),t.showStatusAfterError?(a.progressDiv.hide(),a.statusbar.append("ERROR: "+s+"")):(a.statusbar.hide(),a.statusbar.remove()),n.selectedFiles-=i.length),e.remove(),n.fCounter+=i.length}};t.autoSubmit?e.ajaxSubmit(d):(t.showCancel&&(a.cancel.show(),a.cancel.click(function(){e.remove(),a.statusbar.remove(),n.selectedFiles-=i.length,l(t,n)})),e.ajaxForm(d))}var c=e.extend({url:"",method:"POST",enctype:"multipart/form-data",formData:null,returnType:null,allowedTypes:"*",fileName:"file",formData:{},dynamicFormData:function(){return{}},maxFileSize:-1,maxFileCount:-1,multiple:!0,dragDrop:!0,autoSubmit:!0,showCancel:!0,showAbort:!0,showDone:!0,showDelete:!1,showError:!0,showStatusAfterSuccess:!0,showStatusAfterError:!0,showFileCounter:!0,fileCounterStyle:"). ",showProgress:!1,onSelect:function(e){return!0},onSubmit:function(e,r){},onSuccess:function(e,r,t){},onError:function(e,r,t){},deleteCallback:!1,afterUploadAll:!1,uploadButtonClass:"upload",dragDropStr:"",abortStr:"Abort",cancelStr:"Cancel",deletelStr:"Delete",doneStr:"Done",multiDragErrorStr:"Multiple File Drag & Drop is not allowed.",extErrorStr:"",sizeErrorStr:"",uploadErrorStr:"Upload is not allowed",maxFileCountErrorStr:""},t);this.fileCounter=1,this.selectedFiles=0,this.fCounter=0,this.sCounter=0,this.tCounter=0;var h="upload-"+(new Date).getTime();this.formGroup=h,this.hide(),this.errorLog=e("
"),this.after(this.errorLog),this.responses=[],r.formdata||(c.dragDrop=!1),r.formdata||(c.multiple=!1);var f=this,m=e("
"+e(this).html()+"
");e(m).addClass(c.uploadButtonClass),function r(){if(e.fn.ajaxForm){if(c.dragDrop){var t=e('
');e(f).before(t),e(t).append(m),e(t).prepend(e(c.dragDropStr)),a(f,c,t)}else e(f).before(m);d(f,h,c,m)}else window.setTimeout(r,10)}(),this.startUpload=function(){e("."+this.formGroup).each(function(r,t){e(this).is("form")&&e(this).submit()})},this.stopUpload=function(){e(".upload-red").each(function(r,t){e(this).hasClass(f.formGroup)&&e(this).click()})},this.getResponses=function(){return this.responses};var v=!1;return this}}(jQuery);