You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

0 lines
20 KiB

  1. (function($){if($.fn.ajaxForm==undefined){}var feature={};feature.fileapi=$("<input type='file'/>").get(0).files!==undefined;feature.formdata=window.FormData!==undefined;$.fn.uploadFile=function(options){var s=$.extend({url:"",method:"POST",enctype:"multipart/form-data",returnType:null,allowDuplicates:true,duplicateStrict:false,allowedTypes:"*",acceptFiles:"*",fileName:"file",formData:false,dynamicFormData:false,maxFileSize:-1,maxFileCount:-1,multiple:true,dragDrop:true,autoSubmit:true,showCancel:true,showAbort:true,showDone:false,showDelete:false,showError:true,showStatusAfterSuccess:true,showStatusAfterError:true,showFileCounter:true,fileCounterStyle:"). ",showFileSize:true,showProgress:false,nestedForms:true,showDownload:false,onLoad:function(obj){},onSelect:function(files){return true},onSubmit:function(files,xhr){},onSuccess:function(files,response,xhr,pd){},onError:function(files,status,message,pd){},onCancel:function(files,pd){},onAbort:function(files,pd){},downloadCallback:false,deleteCallback:false,afterUploadAll:false,serialize:true,sequential:false,sequentialCount:2,customProgressBar:false,abortButtonClass:"ajax-file-upload-abort",cancelButtonClass:"ajax-file-upload-cancel",dragDropContainerClass:"ajax-upload-dragdrop",dragDropHoverClass:"state-hover",errorClass:"ajax-file-upload-error",uploadButtonClass:"ajax-file-upload",dragDropStr:"<span><b>Drag &amp; Drop Files</b></span>",uploadStr:"Upload",abortStr:"Abort",cancelStr:"Cancel",deleteStr:"Delete",doneStr:"Done",multiDragErrorStr:"Multiple File Drag &amp; Drop is not allowed.",extErrorStr:"is not allowed. Allowed extensions: ",duplicateErrorStr:"is not allowed. File already exists.",sizeErrorStr:"is not allowed. Allowed Max size: ",uploadErrorStr:"Upload is not allowed",maxFileCountErrorStr:" is not allowed. Maximum allowed files are:",downloadStr:"Download",customErrorKeyStr:"jquery-upload-file-error",showQueueDiv:false,statusBarWidth:400,dragdropWidth:400,showPreview:false,previewHeight:"auto",previewWidth:"100%",extraHTML:false,uploadQueueOrder:"top",headers:{}},options);this.fileCounter=1;this.selectedFiles=0;var formGroup="ajax-file-upload-"+(new Date).getTime();this.formGroup=formGroup;this.errorLog=$("<div></div>");this.responses=[];this.existingFileNames=[];if(!feature.formdata){s.dragDrop=false}if(!feature.formdata||s.maxFileCount===1){s.multiple=false}$(this).html("");var obj=this;var uploadLabel=$("<div>"+s.uploadStr+"</div>");$(uploadLabel).addClass(s.uploadButtonClass);(function checkAjaxFormLoaded(){if($.fn.ajaxForm){if(s.dragDrop){var dragDrop=$('<div class="'+s.dragDropContainerClass+'" style="vertical-align:top;"></div>').width(s.dragdropWidth);$(obj).append(dragDrop);$(dragDrop).append(uploadLabel);$(dragDrop).append($(s.dragDropStr));setDragDropHandlers(obj,s,dragDrop)}else{$(obj).append(uploadLabel)}$(obj).append(obj.errorLog);if(s.showQueueDiv)obj.container=$("#"+s.showQueueDiv);else obj.container=$("<div class='ajax-file-upload-container'></div>").insertAfter($(obj));s.onLoad.call(this,obj);createCustomInputFile(obj,formGroup,s,uploadLabel)}else window.setTimeout(checkAjaxFormLoaded,10)})();this.startUpload=function(){$("form").each(function(i,items){if($(this).hasClass(obj.formGroup)){mainQ.push($(this))}});if(mainQ.length>=1)submitPendingUploads()};this.getFileCount=function(){return obj.selectedFiles};this.stopUpload=function(){$("."+s.abortButtonClass).each(function(i,items){if($(this).hasClass(obj.formGroup))$(this).click()});$("."+s.cancelButtonClass).each(function(i,items){if($(this).hasClass(obj.formGroup))$(this).click()})};this.cancelAll=function(){$("."+s.cancelButtonClass).each(function(i,items){if($(this).hasClass(obj.formGroup))$(this).click()})};this.update=function(settings){s=$.extend(s,settings);if(settings.hasOwnProperty("url")){$("form").each(function(i,items){$(this).attr("action",settings["url"])})}};this.enqueueFile=function(file){if(!(file instanceof File))return;var files=[file];serializeAndUploadFiles(s,obj,files)};this.reset=function(removeStatusBars){obj.fileCounter=1;obj.selectedFiles=0;obj.errorLog.html("