mirror of
https://github.com/unraid/webgui.git
synced 2026-01-01 06:59:56 -06:00
2 lines
2.9 KiB
JavaScript
2 lines
2.9 KiB
JavaScript
/* jQuery filedrop v0.1.0, copyright Weixi Yen - modified by Bergware for jQuery v3.6 */
|
|
!function(n){var r,s,f={},t={url:"",refresh:1e3,paramname:"userfile",maxfiles:25,maxfilesize:1024,data:{},drop:e,dragEnter:e,dragOver:e,dragLeave:e,docEnter:e,docOver:e,docLeave:e,beforeEach:e,afterAll:e,rename:e,error:function(e,r,t){alert(e)},uploadStarted:e,uploadFinished:e,progressUpdated:e,speedUpdated:e},a=["BrowserNotSupported","TooManyFiles","FileTooLarge"],l=!1,c=0;function o(e){return f.drop(e),null==(s=e.dataTransfer.files)?(f.error(a[0]),!1):(c=s.length,e.preventDefault(),function(){if(l=!1,!s)return f.error(a[0]),!1;var d=0,u=0;if(c>f.maxfiles)return f.error(a[1]),!1;for(var e=0;e<c;e++){if(l)return!1;try{if(0!=function(e){return f.beforeEach(e)}(s[e])){if(e===c)return;var r=new FileReader,t=1024*f.maxfilesize;if(r.index=e,s[e].size>t){f.error(a[2],s[e],e),u++;continue}r.onloadend=n,r.readAsDataURL(s[e])}else u++}catch(e){return f.error(a[0]),!1}}function n(e){null==e.target.index&&(e.target.index=function(e){for(var r=0;r<c;r++)if(s[r].size==e)return r;return}(e.total));var r,t=new XMLHttpRequest,n=t.upload,a=s[e.target.index],o=e.target.index,i=(new Date).getTime();newName=(r=a.name,f.rename(r)),e="string"==typeof newName?p(newName,e.target.result):p(a.name,e.target.result),n.index=o,n.file=a,n.downloadStartTime=i,n.currentStart=i,n.currentProgress=0,n.startData=0,n.addEventListener("progress",g,!1),t.open("POST",f.url,!0),t.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),t.send(e),f.uploadStarted(o,a,c),t.onload=function(){var e;t.responseText&&(e=(new Date).getTime()-i,e=f.uploadFinished(o,a,t.responseText,e),++d==c-u&&f.afterAll(),!1===e&&(l=!0))}}return 0==u}())}function p(e,r){var t=[];return n.each(f.data,function(e,r){"function"==typeof r&&(r=r()),t.push(e+"="+r)}),t.push("filename="+encodeURI(e)),t.push("filedata="+r),t.join("&")}function g(e){var r,t;e.lengthComputable&&(t=Math.round(100*e.loaded/e.total),this.currentProgress!=t&&(this.currentProgress=t,f.progressUpdated(this.index,this.file,this.currentProgress),(t=(r=(new Date).getTime())-this.currentStart)>=f.refresh&&(t=(e.loaded-this.startData)/t,f.speedUpdated(this.index,this.file,t),this.startData=e.loaded,this.currentStart=r)))}function i(e){clearTimeout(r),e.preventDefault(),f.dragEnter(e)}function d(e){clearTimeout(r),e.preventDefault(),f.docOver(e),f.dragOver(e)}function u(e){clearTimeout(r),f.dragLeave(e),e.stopPropagation()}function v(e){return e.preventDefault(),f.docLeave(e),!1}function m(e){return clearTimeout(r),e.preventDefault(),f.docEnter(e),!1}function h(e){return clearTimeout(r),e.preventDefault(),f.docOver(e),!1}function T(e){r=setTimeout(function(){f.docLeave(e)},200)}function e(){}n.fn.filedrop=function(e){f=n.extend({},t,e),this.on("drop",o).on("dragenter",i).on("dragover",d).on("dragleave",u),n(document).on("drop",v).on("dragenter",m).on("dragover",h).on("dragleave",T)}}(jQuery); |