/*!
* jQuery Upload File Plugin
* version: 3.1.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(("https:"==document.location.protocol?"https://":"http://")+"malsup.github.io/jquery.form.js")}var a={};a.fileapi=b(" ").get(0).files!==undefined;a.formdata=window.FormData!==undefined;b.fn.uploadFile=function(f){var p=b.extend({url:"",method:"POST",enctype:"multipart/form-data",returnType:null,allowDuplicates:true,duplicateStrict:false,allowedTypes:"*",acceptFiles:"*",fileName:"file",formData:{},dynamicFormData:function(){return{}},maxFileSize:-1,maxFileCount:-1,multiple:true,dragDrop:true,autoSubmit:true,showCancel:true,showAbort:true,showDone:true,showDelete:false,showError:true,showStatusAfterSuccess:true,showStatusAfterError:true,showFileCounter:true,fileCounterStyle:"). ",showProgress:false,nestedForms:true,showDownload:false,onLoad:function(s){},onSelect:function(s){return true},onSubmit:function(s,x){},onSuccess:function(y,x,z,s){},onError:function(z,s,y,x){},onCancel:function(x,s){},downloadCallback:false,deleteCallback:false,afterUploadAll: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 ",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:'100%',dragdropWidth:'100%',showPreview:false,previewHeight:"auto",previewWidth:"100%",uploadFolder:"uploads/"},f);this.fileCounter=1;this.selectedFiles=0;this.fCounter=0;this.sCounter=0;this.tCounter=0;var e="ajax-file-upload-"+(new Date().getTime());this.formGroup=e;this.hide();this.errorLog=b("
");this.after(this.errorLog);this.responses=[];this.existingFileNames=[];if(!a.formdata){p.dragDrop=false}if(!a.formdata){p.multiple=false}var n=this;var q=b(""+b(this).html()+"
");b(q).addClass(p.uploadButtonClass);(function l(){if(b.fn.ajaxForm){if(p.dragDrop){var s=b('
').width(p.dragdropWidth);b(n).before(s);b(s).append(q);b(s).append(b(p.dragDropStr));c(n,p,s)}else{b(n).before(q)}p.onLoad.call(this,n);k(n,e,p,q)}else{window.setTimeout(l,10)}})();this.startUpload=function(){b("."+this.formGroup).each(function(x,s){if(b(this).is("form")){b(this).submit()}})};this.getFileCount=function(){return n.selectedFiles};this.stopUpload=function(){b("."+p.abortButtonClass).each(function(x,s){if(b(this).hasClass(n.formGroup)){b(this).click()}})};this.cancelAll=function(){b("."+p.cancelButtonClass).each(function(x,s){if(b(this).hasClass(n.formGroup)){b(this).click()}})};this.update=function(s){p=b.extend(p,s)};this.createProgress=function(y){var x=new j(this,p);x.progressDiv.show();x.progressbar.width("100%");var s="";if(p.showFileCounter){s=n.fileCounter+p.fileCounterStyle+y}else{s=y}x.filename.html(s);n.fileCounter++;n.selectedFiles++;if(p.showPreview){x.preview.attr("src",p.uploadFolder+y);x.preview.show()}if(p.showDownload){x.download.show();x.download.click(function(){if(p.downloadCallback){p.downloadCallback.call(n,[y])}})}x.del.show();x.del.click(function(){var z=[y];if(p.deleteCallback){p.deleteCallback.call(this,z,x)}n.selectedFiles-=1;d(p,n)})};this.getResponses=function(){return this.responses};var m=false;function u(){if(p.afterUploadAll&&!m){m=true;(function s(){if(n.sCounter!=0&&(n.sCounter+n.fCounter==n.tCounter)){p.afterUploadAll(n);m=false}else{window.setTimeout(s,100)}})()}}function c(z,x,y){y.on("dragenter",function(s){s.stopPropagation();s.preventDefault();b(this).addClass(x.dragDropHoverClass)});y.on("dragover",function(A){A.stopPropagation();A.preventDefault();var s=b(this);if(s.hasClass(x.dragDropContainerClass)&&!s.hasClass(x.dragDropHoverClass)){s.addClass(x.dragDropHoverClass)}});y.on("drop",function(A){A.preventDefault();b(this).removeClass(x.dragDropHoverClass);z.errorLog.html("");var s=A.originalEvent.dataTransfer.files;if(!x.multiple&&s.length>1){if(x.showError){b(""+x.multiDragErrorStr+"
").appendTo(z.errorLog)}return}if(x.onSelect(s)==false){return}r(x,z,s)});y.on("dragleave",function(s){b(this).removeClass(x.dragDropHoverClass)});b(document).on("dragenter",function(s){s.stopPropagation();s.preventDefault()});b(document).on("dragover",function(A){A.stopPropagation();A.preventDefault();var s=b(this);if(!s.hasClass(x.dragDropContainerClass)){s.removeClass(x.dragDropHoverClass)}});b(document).on("drop",function(s){s.stopPropagation();s.preventDefault();b(this).removeClass(x.dragDropHoverClass)})}function t(s){var y="";var x=s/1024;if(parseInt(x)>1024){var z=x/1024;y=z.toFixed(2)+" MB"}else{y=x.toFixed(2)+" KB"}return y}function i(A){var B=[];if(jQuery.type(A)=="string"){B=A.split("&")}else{B=b.param(A).split("&")}var x=B.length;var s=[];var z,y;for(z=0;z"+x[F].name+" "+K.extErrorStr+K.allowedTypes+"").appendTo(E.errorLog)}continue}if(!K.allowDuplicates&&o(E,x[F].name)){if(K.showError){b(""+x[F].name+" "+K.duplicateErrorStr+"
").appendTo(E.errorLog)}continue}if(K.maxFileSize!=-1&&x[F].size>K.maxFileSize){if(K.showError){b(""+x[F].name+" "+K.sizeErrorStr+t(K.maxFileSize)+"
").appendTo(E.errorLog)}continue}if(K.maxFileCount!=-1&&E.selectedFiles>=K.maxFileCount){if(K.showError){b(""+x[F].name+" "+K.maxFileCountErrorStr+K.maxFileCount+"
").appendTo(E.errorLog)}continue}E.selectedFiles++;E.existingFileNames.push(x[F].name);var G=K;var z=new FormData();var D=K.fileName.replace("[]","");z.append(D,x[F]);var B=K.formData;if(B){var I=i(B);for(var C=0;C");y.appendTo("body");var A=[];A.push(x[F].name);w(y,G,H,A,E,x[F]);E.fileCounter++}}function g(z,y,B){var A=y.allowedTypes.toLowerCase().split(",");var x=B.split(".").pop().toLowerCase();if(y.allowedTypes!="*"&&jQuery.inArray(x,A)<0){return false}return true}function o(A,y){var z=false;if(A.existingFileNames.length){for(var s=0;s");var y=" ";if(z.multiple){if(z.fileName.indexOf("[]")!=z.fileName.length-2){z.fileName+="[]"}y=" "}var A=b(y).appendTo(B);A.change(function(){D.errorLog.html("");var L=z.allowedTypes.toLowerCase().split(",");var H=[];if(this.files){for(I=0;I"+J+" "+z.extErrorStr+z.allowedTypes+"").appendTo(D.errorLog)}return}G.push({name:J,size:"NA"});if(z.onSelect(G)==false){return}}d(z,D);x.unbind("click");B.hide();k(D,C,z,x);B.addClass(C);if(a.fileapi&&a.formdata){B.removeClass(C);var K=this.files;r(z,D,K)}else{var F="";for(var I=0;I"}else{F+=H[I]+" "}D.fileCounter++}if(z.maxFileCount!=-1&&(D.selectedFiles+H.length)>z.maxFileCount){if(z.showError){b(""+F+" "+z.maxFileCountErrorStr+z.maxFileCount+"
").appendTo(D.errorLog)}return}D.selectedFiles+=H.length;var s=new j(D,z);s.filename.html(F);w(B,z,s,H,D,null)}});if(z.nestedForms){B.css({margin:0,padding:0});x.css({position:"relative",overflow:"hidden",cursor:"default"});A.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"});B.appendTo(x)}else{B.appendTo(b("body"));B.css({margin:0,padding:0,display:"block",position:"absolute",left:"-250px"});if(navigator.appVersion.indexOf("MSIE ")!=-1){x.attr("for",E)}else{x.click(function(){A.click()})}}}function j(y,x){this.statusbar=b("
").width(x.statusBarWidth);this.preview=b(" ").width(x.previewWidth).height(x.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("
"+x.abortStr+"
").appendTo(this.statusbar).hide();this.cancel=b("
"+x.cancelStr+"
").appendTo(this.statusbar).hide();this.done=b("
"+x.doneStr+"
").appendTo(this.statusbar).hide();this.download=b("
"+x.downloadStr+"
").appendTo(this.statusbar).hide();this.del=b("
"+x.deletelStr+"
").appendTo(this.statusbar).hide();if(x.showQueueDiv){b("#"+x.showQueueDiv).append(this.statusbar)}else{y.errorLog.after(this.statusbar)}return this}function w(D,C,x,z,E,B){var A=null;var y={cache:false,contentType:false,processData:false,forceSync:false,type:C.method,data:C.formData,formData:C.fileData,dataType:C.returnType,beforeSubmit:function(J,G,I){if(C.onSubmit.call(this,z)!=false){var F=C.dynamicFormData();if(F){var s=i(F);if(s){for(var H=0;H
"+C.uploadErrorStr+" ");x.cancel.show();D.remove();x.cancel.click(function(){h(E,z);x.statusbar.remove();C.onCancel.call(E,z,x);E.selectedFiles-=z.length;d(C,E)});return false},beforeSend:function(F,s){x.progressDiv.show();x.cancel.hide();x.done.hide();if(C.showAbort){x.abort.show();x.abort.click(function(){h(E,z);F.abort();E.selectedFiles-=z.length})}if(!a.formdata){x.progressbar.width("5%")}else{x.progressbar.width("1%")}},uploadProgress:function(I,s,H,G){if(G>98){G=98}var F=G+"%";if(G>1){x.progressbar.width(F)}if(C.showProgress){x.progressbar.html(F);x.progressbar.css("text-align","center")}},success:function(F,s,H){if(C.returnType=="json"&&b.type(F)=="object"&&F.hasOwnProperty(C.customErrorKeyStr)){x.abort.hide();var G=F[C.customErrorKeyStr];C.onError.call(this,z,200,G,x);if(C.showStatusAfterError){x.progressDiv.hide();x.statusbar.append("ERROR: "+G+" ")}else{x.statusbar.hide();x.statusbar.remove()}E.selectedFiles-=z.length;D.remove();E.fCounter+=z.length;return}E.responses.push(F);x.progressbar.width("100%");if(C.showProgress){x.progressbar.html("100%");x.progressbar.css("text-align","center")}x.abort.hide();C.onSuccess.call(this,z,F,H,x);if(C.showStatusAfterSuccess){if(C.showDone){x.done.show();x.done.click(function(){x.statusbar.hide("slow");x.statusbar.remove()})}else{x.done.hide()}if(C.showDelete){x.del.show();x.del.click(function(){if(C.deleteCallback){C.deleteCallback.call(this,F,x)}E.selectedFiles-=z.length;d(C,E)})}else{x.del.hide()}}else{x.statusbar.hide("slow");x.statusbar.remove()}if(C.showDownload){x.download.show();x.download.click(function(){if(C.downloadCallback){C.downloadCallback(F)}})}D.remove();E.sCounter+=z.length},error:function(G,s,F){x.abort.hide();if(G.statusText=="abort"){x.statusbar.hide("slow").remove();d(C,E)}else{C.onError.call(this,z,s,F,x);if(C.showStatusAfterError){x.progressDiv.hide();x.statusbar.append("ERROR: "+F+" ")}else{x.statusbar.hide();x.statusbar.remove()}E.selectedFiles-=z.length}D.remove();E.fCounter+=z.length}};if(C.showPreview&&B!=null){if(B.type.toLowerCase().split("/").shift()=="image"){v(B,x.preview)}}if(C.autoSubmit){D.ajaxSubmit(y)}else{if(C.showCancel){x.cancel.show();x.cancel.click(function(){h(E,z);D.remove();x.statusbar.remove();C.onCancel.call(E,z,x);E.selectedFiles-=z.length;d(C,E)})}D.ajaxForm(y)}}return this}}(jQuery));