mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-01-02 21:12:02 +08:00
Momentor.reload to CustomEvent
This commit is contained in:
parent
9f1ea1a0fd
commit
efc2dd89e1
4 changed files with 23 additions and 38 deletions
14
README.md
14
README.md
|
@ -79,23 +79,23 @@ Things might work in Edge 16-18, Firefox 50-62 and Chrome 54-68 due to one polyf
|
|||
|
||||
|js/* |1.14.0 |native |
|
||||
|----------- |--------: |--------: |
|
||||
|admin.js |2.130.942 |1.090.923 |
|
||||
|app.js |4.184.455 |2.775.561 |
|
||||
|admin.js |2.130.942 |1.089.940 |
|
||||
|app.js |4.184.455 |2.774.461 |
|
||||
|boot.js | 671.522 | 44.029 |
|
||||
|libs.js | 647.614 | 316.107 |
|
||||
|polyfills.js | 325.834 | 0 |
|
||||
|TOTAL |7.960.367 |4.226.620 |
|
||||
|TOTAL |7.960.367 |4.224.537 |
|
||||
|
||||
|js/min/* |1.14.0 |native |gzip 1.14 |gzip |
|
||||
|--------------- |--------: |--------: |--------: |--------: |
|
||||
|admin.min.js | 252.147 | 148.293 | 73.657 | 42.376 |
|
||||
|app.min.js | 511.202 | 371.757 |140.462 | 97.432 |
|
||||
|admin.min.js | 252.147 | 148.234 | 73.657 | 42.376 |
|
||||
|app.min.js | 511.202 | 371.731 |140.462 | 97.432 |
|
||||
|boot.min.js | 66.007 | 5.589 | 22.567 | 2.332 |
|
||||
|libs.min.js | 572.545 | 300.211 |176.720 | 92.699 |
|
||||
|polyfills.min.js | 32.452 | 0 | 11.312 | 0 |
|
||||
|TOTAL |1.434.353 | 825.850 |424.718 |234.839 |
|
||||
|TOTAL |1.434.353 | 825.765 |424.718 |234.839 |
|
||||
|
||||
604.051 bytes (188.978 gzip) is not much, but it feels faster.
|
||||
608.588 bytes (189.879 gzip) is not much, but it feels faster.
|
||||
|
||||
|
||||
|css/* |1.14.0 |native |
|
||||
|
|
|
@ -23,7 +23,6 @@ import { $htmlCL, leftPanelDisabled, bMobileDevice } from 'Common/Globals';
|
|||
|
||||
import { UNUSED_OPTION_VALUE } from 'Common/Consts';
|
||||
import { runHook } from 'Common/Plugins';
|
||||
import { reload as momentReload } from 'Common/Momentor';
|
||||
|
||||
import {
|
||||
initMessageFlagsFromCache,
|
||||
|
@ -1141,7 +1140,7 @@ class AppUser extends AbstractApp {
|
|||
this.bootstartLoginScreen();
|
||||
}
|
||||
|
||||
setInterval(momentReload, 60000);
|
||||
setInterval(() => dispatchEvent(new CustomEvent('reload-time')), 60000);
|
||||
|
||||
runHook('rl-start-screens');
|
||||
}
|
||||
|
|
|
@ -1,35 +1,26 @@
|
|||
import { i18n } from 'Common/Translator';
|
||||
|
||||
let d,
|
||||
_moment = null,
|
||||
momentNow = () => {
|
||||
if (!d) {
|
||||
d = setTimeout(()=>d=0, 500);
|
||||
_moment = new Date();
|
||||
}
|
||||
return _moment;
|
||||
};
|
||||
|
||||
export function format(timeStampInUTC, formatStr) {
|
||||
const now = Date.now() / 1000;
|
||||
const now = Date.now(),
|
||||
time = 0 < timeStampInUTC ? Math.min(now, timeStampInUTC * 1000) : (0 === timeStampInUTC ? now : 0);
|
||||
|
||||
timeStampInUTC = 0 < timeStampInUTC ? Math.min(now, timeStampInUTC) : (0 === timeStampInUTC ? now : 0);
|
||||
|
||||
if (31536000 < timeStampInUTC) {
|
||||
const m = new Date(timeStampInUTC * 1000);
|
||||
if (31536000000 < time) {
|
||||
const m = new Date(time);
|
||||
switch (formatStr) {
|
||||
case 'FROMNOW':
|
||||
return m.fromNow();
|
||||
case 'SHORT':
|
||||
if (4 >= (now - timeStampInUTC) / 3600)
|
||||
case 'SHORT': {
|
||||
if (4 >= (now - time) / 3600000)
|
||||
return m.fromNow();
|
||||
if (momentNow().format('Ymd') === m.format('Ymd'))
|
||||
const ymd = m.format('Ymd'), date = new Date;
|
||||
if (date.format('Ymd') === ymd)
|
||||
return i18n('MESSAGE_LIST/TODAY_AT', {TIME: m.format('LT')});
|
||||
if (new Date((now - 86400) * 1000).format('Ymd') === m.format('Ymd'))
|
||||
if (new Date(now - 86400000).format('Ymd') === ymd)
|
||||
return i18n('MESSAGE_LIST/YESTERDAY_AT', {TIME: m.format('LT')});
|
||||
if (momentNow().getFullYear() === m.getFullYear())
|
||||
if (date.getFullYear() === m.getFullYear())
|
||||
return m.format('d M.');
|
||||
return m.format('LL');
|
||||
}
|
||||
case 'FULL':
|
||||
return m.format('LLL');
|
||||
default:
|
||||
|
@ -63,11 +54,7 @@ export function timeToNode(element, time) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {void}
|
||||
*/
|
||||
export function reload() {
|
||||
setTimeout(() =>
|
||||
addEventListener('reload-time', () => setTimeout(() =>
|
||||
document.querySelectorAll('[data-bind*="moment:"]').forEach(element => timeToNode(element))
|
||||
, 1);
|
||||
}
|
||||
, 1)
|
||||
);
|
||||
|
|
|
@ -2,7 +2,6 @@ import ko from 'ko';
|
|||
import { Notification, UploadErrorCode } from 'Common/Enums';
|
||||
import { pInt } from 'Common/Utils';
|
||||
import { $html, $htmlCL } from 'Common/Globals';
|
||||
import { reload as momentorReload } from 'Common/Momentor';
|
||||
import { langLink } from 'Common/Links';
|
||||
|
||||
let I18N_DATA = window.rainloopI18N || {};
|
||||
|
@ -148,7 +147,7 @@ const reloadData = () => {
|
|||
|
||||
i18nToNodes(document);
|
||||
|
||||
momentorReload();
|
||||
dispatchEvent(new CustomEvent('reload-time'));
|
||||
trigger(!trigger());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue