mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-29 20:19:22 +03:00
Cleanup JS and better terser compression
This commit is contained in:
parent
058217de02
commit
ba7ed497b2
20 changed files with 247 additions and 298 deletions
6
dev/External/User/ko.js
vendored
6
dev/External/User/ko.js
vendored
|
|
@ -87,9 +87,9 @@ ko.bindingHandlers.emailsTags = {
|
|||
});
|
||||
|
||||
if (fValue && fValue.focused && fValue.focused.subscribe) {
|
||||
fValue.focused.subscribe(value => {
|
||||
element.inputosaurus[value ? 'focus' : 'blur']();
|
||||
});
|
||||
fValue.focused.subscribe(value =>
|
||||
element.inputosaurus[value ? 'focus' : 'blur']()
|
||||
);
|
||||
}
|
||||
},
|
||||
update: (element, fValueAccessor) => {
|
||||
|
|
|
|||
|
|
@ -352,12 +352,12 @@ class EmailModel {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param {boolean} friendlyView
|
||||
* @param {boolean} friendlyView = false
|
||||
* @param {boolean=} wrapWithLink = false
|
||||
* @param {boolean=} useEncodeHtml = false
|
||||
* @returns {string}
|
||||
*/
|
||||
toLine(friendlyView, wrapWithLink = false, useEncodeHtml = false) {
|
||||
toLine(friendlyView, wrapWithLink, useEncodeHtml) {
|
||||
let result = '';
|
||||
if (this.email) {
|
||||
if (friendlyView && this.name) {
|
||||
|
|
|
|||
4
dev/bootstrap.js
vendored
4
dev/bootstrap.js
vendored
|
|
@ -124,8 +124,8 @@ export default (App) => {
|
|||
window.__APP_BOOT = fErrorCallback => {
|
||||
const doc = document,
|
||||
cb = () => setTimeout(() => {
|
||||
if (window.rainloopTEMPLATES && rainloopTEMPLATES[0]) {
|
||||
doc.getElementById('rl-templates').innerHTML = rainloopTEMPLATES[0];
|
||||
if (rl.TEMPLATES) {
|
||||
doc.getElementById('rl-templates').innerHTML = rl.TEMPLATES;
|
||||
setTimeout(() => App.bootstart(), 10);
|
||||
} else {
|
||||
fErrorCallback();
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
allowDrop,
|
||||
lastTarget,
|
||||
lastTouch,
|
||||
pressHoldInterval,
|
||||
holdInterval,
|
||||
|
||||
img, imgCustom, imgOffset;
|
||||
|
||||
|
|
@ -64,22 +64,17 @@
|
|||
}
|
||||
|
||||
const
|
||||
// copy styles/attributes from drag source to drag image element
|
||||
rmvAtts = 'id,class,style,draggable'.split(','),
|
||||
kbdProps = 'altKey,ctrlKey,metaKey,shiftKey'.split(','),
|
||||
ptProps = 'pageX,pageY,clientX,clientY,screenX,screenY,offsetX,offsetY'.split(','),
|
||||
|
||||
// clear all members
|
||||
reset = () => {
|
||||
destroyImage();
|
||||
dragSource = lastTouch = lastTarget = dataTransfer = null;
|
||||
isDragging = allowDrop = false;
|
||||
clearInterval(pressHoldInterval);
|
||||
if (dragSource) {
|
||||
clearInterval(holdInterval);
|
||||
destroyImage();
|
||||
isDragging && dispatchEvent(lastTouch, 'dragend', dragSource);
|
||||
dragSource = lastTouch = lastTarget = dataTransfer = holdInterval = null;
|
||||
isDragging = allowDrop = false;
|
||||
}
|
||||
},
|
||||
|
||||
// ignore events that have been handled or that involve more than one touch
|
||||
shouldHandle = e => e && !e.defaultPrevented && e.touches && e.touches.length < 2,
|
||||
|
||||
// get point for a touch event
|
||||
getPoint = e => {
|
||||
if (e && e.touches) {
|
||||
|
|
@ -89,28 +84,26 @@
|
|||
},
|
||||
|
||||
touchstart = e => {
|
||||
if (shouldHandle(e)) {
|
||||
// clear all variables
|
||||
reset();
|
||||
|
||||
// clear all variables
|
||||
reset();
|
||||
// ignore events that have been handled or that involve more than one touch
|
||||
if (e && !e.defaultPrevented && e.touches && e.touches.length < 2) {
|
||||
// get nearest draggable element
|
||||
let src = e.target.closest('[draggable]');
|
||||
if (src) {
|
||||
dragSource = e.target.closest('[draggable]');
|
||||
if (dragSource) {
|
||||
// get ready to start dragging
|
||||
dragSource = src;
|
||||
lastTouch = e;
|
||||
e.preventDefault(); // prevent scrolling NOTE: this creates a bug that click will not work
|
||||
|
||||
// 1000 ms to wait, chrome on android triggers dragstart in 600
|
||||
pressHoldInterval = setTimeout(() => {
|
||||
holdInterval = setTimeout(() => {
|
||||
// start dragging
|
||||
if (dragSource && !isDragging) {
|
||||
isDragging = true;
|
||||
dataTransfer = new DataTransfer();
|
||||
if ((isDragging = dispatchEvent(e, 'dragstart', dragSource))) {
|
||||
createImage(e);
|
||||
dispatchEvent(e, 'dragenter', getTarget(e));
|
||||
}
|
||||
dataTransfer = new DataTransfer();
|
||||
if ((isDragging = dispatchEvent(e, 'dragstart', dragSource))) {
|
||||
createImage(e);
|
||||
dispatchEvent(e, 'dragenter', getTarget(e));
|
||||
} else {
|
||||
reset();
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
|
|
@ -120,37 +113,30 @@
|
|||
touchmove = e => {
|
||||
if (isDragging) {
|
||||
// continue dragging
|
||||
if (isDragging) {
|
||||
let target = getTarget(e);
|
||||
lastTouch = e;
|
||||
e.preventDefault(); // prevent scrolling
|
||||
if (target != lastTarget) {
|
||||
dispatchEvent(lastTouch, 'dragleave', lastTarget);
|
||||
dispatchEvent(e, 'dragenter', target);
|
||||
lastTarget = target;
|
||||
}
|
||||
moveImage(e);
|
||||
allowDrop = !dispatchEvent(e, 'dragover', target);
|
||||
let target = getTarget(e);
|
||||
lastTouch = e;
|
||||
e.preventDefault(); // prevent scrolling
|
||||
if (target != lastTarget) {
|
||||
dispatchEvent(lastTouch, 'dragleave', lastTarget);
|
||||
dispatchEvent(e, 'dragenter', target);
|
||||
lastTarget = target;
|
||||
}
|
||||
moveImage(e);
|
||||
allowDrop = !dispatchEvent(e, 'dragover', target);
|
||||
} else {
|
||||
reset();
|
||||
}
|
||||
},
|
||||
|
||||
touchend = e => {
|
||||
if (shouldHandle(e)) {
|
||||
if (dragSource) {
|
||||
if (!isDragging) {
|
||||
// touched the element but didn't drag, so simulate a click
|
||||
dispatchEvent(lastTouch, 'click', e.target);
|
||||
}
|
||||
// finish dragging
|
||||
if (dragSource) {
|
||||
if (allowDrop && !e.type.includes('cancel')) {
|
||||
dispatchEvent(lastTouch, 'drop', lastTarget);
|
||||
}
|
||||
dispatchEvent(lastTouch, 'dragend', dragSource);
|
||||
reset();
|
||||
}
|
||||
allowDrop && 'touchcancel' !== e.type && dispatchEvent(lastTouch, 'drop', lastTarget);
|
||||
reset();
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -205,9 +191,7 @@
|
|||
|
||||
copyStyle = (src, dst) => {
|
||||
// remove potentially troublesome attributes
|
||||
rmvAtts.forEach(function (att) {
|
||||
dst.removeAttribute(att);
|
||||
});
|
||||
['id','class','style','draggable'].forEach(att => dst.removeAttribute(att));
|
||||
// copy canvas content
|
||||
if (src instanceof HTMLCanvasElement) {
|
||||
let cSrc = src, cDst = dst;
|
||||
|
|
@ -237,10 +221,10 @@
|
|||
evt.button = 0;
|
||||
evt.which = evt.buttons = 1;
|
||||
// copy event properties into new event
|
||||
kbdProps.forEach(k => evt[k] = e[k]);
|
||||
['altKey','ctrlKey','metaKey','shiftKey'].forEach(k => evt[k] = e[k]);
|
||||
let src = e.touches ? e.touches[0] : e;
|
||||
ptProps.forEach(k => evt[k] = src[k]);
|
||||
if (isDragging) {
|
||||
['pageX','pageY','clientX','clientY','screenX','screenY','offsetX','offsetY'].forEach(k => evt[k] = src[k]);
|
||||
if (dragSource) {
|
||||
evt.dataTransfer = dataTransfer;
|
||||
}
|
||||
return target.dispatchEvent(evt);
|
||||
|
|
@ -249,7 +233,7 @@
|
|||
};
|
||||
|
||||
// Chrome on mobile supports drag & drop
|
||||
if (ua.includes("mobile") && ua.includes('gecko/')) {
|
||||
if (ua.includes('mobile') && ua.includes('gecko/')) {
|
||||
let opt = { passive: false, capture: false };
|
||||
doc.addEventListener('touchstart', touchstart, opt);
|
||||
doc.addEventListener('touchmove', touchmove, opt);
|
||||
|
|
|
|||
|
|
@ -8,37 +8,35 @@ const
|
|||
_scopes = {},
|
||||
toArray = v => Array.isArray(v) ? v : v.split(/\s*,\s*/),
|
||||
|
||||
fire = (actions, event) => {
|
||||
let modifiers = [];
|
||||
event.altKey && modifiers.push('alt');
|
||||
event.ctrlKey && modifiers.push('ctrl');
|
||||
event.metaKey && modifiers.push('meta');
|
||||
event.shiftKey && modifiers.push('shift');
|
||||
modifiers = modifiers.join('+');
|
||||
if (actions[modifiers]) {
|
||||
// for each potential shortcut
|
||||
actions[modifiers].forEach(cmd => {
|
||||
try {
|
||||
// call the handler and stop the event if neccessary
|
||||
if (!event.defaultPrevented && cmd(event) === false) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
keydown = event => {
|
||||
let key = (event.key || event.code || '').toLowerCase(),
|
||||
scopes = [];
|
||||
scope[key] && scopes.push(scope[key]);
|
||||
_scope !== 'all' && _scopes.all[key] && scopes.push(_scopes.all[key]);
|
||||
if (scopes.length && win.shortcuts.filter(event.target)) {
|
||||
let modifiers = [];
|
||||
event.altKey && modifiers.push('alt');
|
||||
event.ctrlKey && modifiers.push('ctrl');
|
||||
event.metaKey && modifiers.push('meta');
|
||||
event.shiftKey && modifiers.push('shift');
|
||||
modifiers = modifiers.join('+');
|
||||
scopes.forEach(actions => {
|
||||
if (actions[modifiers]) {
|
||||
// for each potential shortcut
|
||||
actions[modifiers].forEach(cmd => {
|
||||
try {
|
||||
// call the handler and stop the event if neccessary
|
||||
if (!event.defaultPrevented && cmd(event) === false) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
keydown = event => {
|
||||
const key = (event.key||event.code||'').toLowerCase();
|
||||
if (scope[key] && win.shortcuts.filter(event.target)) {
|
||||
fire(scope[key], event);
|
||||
}
|
||||
if (!event.defaultPrevented && _scope !== 'all' && _scopes.all[key] && win.shortcuts.filter(event.target)) {
|
||||
fire(_scopes.all[key], event);
|
||||
}
|
||||
};
|
||||
|
||||
let
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue