-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.dnd.min.js
6 lines (6 loc) · 3.01 KB
/
jquery.dnd.min.js
1
2
3
4
5
6
(function(n){function v(a){a.preventDefault();b.drop(a);f=a.dataTransfer.files;h=f.length;for(a=0;a<h;a++)t+=f[a].size;w();return false}function x(a){if(a.lengthComputable){var c=Math.round(a.loaded*100/a.total);if(this.currentProgress!==c){this.currentProgress=c;b.progressUpdated(this.index,this.file,a.loaded);c=(new Date).getTime();var k=c-this.currentStart;if(k>=b.refresh){b.speedUpdated(this.index,this.file,(a.loaded-this.startData)/k);this.startData=a.loaded;this.currentStart=c}}}}function w(){function a(l){if(l.target.index==
undefined)l.target.index=y(l.total);var e=new XMLHttpRequest,j=e.upload,i=f[l.target.index],o=l.target.index,u=(new Date).getTime();j.index=o;j.file=i;j.downloadStartTime=u;j.currentStart=u;j.currentProgress=0;j.startData=0;j.addEventListener("progress",x,false);e.open("POST",b.url+"&name="+i.name,true);e.setRequestHeader("UP-FILENAME",i.name);e.setRequestHeader("UP-SIZE",i.size);e.setRequestHeader("UP-TYPE",i.type);e.send(window.btoa(l.target.result));b.uploadStarted(o,i,h,t);if(Modernizr.draganddrop)e.onreadystatechange=
function(){if(e.readyState>=3){var s=b.uploadFinished(o,i,e.responseText);c++;c==h-k&&b.afterAll();if(s===false)p=true}};else e.onload=function(){if(e.readyState>=3){var s=b.uploadFinished(o,i,e.responseText);c++;c==h-k&&b.afterAll();if(s===false)p=true}}}p=false;if(!f){b.error(q[0]);return false}var c=0,k=0;if(h>b.maxfiles){b.error(q[1]);return false}var g;for(g=0;g<h;g++){if(p)return false;try{if(b.beforeEach(f[g])!=false){if(g===h)break;var r=new FileReader,z=1048576*b.maxfilesize;r.index=g;if(f[g].size>
z){b.error(q[2],f[g]);return false}if(typeof FileReader.prototype.addEventListener==="function")r.addEventListener("loadend",a,false);else r.onload=a;r.readAsBinaryString(f[g])}else k++}catch(I){b.error(q[0]);return false}}}function y(a){for(var c=0;c<filesCount;c++)if(f[c].size==a)return c}function A(a){clearTimeout(m);a.preventDefault();b.dragEnter(a)}function B(a){clearTimeout(m);a.preventDefault();b.docOver(a);b.dragOver(a)}function C(a){clearTimeout(m);b.dragLeave(a);a.stopPropagation()}function D(a){a.preventDefault();
b.docLeave(a);return false}function E(a){clearTimeout(m);a.preventDefault();b.docEnter(a);return false}function F(a){clearTimeout(m);a.preventDefault();b.docOver(a);return false}function G(a){m=setTimeout(function(){b.docLeave(a)},200)}function d(){}var b={},H={url:"",refresh:1E3,paramname:"userfile",maxfiles:1,maxfilesize:10,data:{},drop:d,dragEnter:d,dragOver:d,dragLeave:d,docEnter:d,docOver:d,docLeave:d,beforeEach:d,afterAll:d,rename:d,error:function(a){alert(a)},uploadStarted:d,uploadFinished:d,
progressUpdated:d,speedUpdated:d},q=["BrowserNotSupported","TooManyFiles","FileTooLarge"],m,p=false,h=0,t=0,f;n.fn.filedrop=function(a){b=n.extend({},H,a);if(Modernizr.draganddrop){this.get(0).addEventListener("drop",v,true);this.bind("dragenter",A).bind("dragover",B).bind("dragleave",C);document.addEventListener("drop",D,true);n(document).bind("dragenter",E).bind("dragover",F).bind("dragleave",G)}}})(jQuery);function hello(n){alert("Hello, "+n)}hello("New user");