mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-11-10 09:02:45 +08:00
Cleanup Jua multi file uploader
This commit is contained in:
parent
7027b1b74c
commit
6ba4e70d5e
1 changed files with 29 additions and 34 deletions
63
vendors/jua/jua.js
vendored
63
vendors/jua/jua.js
vendored
|
@ -13,10 +13,10 @@
|
|||
if (aItems && aItems.length)
|
||||
{
|
||||
let
|
||||
oFile,
|
||||
iInputLimit = iLimit,
|
||||
oFile = null,
|
||||
bUseLimit = 0 < iLimit,
|
||||
bCallLimit = false
|
||||
bCallLimit = !fLimitCallback
|
||||
;
|
||||
|
||||
[...aItems].forEach(oItem => {
|
||||
|
@ -27,7 +27,7 @@
|
|||
oFile = getDataFromFile(oItem);
|
||||
oFile && fFileCallback(oFile);
|
||||
}
|
||||
else if (bUseLimit && !bCallLimit && 0 > iLimit && fLimitCallback)
|
||||
else if (bUseLimit && !bCallLimit)
|
||||
{
|
||||
bCallLimit = true;
|
||||
fLimitCallback(iInputLimit);
|
||||
|
@ -101,7 +101,18 @@
|
|||
{
|
||||
constructor(options)
|
||||
{
|
||||
const self = this;
|
||||
let timer,
|
||||
el = options.clickElement;
|
||||
|
||||
const self = this,
|
||||
timerStart = fn => {
|
||||
timerStop();
|
||||
timer = setTimeout(fn, 200);
|
||||
},
|
||||
timerStop = () => {
|
||||
timer && clearTimeout(timer);
|
||||
timer = 0;
|
||||
};
|
||||
|
||||
self.oEvents = {
|
||||
onSelect: null,
|
||||
|
@ -125,7 +136,6 @@
|
|||
}, options || {});
|
||||
self.oQueue = new Queue(1 == options.limit ? 1 : 2);
|
||||
|
||||
let el = options.clickElement;
|
||||
if (el) {
|
||||
el.style.position = 'relative';
|
||||
el.style.overflow = 'hidden';
|
||||
|
@ -161,24 +171,24 @@
|
|||
if (oBigDropZone)
|
||||
{
|
||||
addEventListeners(oBigDropZone, {
|
||||
dragover: () => self.docTimer.clear(),
|
||||
dragover: () => timerStop(),
|
||||
dragenter: oEvent => {
|
||||
if (eventContainsFiles(oEvent))
|
||||
{
|
||||
self.docTimer.clear();
|
||||
timerStop();
|
||||
oEvent.preventDefault();
|
||||
|
||||
self.runEvent('onBodyDragEnter', [oEvent]);
|
||||
self.runEvent('onBodyDragEnter', oEvent);
|
||||
}
|
||||
},
|
||||
dragleave: oEvent =>
|
||||
oEvent.dataTransfer && self.docTimer.start(() => self.runEvent('onBodyDragLeave', [oEvent])),
|
||||
oEvent.dataTransfer && timerStart(() => self.runEvent('onBodyDragLeave', oEvent)),
|
||||
drop: oEvent => {
|
||||
if (oEvent.dataTransfer) {
|
||||
let bFiles = eventContainsFiles(oEvent);
|
||||
bFiles && oEvent.preventDefault();
|
||||
|
||||
self.runEvent('onBodyDragLeave', [oEvent]);
|
||||
self.runEvent('onBodyDragLeave', oEvent);
|
||||
|
||||
return !bFiles;
|
||||
}
|
||||
|
@ -191,10 +201,10 @@
|
|||
addEventListeners(el, {
|
||||
dragenter: oEvent => {
|
||||
if (eventContainsFiles(oEvent)) {
|
||||
self.docTimer.clear();
|
||||
timerStop();
|
||||
|
||||
oEvent.preventDefault();
|
||||
self.runEvent('onDragEnter', [el, oEvent]);
|
||||
self.runEvent('onDragEnter', el, oEvent);
|
||||
}
|
||||
},
|
||||
dragover: oEvent => {
|
||||
|
@ -203,7 +213,7 @@
|
|||
{
|
||||
let sEffect = oEvent.dataTransfer.effectAllowed;
|
||||
|
||||
self.docTimer.clear();
|
||||
timerStop();
|
||||
|
||||
oEvent.dataTransfer.dropEffect = (sEffect === 'move' || sEffect === 'linkMove') ? 'move' : 'copy';
|
||||
|
||||
|
@ -219,8 +229,8 @@
|
|||
if (oEvent.dataTransfer) {
|
||||
let oRelatedTarget = doc.elementFromPoint(oEvent.clientX, oEvent.clientY);
|
||||
if (!oRelatedTarget || !el.contains(oRelatedTarget)) {
|
||||
self.docTimer.clear();
|
||||
self.runEvent('onDragLeave', [el, oEvent]);
|
||||
timerStop();
|
||||
self.runEvent('onDragLeave', el, oEvent);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -233,7 +243,7 @@
|
|||
oFile => {
|
||||
if (oFile) {
|
||||
self.addNewFile(oFile);
|
||||
self.docTimer.clear();
|
||||
timerStop();
|
||||
}
|
||||
},
|
||||
self.options.limit,
|
||||
|
@ -241,7 +251,7 @@
|
|||
);
|
||||
}
|
||||
|
||||
self.runEvent('onDragLeave', [oEvent]);
|
||||
self.runEvent('onDragLeave', oEvent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -259,11 +269,10 @@
|
|||
|
||||
/**
|
||||
* @param {string} sName
|
||||
* @param {string=} aArgs
|
||||
*/
|
||||
runEvent(sName, aArgs)
|
||||
runEvent(sName, ...aArgs)
|
||||
{
|
||||
this.oEvents[sName] && this.oEvents[sName].apply(null, aArgs || []);
|
||||
this.oEvents[sName] && this.oEvents[sName].apply(null, aArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -448,20 +457,6 @@
|
|||
return arr.map(dec => dec.toString(16).padStart(2,'0')).join('');
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
Jua.prototype.docTimer = {
|
||||
start: function(fn){
|
||||
this.clear();
|
||||
this.timer = setTimeout(fn, 200);
|
||||
},
|
||||
clear: function(){
|
||||
this.timer && clearTimeout(this.timer);
|
||||
this.timer = 0;
|
||||
}
|
||||
};
|
||||
|
||||
this.Jua = Jua;
|
||||
|
||||
})(document);
|
||||
|
|
Loading…
Reference in a new issue