-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.imgup.min.js
4 lines (4 loc) · 2.05 KB
/
jquery.imgup.min.js
1
2
3
4
(function(d){var i={init:function(f){return this.each(function(){var g={uploadurl:"",sizeExceededMessage:"too big image",imgMaxSize:167772160,imgUploading:function(){return null},imgUploaded:function(){},uploaderror:function(){},allImgsSent:function(){},allImgsSendStarted:function(){},completeFormData:function(){},enableLocalFileRead:!1,onFileReaded:function(){}};f&&d.extend(g,f);var h=this,b=d(this);b.settings=g;this.triggerUpload=function(c){b.data("imgup").hasFormData&&h.uploadWithFormData(c)};
this.uploadWithFormData=function(c){var e=b.settings.imgUploading(c);if(c.size>b.settings.imgMaxSize)b.settings.uploaderror(e,b.settings.sizeExceededMessage,null);else{var a=new FormData;a.append("image",c);b.settings.completeFormData(a);d.ajax({url:b.settings.uploadurl,type:"POST",cache:!1,contentType:!1,processData:!1,data:a,success:function(a){b.settings.imgUploaded(a,e)},error:function(a,c,d){b.settings.uploaderror(e,c,d)}});b.data("imgup").hasFileReader&&(a=new FileReader,a.onload=function(a){return function(c){b.settings.onFileReaded(e,
a,c.target.result)}}(c),a.readAsDataURL(c))}};this.triggerFilesUpload=function(c){b.settings.allImgsSendStarted();for(var e=0,a=c.length;e<a;e++){var d=c[e];d.type.match("image.*")&&h.triggerUpload(d)}b.settings.allImgsSent()};this.configureDropZone=function(){b.settings.linkedDropZone&&d.each(b.settings.linkedDropZone,function(b,e){d(e).on("dragover.imgup",function(a){a.stopPropagation();a.preventDefault();a.originalEvent.dataTransfer.dropEffect="copy"});d(e).on("drop.imgup",function(a){a.stopPropagation();
a.preventDefault();h.triggerFilesUpload(a.originalEvent.dataTransfer.files)})})};g=!1;try{new FormData,g=!0}catch(i){g=!1}b.data("imgup",{hasFormData:g,hasFileReader:window.FileReader&&b.settings.enableLocalFileRead});h.configureDropZone();b.on("change.imgup",function(){h.triggerFilesUpload(h.files)})})}};d.fn.imgup=function(f){if(i[f])return i[f].apply(this,Array.prototype.slice.call(arguments,1));if("object"===typeof f||!f)return i.init.apply(this,arguments);d.error("Method "+f+" does not exist on jQuery.imgup")}})(jQuery);