From 1ec45a9f8e3a0ac0f39cbd160638f268a5708fa9 Mon Sep 17 00:00:00 2001 From: djmaze Date: Sat, 19 Sep 2020 13:32:50 +0200 Subject: [PATCH] Bugfix: somehow Jua minified was broken. Cleaned it up and it works again --- vendors/jua/jua.js | 124 +++++++++++------------------------------ vendors/jua/jua.min.js | 2 +- 2 files changed, 35 insertions(+), 91 deletions(-) diff --git a/vendors/jua/jua.js b/vendors/jua/jua.js index a04f38c9e..96b980f17 100644 --- a/vendors/jua/jua.js +++ b/vendors/jua/jua.js @@ -79,15 +79,11 @@ eventContainsFiles = oEvent => { - if (oEvent.dataTransfer && oEvent.dataTransfer.types && oEvent.dataTransfer.types.length) { - let index = oEvent.dataTransfer.types.length; - while (index--) { - if (oEvent.dataTransfer.types[index].toLowerCase() === 'files') { - return true; - } - } + try { + return oEvent.dataTransfer.types.includes('Files'); + } catch (e) { + return false; } - return false; }; @@ -122,13 +118,11 @@ /** * @param {string} sUid * @param {?} oFileInfo - * @param {Function} fCallback */ - uploadTask(sUid, oFileInfo, fCallback) + uploadTask(sUid, oFileInfo) { if (false === this.oUids[sUid] || !oFileInfo || !oFileInfo['File']) { - fCallback(null, sUid); return false; } @@ -184,23 +178,17 @@ { self.oXhrs[sUid] = null; } - - fCallback(null, sUid); } else { if (4 === oXhr.readyState) { fCompleteFunction(sUid, false, null); - fCallback(null, sUid); } } }; - if (fStartFunction) - { - fStartFunction(sUid); - } + fStartFunction && fStartFunction(sUid); oFormData.append('jua-post-type', 'ajax'); oFormData.append(this.oOptions.name, oFileInfo['File']); @@ -215,9 +203,9 @@ } catch (oError) { + console.error(oError) } - fCallback(null, sUid); return false; } @@ -277,6 +265,7 @@ } catch (oError) { + console.error(oError); } this.oXhrs[sUid] = null; @@ -284,58 +273,26 @@ } } - /** - * @type {Object} - */ - AjaxDriver.prototype.oXhrs = {}; - - /** - * @type {Object} - */ - AjaxDriver.prototype.oUids = {}; - - /** - * @type {?Jua} - */ - AjaxDriver.prototype.oJua = null; - - /** - * @type {Object} - */ - AjaxDriver.prototype.oOptions = {}; - - - function queue(a) { - function l() { - if (g && d < a) { - let b = g, - c = b[0], - f = Array.prototype.slice.call(b, 1), - m = b.index; - g === h ? g = h = null : g = g.next, ++d, f.push(function (a, b) { - --d; - if (i) return; - a ? e && k(i = a, e = j = g = h = null) : (j[m] = b, --e ? l() : k(null, j)) - }), - c.apply(null, f) + class Queue extends Array + { + constructor(limit) { + super(); + this.limit = parseInt(limit || 0, 10); + } + push(fn, ...args) { + if (this.limit > this.length) { + super.push([fn, args]); + this.call(); } } - let c = {}, - d = 0, - e = 0, - f = -1, - g, h, i = null, - j = [], - k = ()=>{}; - return arguments.length < 1 && (a = Infinity), c.defer = function () { - if (!i) { - let a = arguments; - a.index = ++f, h ? (h.next = a, h = h.next) : g = h = a, ++e, l() + call() { + if (!this.running) { + this.running = true; + let f; + while ((f = this.shift())) f[0](...f[1]); + this.running = false; } - return c - }, c.await = function (a) { - return k = a, e || k(i, j), c - }, c + } } /** @@ -369,7 +326,7 @@ multipleSizeLimit: iDefLimit }, oOptions || {}); - self.oQueue = queue(parseInt(oOptions.queueSize || 0, 10)); + self.oQueue = new Queue(oOptions.queueSize); self.oDriver = new AjaxDriver(self, oOptions); @@ -381,7 +338,7 @@ el.style.display = 'inline-block'; } - this.oDriver.generateNewInput(el); + self.oDriver.generateNewInput(el); } el = oOptions.dragAndDropElement; @@ -399,7 +356,9 @@ oEvent.dataTransfer.dropEffect = 'none'; oEvent.preventDefault(); } - catch (oExc) {} + catch (oExc) { + console.error(oExc); + } } }); } @@ -455,10 +414,10 @@ oEvent.stopPropagation(); oEvent.preventDefault(); - - oBigDropZone && oBigDropZone.dispatchEvent(oEvent); } - catch (oExc) {} + catch (oExc) { + console.error(oExc); + } } }, dragleave: oEvent => { @@ -556,7 +515,7 @@ if (oFileInfo && (!fOnSelect || (false !== fOnSelect(sUid, oFileInfo)))) { this.oDriver.regTaskUid(sUid); - this.oQueue.defer((...args) => this.oDriver.uploadTask(...args), sUid, oFileInfo); + this.oQueue.push((...args) => this.oDriver.uploadTask(...args), sUid, oFileInfo); } else { @@ -579,21 +538,6 @@ } }; - /** - * @type {Object} - */ - Jua.prototype.oEvents = {}; - - /** - * @type {?Object} - */ - Jua.prototype.oQueue = null; - - /** - * @type {?Object} - */ - Jua.prototype.oDriver = null; - window.Jua = Jua; })(); diff --git a/vendors/jua/jua.min.js b/vendors/jua/jua.min.js index 01d172516..1b3fb1935 100644 --- a/vendors/jua/jua.min.js +++ b/vendors/jua/jua.min.js @@ -1,2 +1,2 @@ /* RainLoop Webmail (c) RainLoop Team | MIT */ -(()=>{"use strict";const e=document,t=20,n=e=>void 0!==e,r=(e,r,o,i)=>{if(e&&e.length){let a=o=n(o)?parseInt(o||0,10):t,s=null,u=0{e&&(!u||0<=--o?(s=l(e))&&r(s):u&&!d&&0>o&&i&&(d=!0,i(a)))})}},o=(e,t)=>{Object.entries(t).forEach(([t,n])=>e.addEventListener(t,n))},l=e=>{let t=n(e.fileName)?e.fileName:n(e.name)?e.name:null,r=n(e.fileSize)?e.fileSize:n(e.size)?e.size:null,o=n(e.type)?e.type:null;return"/"===t.charAt(0)&&(t=t.substr(1)),o||0!==r?{FileName:t,Size:r,Type:o,Folder:"",File:e}:null},i=e=>{if(e.dataTransfer&&e.dataTransfer.types&&e.dataTransfer.types.length){let t=e.dataTransfer.types.length;for(;t--;)if("files"===e.dataTransfer.types[t].toLowerCase())return!0}return!1};class a{constructor(e,t){this.oXhrs={},this.oUids={},this.oJua=e,this.oOptions=Object.assign({action:"",name:"juaFile",hidden:{},disableMultiple:!1},t)}regTaskUid(e){this.oUids[e]=!0}uploadTask(e,t,r){if(!1===this.oUids[e]||!t||!t.File)return r(null,e),!1;try{const o=this,l=new XMLHttpRequest,i=new FormData,a=this.oOptions.action,s=this.oOptions.hidden,u=this.oJua.getEvent("onStart"),d=this.oJua.getEvent("onComplete"),p=this.oJua.getEvent("onProgress");return l.open("POST",a,!0),p&&l.upload&&(l.upload.onprogress=function(t){t&&t.lengthComputable&&n(t.loaded)&&n(t.total)&&p(e,t.loaded,t.total)}),l.onreadystatechange=function(){if(4===l.readyState&&200===l.status){if(d){let t=!1,n=null;try{n=JSON.parse(l.responseText),t=!0}catch(e){n=null}d(e,t,n)}n(o.oXhrs[e])&&(o.oXhrs[e]=null),r(null,e)}else 4===l.readyState&&(d(e,!1,null),r(null,e))},u&&u(e),i.append("jua-post-type","ajax"),i.append(this.oOptions.name,t.File),Object.entries(s).forEach(([e,n])=>i.append(e,("function"==typeof n?n(t):n).toString())),l.send(i),this.oXhrs[e]=l,!0}catch(e){}return r(null,e),!1}generateNewInput(t){if(t){const n=this,o=e.createElement("label"),l=o.appendChild(e.createElement("input"));l.type="file",l.tabIndex=-1,l.style.cssText="position:absolute;left:-9999px;",l.multiple=!n.oOptions.disableMultiple,o.style.cssText="position:absolute;background-color:#fff;right:0;top:0;left:0;bottom:0;margin:0;padding:0;cursor:pointer;opacity:0",t.append(o),l.addEventListener("input",()=>{const e=e=>{n.oJua.addNewFile(e),n.generateNewInput(t),setTimeout(()=>o.remove(),10)};l.files&&l.files.length?r(l.files,e,n.oOptions.multipleSizeLimit,n.oJua.getEvent("onLimitReached")):e({FileName:l.value.split("\\").pop().split("/").pop(),Size:null,Type:null,Folder:"",File:null})})}}cancel(e){if(this.oUids[e]=!1,this.oXhrs[e]){try{this.oXhrs[e].abort&&this.oXhrs[e].abort()}catch(e){}this.oXhrs[e]=null}}}function s(e){let t,n,r={},o=0,l=0,i=-1,a=null,s=[],u=()=>{};return arguments.length<1&&(e=1/0),r.defer=function(){if(!a){let e=arguments;e.index=++i,n?(n.next=e,n=n.next):t=n=e,++l,function r(){if(t&&o{if(i(e))try{e.dataTransfer.dropEffect="none",e.preventDefault()}catch(e){}}),t&&o(t,{dragover:()=>l.docTimer.clear(),dragenter:e=>{i(e)&&(l.docTimer.clear(),e.preventDefault(),l.runEvent("onBodyDragEnter",[e]))},dragleave:e=>e.dataTransfer&&l.docTimer.start(()=>l.runEvent("onBodyDragLeave",[e])),drop:e=>{if(e.dataTransfer){let t=i(e);return t&&e.preventDefault(),l.runEvent("onBodyDragLeave",[e]),!t}return!1}}),o(u,{dragenter:e=>{i(e)&&(l.docTimer.clear(),e.preventDefault(),l.runEvent("onDragEnter",[u,e]))},dragover:e=>{if(i(e))try{let n=e.dataTransfer.effectAllowed;l.docTimer.clear(),e.dataTransfer.dropEffect="move"===n||"linkMove"===n?"move":"copy",e.stopPropagation(),e.preventDefault(),t&&t.dispatchEvent(e)}catch(e){}},dragleave:t=>{if(t.dataTransfer){let n=e.elementFromPoint(t.clientX,t.clientY);n&&u.contains(n)||(l.docTimer.clear(),l.runEvent("onDragLeave",[u,t]))}},drop:e=>{i(e)&&(e.preventDefault(),r(e.files||e.dataTransfer.files,e=>{e&&(l.addNewFile(e),l.docTimer.clear())},n.multipleSizeLimit,l.getEvent("onLimitReached"))),l.runEvent("onDragLeave",[e])}})}}on(e,t){return this.oEvents[e]=t,this}runEvent(e,t){this.oEvents[e]&&this.oEvents[e].apply(null,t||[])}getEvent(e){return this.oEvents[e]||null}cancel(e){this.oDriver.cancel(e)}addNewFile(e){let t=16,n="";for(;t--;)n+="0123456789abcdefghijklmnopqrstuvwxyz".substr(Math.round(36*Math.random()),1);this.addFile("jua-uid-"+n+"-"+(new Date).getTime().toString(),e)}addFile(e,t){const n=this.getEvent("onSelect");!t||n&&!1===n(e,t)?this.oDriver.cancel(e):(this.oDriver.regTaskUid(e),this.oQueue.defer((...e)=>this.oDriver.uploadTask(...e),e,t))}}u.prototype.docTimer={start:function(e){this.clear(),this.timer=setTimeout(e,200)},clear:function(){this.timer&&clearTimeout(this.timer),this.timer=0}},u.prototype.oEvents={},u.prototype.oQueue=null,u.prototype.oDriver=null,window.Jua=u})(); +(()=>{"use strict";const e=document,t=20,n=e=>void 0!==e,r=(e,r,i,l)=>{if(e&&e.length){let a=i=n(i)?parseInt(i||0,10):t,s=null,u=0{e&&(!u||0<=--i?(s=o(e))&&r(s):u&&!d&&0>i&&l&&(d=!0,l(a)))})}},i=(e,t)=>{Object.entries(t).forEach(([t,n])=>e.addEventListener(t,n))},o=e=>{let t=n(e.fileName)?e.fileName:n(e.name)?e.name:null,r=n(e.fileSize)?e.fileSize:n(e.size)?e.size:null,i=n(e.type)?e.type:null;return"/"===t.charAt(0)&&(t=t.substr(1)),i||0!==r?{FileName:t,Size:r,Type:i,Folder:"",File:e}:null},l=e=>{try{return e.dataTransfer.types.includes("Files")}catch(e){return!1}};class a{constructor(e,t){this.oXhrs={},this.oUids={},this.oJua=e,this.oOptions=Object.assign({action:"",name:"juaFile",hidden:{},disableMultiple:!1},t)}regTaskUid(e){this.oUids[e]=!0}uploadTask(e,t){if(!1===this.oUids[e]||!t||!t.File)return!1;try{const r=this,i=new XMLHttpRequest,o=new FormData,l=this.oOptions.action,a=this.oOptions.hidden,s=this.oJua.getEvent("onStart"),u=this.oJua.getEvent("onComplete"),d=this.oJua.getEvent("onProgress");return i.open("POST",l,!0),d&&i.upload&&(i.upload.onprogress=function(t){t&&t.lengthComputable&&n(t.loaded)&&n(t.total)&&d(e,t.loaded,t.total)}),i.onreadystatechange=function(){if(4===i.readyState&&200===i.status){if(u){let t=!1,n=null;try{n=JSON.parse(i.responseText),t=!0}catch(e){n=null}u(e,t,n)}n(r.oXhrs[e])&&(r.oXhrs[e]=null)}else 4===i.readyState&&u(e,!1,null)},s&&s(e),o.append("jua-post-type","ajax"),o.append(this.oOptions.name,t.File),Object.entries(a).forEach(([e,n])=>o.append(e,("function"==typeof n?n(t):n).toString())),i.send(o),this.oXhrs[e]=i,!0}catch(e){console.error(e)}return!1}generateNewInput(t){if(t){const n=this,i=e.createElement("label"),o=i.appendChild(e.createElement("input"));o.type="file",o.tabIndex=-1,o.style.cssText="position:absolute;left:-9999px;",o.multiple=!n.oOptions.disableMultiple,i.style.cssText="position:absolute;background-color:#fff;right:0;top:0;left:0;bottom:0;margin:0;padding:0;cursor:pointer;opacity:0",t.append(i),o.addEventListener("input",()=>{const e=e=>{n.oJua.addNewFile(e),n.generateNewInput(t),setTimeout(()=>i.remove(),10)};o.files&&o.files.length?r(o.files,e,n.oOptions.multipleSizeLimit,n.oJua.getEvent("onLimitReached")):e({FileName:o.value.split("\\").pop().split("/").pop(),Size:null,Type:null,Folder:"",File:null})})}}cancel(e){if(this.oUids[e]=!1,this.oXhrs[e]){try{this.oXhrs[e].abort&&this.oXhrs[e].abort()}catch(e){console.error(e)}this.oXhrs[e]=null}}}class s extends Array{constructor(e){super(),this.limit=parseInt(e||0,10)}push(e,...t){this.limit>this.length&&(super.push([e,t]),this.call())}call(){if(!this.running){let e;for(this.running=!0;e=this.shift();)e[0](...e[1]);this.running=!1}}}class u{constructor(n){const o=this;o.oEvents={onSelect:null,onStart:null,onComplete:null,onProgress:null,onDragEnter:null,onDragLeave:null,onBodyDragEnter:null,onBodyDragLeave:null,onLimitReached:null},n=Object.assign({queueSize:10,clickElement:null,dragAndDropElement:null,dragAndDropBodyElement:null,disableDocumentDropPrevent:!1,multipleSizeLimit:t},n||{}),o.oQueue=new s(n.queueSize),o.oDriver=new a(o,n);let u=n.clickElement;if(u&&(u.style.position="relative",u.style.overflow="hidden","inline"===u.style.display&&(u.style.display="inline-block"),o.oDriver.generateNewInput(u)),u=n.dragAndDropElement){let t=n.dragAndDropBodyElement||e;n.disableDocumentDropPrevent||e.addEventListener("dragover",e=>{if(l(e))try{e.dataTransfer.dropEffect="none",e.preventDefault()}catch(e){console.error(e)}}),t&&i(t,{dragover:()=>o.docTimer.clear(),dragenter:e=>{l(e)&&(o.docTimer.clear(),e.preventDefault(),o.runEvent("onBodyDragEnter",[e]))},dragleave:e=>e.dataTransfer&&o.docTimer.start(()=>o.runEvent("onBodyDragLeave",[e])),drop:e=>{if(e.dataTransfer){let t=l(e);return t&&e.preventDefault(),o.runEvent("onBodyDragLeave",[e]),!t}return!1}}),i(u,{dragenter:e=>{l(e)&&(o.docTimer.clear(),e.preventDefault(),o.runEvent("onDragEnter",[u,e]))},dragover:e=>{if(l(e))try{let t=e.dataTransfer.effectAllowed;o.docTimer.clear(),e.dataTransfer.dropEffect="move"===t||"linkMove"===t?"move":"copy",e.stopPropagation(),e.preventDefault()}catch(e){console.error(e)}},dragleave:t=>{if(t.dataTransfer){let n=e.elementFromPoint(t.clientX,t.clientY);n&&u.contains(n)||(o.docTimer.clear(),o.runEvent("onDragLeave",[u,t]))}},drop:e=>{l(e)&&(e.preventDefault(),r(e.files||e.dataTransfer.files,e=>{e&&(o.addNewFile(e),o.docTimer.clear())},n.multipleSizeLimit,o.getEvent("onLimitReached"))),o.runEvent("onDragLeave",[e])}})}}on(e,t){return this.oEvents[e]=t,this}runEvent(e,t){this.oEvents[e]&&this.oEvents[e].apply(null,t||[])}getEvent(e){return this.oEvents[e]||null}cancel(e){this.oDriver.cancel(e)}addNewFile(e){let t=16,n="";for(;t--;)n+="0123456789abcdefghijklmnopqrstuvwxyz".substr(Math.round(36*Math.random()),1);this.addFile("jua-uid-"+n+"-"+(new Date).getTime().toString(),e)}addFile(e,t){const n=this.getEvent("onSelect");!t||n&&!1===n(e,t)?this.oDriver.cancel(e):(this.oDriver.regTaskUid(e),this.oQueue.push((...e)=>this.oDriver.uploadTask(...e),e,t))}}u.prototype.docTimer={start:function(e){this.clear(),this.timer=setTimeout(e,200)},clear:function(){this.timer&&clearTimeout(this.timer),this.timer=0}},window.Jua=u})();