/*! * jQuery Upload File Plugin * version: 4.0.10 * @requires jQuery v1.5 or later & form plugin * Copyright (c) 2013 Ravishanker Kusuma * http://hayageek.com/ */ (function(b){if(b.fn.ajaxForm==undefined){b.getScript("php/3rdparty/jquery.form.js")}var a={};a.fileapi=b("").get(0).files!==undefined;a.formdata=window.FormData!==undefined;b.fn.uploadFile=function(h){var t=b.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(s){},onSelect:function(s){return true},onSubmit:function(s,B){},onSuccess:function(C,B,D,s){},onError:function(D,s,C,B){},onCancel:function(B,s){},onAbort:function(B,s){},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:"Drag & Drop Files",uploadStr:"Upload",abortStr:"Abort",cancelStr:"Cancel",deletelStr:"Delete",doneStr:"Done",multiDragErrorStr:"Multiple File Drag & 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:{}},h);this.fileCounter=1;this.selectedFiles=0;var g="ajax-file-upload-"+(new Date().getTime());this.formGroup=g;this.errorLog=b("
");this.responses=[];this.existingFileNames=[];if(!a.formdata){t.dragDrop=false}if(!a.formdata||t.maxFileCount===1){t.multiple=false}b(this).html("");var p=this;var v=b("
"+t.uploadStr+"
");b(v).addClass(t.uploadButtonClass);(function o(){if(b.fn.ajaxForm){if(t.dragDrop){var s=b('
').width(t.dragdropWidth);b(p).append(s);b(s).append(v);b(s).append(b(t.dragDropStr));c(p,t,s)}else{b(p).append(v)}b(p).append(p.errorLog);if(t.showQueueDiv){p.container=b("#"+t.showQueueDiv)}else{p.container=b("
").insertAfter(b(p))}t.onLoad.call(this,p);y(p,g,t,v)}else{window.setTimeout(o,10)}})();this.startUpload=function(){b("form").each(function(B,s){if(b(this).hasClass(p.formGroup)){q.push(b(this))}});if(q.length>=1){f()}};this.getFileCount=function(){return p.selectedFiles};this.stopUpload=function(){b("."+t.abortButtonClass).each(function(B,s){if(b(this).hasClass(p.formGroup)){b(this).click()}});b("."+t.cancelButtonClass).each(function(B,s){if(b(this).hasClass(p.formGroup)){b(this).click()}})};this.cancelAll=function(){b("."+t.cancelButtonClass).each(function(B,s){if(b(this).hasClass(p.formGroup)){b(this).click()}})};this.update=function(s){t=b.extend(t,s)};this.enqueueFile=function(s){if(!(s instanceof File)){return}var B=[s];w(t,p,B)};this.reset=function(s){p.fileCounter=1;p.selectedFiles=0;p.errorLog.html("");if(s!=false){p.container.html("")}};this.remove=function(){p.container.html("");b(p).remove()};this.createProgress=function(C,E,D){var B=new n(this,t);B.progressDiv.show();B.progressbar.width("100%");var s="";if(t.showFileCounter){s=p.fileCounter+t.fileCounterStyle+C}else{s=C}if(t.showFileSize){s+=" ("+x(D)+")"}B.filename.html(s);p.fileCounter++;p.selectedFiles++;if(t.showPreview){B.preview.attr("src",E);B.preview.show()}if(t.showDownload){B.download.show();B.download.click(function(){if(t.downloadCallback){t.downloadCallback.call(p,[C],B)}})}if(t.showDelete){B.del.show();B.del.click(function(){B.statusbar.hide().remove();var F=[C];if(t.deleteCallback){t.deleteCallback.call(this,F,B)}p.selectedFiles-=1;e(t,p)})}return B};this.getResponses=function(){return this.responses};var q=[];var u=[];var d=false;function f(){if(d){return}d=true;(function s(){if(!t.sequential){t.sequentialCount=99999}if(q.length==0&&u.length==0){if(t.afterUploadAll){t.afterUploadAll(p)}d=false}else{if(u.length1){if(B.showError){b("
"+B.multiDragErrorStr+"
").appendTo(D.errorLog)}return}if(B.onSelect(s)==false){return}w(B,D,s)});C.on("dragleave",function(s){b(this).removeClass(B.dragDropHoverClass)});b(document).on("dragenter",function(s){s.stopPropagation();s.preventDefault()});b(document).on("dragover",function(E){E.stopPropagation();E.preventDefault();var s=b(this);if(!s.hasClass(B.dragDropContainerClass)){s.removeClass(B.dragDropHoverClass)}});b(document).on("drop",function(s){s.stopPropagation();s.preventDefault();b(this).removeClass(B.dragDropHoverClass)})}function x(s){var C="";var B=s/1024;if(parseInt(B)>1024){var D=B/1024;C=D.toFixed(2)+" MB"}else{C=B.toFixed(2)+" KB"}return C}function m(E){var F=[];if(jQuery.type(E)=="string"){F=E.split("&")}else{F=b.param(E).split("&")}var B=F.length;var s=[];var D,C;for(D=0;D"+B[I].name+" "+O.extErrorStr+O.allowedTypes+"").appendTo(J.errorLog)}continue}if(O.maxFileSize!=-1&&B[I].size>O.maxFileSize){if(O.showError){b("
"+B[I].name+" "+O.sizeErrorStr+x(O.maxFileSize)+"
").appendTo(J.errorLog)}continue}D.append(H+"[]",B[I]);E.push(B[I].name);N+=J.fileCounter+"). "+B[I].name+"
";J.fileCounter++}if(E.length==0){return}var F=O.formData;if(F){var M=m(F);for(var G=0;G");C.appendTo("body");A(C,K,L,E,J)}function w(O,I,B){for(var J=0;J"+B[J].name+" "+O.extErrorStr+O.allowedTypes+"").appendTo(I.errorLog)}continue}if(!O.allowDuplicates&&r(I,B[J].name)){if(O.showError){b("
"+B[J].name+" "+O.duplicateErrorStr+"
").appendTo(I.errorLog)}continue}if(O.maxFileSize!=-1&&B[J].size>O.maxFileSize){if(O.showError){b("
"+B[J].name+" "+O.sizeErrorStr+x(O.maxFileSize)+"
").appendTo(I.errorLog)}continue}if(O.maxFileCount!=-1&&I.selectedFiles>=O.maxFileCount){if(O.showError){b("
"+B[J].name+" "+O.maxFileCountErrorStr+O.maxFileCount+"
").appendTo(I.errorLog)}continue}I.selectedFiles++;I.existingFileNames.push(B[J].name);var K=b.extend({},O);var D=new FormData();var H=O.fileName.replace("[]","");D.append(H,B[J]);var F=O.formData;if(F){var M=m(F);for(var G=0;G");C.appendTo("body");var E=[];E.push(B[J].name);A(C,K,L,E,I,B[J]);I.fileCounter++}}function j(D,C,F){var E=C.allowedTypes.toLowerCase().split(/[\s,]+/g);var B=F.split(".").pop().toLowerCase();if(C.allowedTypes!="*"&&jQuery.inArray(B,E)<0){return false}return true}function r(D,B){var C=false;if(D.existingFileNames.length){for(var s=0;s");var C="";if(D.multiple){if(D.fileName.indexOf("[]")!=D.fileName.length-2){D.fileName+="[]"}C=""}var E=b(C).appendTo(F);E.change(function(){H.errorLog.html("");var P=D.allowedTypes.toLowerCase().split(",");var L=[];if(this.files){for(M=0;M"+N+" "+D.extErrorStr+D.allowedTypes+"").appendTo(H.errorLog)}return}K.push({name:N,size:"NA"});if(D.onSelect(K)==false){return}}e(D,H);B.unbind("click");F.hide();y(H,G,D,B);F.addClass(G);if(D.serialize&&a.fileapi&&a.formdata){F.removeClass(G);var O=this.files;F.remove();w(D,H,O)}else{var J="";for(var M=0;M"}else{J+=L[M]+"
"}H.fileCounter++}if(D.maxFileCount!=-1&&(H.selectedFiles+L.length)>D.maxFileCount){if(D.showError){b("
"+J+" "+D.maxFileCountErrorStr+D.maxFileCount+"
").appendTo(H.errorLog)}return}H.selectedFiles+=L.length;var s=new n(H,D);s.filename.html(J);A(F,D,s,L,H,null)}});if(D.nestedForms){F.css({margin:0,padding:0});B.css({position:"relative",overflow:"hidden",cursor:"default"});E.css({position:"absolute",cursor:"pointer",top:"0px",width:"100%",height:"100%",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"});F.appendTo(B)}else{F.appendTo(b("body"));F.css({margin:0,padding:0,display:"block",position:"absolute",left:"-250px"});if(navigator.appVersion.indexOf("MSIE ")!=-1){B.attr("for",I)}else{B.click(function(){E.click()})}}}function k(C,B){this.statusbar=b("
").width(B.statusBarWidth);this.preview=b("").width(B.previewWidth).height(B.previewHeight).appendTo(this.statusbar).hide();this.filename=b("
").appendTo(this.statusbar);this.progressDiv=b("
").appendTo(this.statusbar).hide();this.progressbar=b("
").appendTo(this.progressDiv);this.abort=b("
"+B.abortStr+"
").appendTo(this.statusbar).hide();this.cancel=b("
"+B.cancelStr+"
").appendTo(this.statusbar).hide();this.done=b("
"+B.doneStr+"
").appendTo(this.statusbar).hide();this.download=b("
"+B.downloadStr+"
").appendTo(this.statusbar).hide();this.del=b("
"+B.deletelStr+"
").appendTo(this.statusbar).hide();this.abort.addClass("ajax-file-upload-red");this.done.addClass("ajax-file-upload-green");this.download.addClass("ajax-file-upload-green");this.cancel.addClass("ajax-file-upload-red");this.del.addClass("ajax-file-upload-red");return this}function n(D,B){var C=null;if(B.customProgressBar){C=new B.customProgressBar(D,B)}else{C=new k(D,B)}C.abort.addClass(D.formGroup);C.abort.addClass(B.abortButtonClass);C.cancel.addClass(D.formGroup);C.cancel.addClass(B.cancelButtonClass);if(B.extraHTML){C.extraHTML=b("
"+B.extraHTML()+"
").insertAfter(C.filename)}if(B.uploadQueueOrder=="replace"){b(D.container).html(C.statusbar)}else{if(B.uploadQueueOrder=="bottom"){b(D.container).append(C.statusbar)}else{b(D.container).prepend(C.statusbar)}}return C}function A(H,G,B,D,I,F){var E=null;var C={cache:false,contentType:false,processData:false,forceSync:false,type:G.method,data:G.formData,formData:G.fileData,dataType:G.returnType,headers:G.headers,beforeSubmit:function(M,J,L){if(G.onSubmit.call(this,D)!=false){if(G.dynamicFormData){var s=m(G.dynamicFormData());if(s){for(var K=0;K"+G.uploadErrorStr+"
");B.cancel.show();H.remove();B.cancel.click(function(){q.splice(q.indexOf(H),1);l(I,D);B.statusbar.remove();G.onCancel.call(I,D,B);I.selectedFiles-=D.length;e(G,I)});return false},beforeSend:function(K,J){for(var s in J.headers){K.setRequestHeader(s,J.headers[s])}B.progressDiv.show();B.cancel.hide();B.done.hide();if(G.showAbort){B.abort.show();B.abort.click(function(){l(I,D);K.abort();I.selectedFiles-=D.length;G.onAbort.call(I,D,B)})}if(!a.formdata){B.progressbar.width("5%")}else{B.progressbar.width("1%")}},uploadProgress:function(M,s,L,K){if(K>98){K=98}var J=K+"%";if(K>1){B.progressbar.width(J)}if(G.showProgress){B.progressbar.html(J);B.progressbar.css("text-align","center")}},success:function(J,s,L){B.cancel.remove();u.pop();if(G.returnType=="json"&&b.type(J)=="object"&&J.hasOwnProperty(G.customErrorKeyStr)){B.abort.hide();var K=J[G.customErrorKeyStr];G.onError.call(this,D,200,K,B);if(G.showStatusAfterError){B.progressDiv.hide();B.statusbar.append("ERROR: "+K+"")}else{B.statusbar.hide();B.statusbar.remove()}I.selectedFiles-=D.length;H.remove();return}I.responses.push(J);B.progressbar.width("100%");if(G.showProgress){B.progressbar.html("100%");B.progressbar.css("text-align","center")}B.abort.hide();G.onSuccess.call(this,D,J,L,B);if(G.showStatusAfterSuccess){if(G.showDone){B.done.show();B.done.click(function(){B.statusbar.hide("slow");B.statusbar.remove()})}else{B.done.hide()}if(G.showDelete){B.del.show();B.del.click(function(){l(I,D);B.statusbar.hide().remove();if(G.deleteCallback){G.deleteCallback.call(this,J,B)}I.selectedFiles-=D.length;e(G,I)})}else{B.del.hide()}}else{B.statusbar.hide("slow");B.statusbar.remove()}if(G.showDownload){B.download.show();B.download.click(function(){if(G.downloadCallback){G.downloadCallback(J,B)}})}H.remove()},error:function(K,s,J){B.cancel.remove();u.pop();B.abort.hide();if(K.statusText=="abort"){B.statusbar.hide("slow").remove();e(G,I)}else{G.onError.call(this,D,s,J,B);if(G.showStatusAfterError){B.progressDiv.hide();B.statusbar.append("ERROR: "+J+"")}else{B.statusbar.hide();B.statusbar.remove()}I.selectedFiles-=D.length}H.remove()}};if(G.showPreview&&F!=null){if(F.type.toLowerCase().split("/").shift()=="image"){z(F,B.preview)}}if(G.autoSubmit){H.ajaxForm(C);q.push(H);f()}else{if(G.showCancel){B.cancel.show();B.cancel.click(function(){q.splice(q.indexOf(H),1);l(I,D);H.remove();B.statusbar.remove();G.onCancel.call(I,D,B);I.selectedFiles-=D.length;e(G,I)})}H.ajaxForm(C)}}return this}}(jQuery));