Bugfix boostrap alerts.less was accidentally removed

Bugfix Date.fromNow('past'/'future') reversed
Replace Events[pub/sub]('interval.*') with setInterval()
Events[pub/sub] to native
Cleanup knockout extensions
Replaced momentToNode with proper HTML5 <time>
Cleanup Momentor
This commit is contained in:
djmaze 2020-08-14 20:35:39 +02:00
parent 6541a1de7c
commit 9f1ea1a0fd
44 changed files with 539 additions and 1126 deletions

View file

@ -1,5 +1,4 @@
import * as Links from 'Common/Links';
import * as Events from 'Common/Events';
class Audio {
notificator = null;
@ -37,7 +36,7 @@ class Audio {
this.player.addEventListener('ended', stopFn);
this.player.addEventListener('error', stopFn);
Events.sub('audio.api.stop', stopFn);
addEventListener('audio.api.stop', stopFn);
}
}
@ -66,7 +65,7 @@ class Audio {
this.player.pause();
}
Events.pub('audio.stop');
dispatchEvent(new CustomEvent('audio.stop'));
}
pause() {
@ -87,7 +86,7 @@ class Audio {
this.player.src = url;
this.player.play();
Events.pub('audio.start', [this.clearName(name, 'mp3'), 'mp3']);
dispatchEvent(new CustomEvent('audio.start', {detail:this.clearName(name, 'mp3')}));
}
}
@ -99,7 +98,7 @@ class Audio {
name = this.clearName(name, 'oga');
name = this.clearName(name, 'ogg');
Events.pub('audio.start', [name, 'ogg']);
dispatchEvent(new CustomEvent('audio.start', {detail:name}));
}
}
@ -108,7 +107,7 @@ class Audio {
this.player.src = url;
this.player.play();
Events.pub('audio.start', [this.clearName(name, 'wav'), 'wav']);
dispatchEvent(new CustomEvent('audio.start', {detail:this.clearName(name, 'wav')}));
}
}

View file

@ -4,21 +4,21 @@
* @enum {string}
*/
export const FileType = {
'Unknown': 'unknown',
'Text': 'text',
'Html': 'html',
'Code': 'code',
'Eml': 'eml',
'WordText': 'word-text',
'Pdf': 'pdf',
'Image': 'image',
'Audio': 'audio',
'Video': 'video',
'Sheet': 'sheet',
'Presentation': 'presentation',
'Certificate': 'certificate',
'CertificateBin': 'certificate-bin',
'Archive': 'archive',
Unknown: 'unknown',
Text: 'text',
Html: 'html',
Code: 'code',
Eml: 'eml',
WordText: 'word-text',
Pdf: 'pdf',
Image: 'image',
Audio: 'audio',
Video: 'video',
Sheet: 'sheet',
Presentation: 'presentation',
Certificate: 'certificate',
CertificateBin: 'certificate-bin',
Archive: 'archive',
getIconClass: function(type) {
let result = ['icon-file', ''];
@ -67,483 +67,483 @@ export const FileType = {
* @enum {string}
*/
export const StorageResultType = {
'Success': 'success',
'Abort': 'abort',
'Error': 'error',
'Unload': 'unload'
Success: 'success',
Abort: 'abort',
Error: 'error',
Unload: 'unload'
};
/**
* @enum {string}
*/
export const Focused = {
'None': 'none',
'MessageList': 'message-list',
'MessageView': 'message-view',
'FolderList': 'folder-list'
None: 'none',
MessageList: 'message-list',
MessageView: 'message-view',
FolderList: 'folder-list'
};
/**
* @enum {number}
*/
export const State = {
'Empty': 10,
'Login': 20,
'Auth': 30
Empty: 10,
Login: 20,
Auth: 30
};
/**
* @enum {number}
*/
export const StateType = {
'Webmail': 0,
'Admin': 1
Webmail: 0,
Admin: 1
};
/**
* @enum {string}
*/
export const Capa = {
'TwoFactor': 'TWO_FACTOR',
'TwoFactorForce': 'TWO_FACTOR_FORCE',
'OpenPGP': 'OPEN_PGP',
'Prefetch': 'PREFETCH',
'Gravatar': 'GRAVATAR',
'Folders': 'FOLDERS',
'Composer': 'COMPOSER',
'Contacts': 'CONTACTS',
'Reload': 'RELOAD',
'Search': 'SEARCH',
'SearchAdv': 'SEARCH_ADV',
'MessageActions': 'MESSAGE_ACTIONS',
'MessageListActions': 'MESSAGELIST_ACTIONS',
'AttachmentsActions': 'ATTACHMENTS_ACTIONS',
'DangerousActions': 'DANGEROUS_ACTIONS',
'Settings': 'SETTINGS',
'Help': 'HELP',
'Themes': 'THEMES',
'UserBackground': 'USER_BACKGROUND',
'Sieve': 'SIEVE',
'Filters': 'FILTERS',
'AttachmentThumbnails': 'ATTACHMENT_THUMBNAILS',
'Templates': 'TEMPLATES',
'AutoLogout': 'AUTOLOGOUT',
'AdditionalAccounts': 'ADDITIONAL_ACCOUNTS',
'Identities': 'IDENTITIES'
TwoFactor: 'TWO_FACTOR',
TwoFactorForce: 'TWO_FACTOR_FORCE',
OpenPGP: 'OPEN_PGP',
Prefetch: 'PREFETCH',
Gravatar: 'GRAVATAR',
Folders: 'FOLDERS',
Composer: 'COMPOSER',
Contacts: 'CONTACTS',
Reload: 'RELOAD',
Search: 'SEARCH',
SearchAdv: 'SEARCH_ADV',
MessageActions: 'MESSAGE_ACTIONS',
MessageListActions: 'MESSAGELIST_ACTIONS',
AttachmentsActions: 'ATTACHMENTS_ACTIONS',
DangerousActions: 'DANGEROUS_ACTIONS',
Settings: 'SETTINGS',
Help: 'HELP',
Themes: 'THEMES',
UserBackground: 'USER_BACKGROUND',
Sieve: 'SIEVE',
Filters: 'FILTERS',
AttachmentThumbnails: 'ATTACHMENT_THUMBNAILS',
Templates: 'TEMPLATES',
AutoLogout: 'AUTOLOGOUT',
AdditionalAccounts: 'ADDITIONAL_ACCOUNTS',
Identities: 'IDENTITIES'
};
/**
* @enum {string}
*/
export const KeyState = {
'All': 'all',
'None': 'none',
'ContactList': 'contact-list',
'MessageList': 'message-list',
'FolderList': 'folder-list',
'MessageView': 'message-view',
'Compose': 'compose',
'Settings': 'settings',
'Menu': 'menu',
'PopupComposeOpenPGP': 'compose-open-pgp',
'PopupMessageOpenPGP': 'message-open-pgp',
'PopupViewOpenPGP': 'view-open-pgp',
'PopupKeyboardShortcutsHelp': 'popup-keyboard-shortcuts-help',
'PopupAsk': 'popup-ask'
All: 'all',
None: 'none',
ContactList: 'contact-list',
MessageList: 'message-list',
FolderList: 'folder-list',
MessageView: 'message-view',
Compose: 'compose',
Settings: 'settings',
Menu: 'menu',
PopupComposeOpenPGP: 'compose-open-pgp',
PopupMessageOpenPGP: 'message-open-pgp',
PopupViewOpenPGP: 'view-open-pgp',
PopupKeyboardShortcutsHelp: 'popup-keyboard-shortcuts-help',
PopupAsk: 'popup-ask'
};
/**
* @enum {number}
*/
export const FolderType = {
'Inbox': 10,
'SentItems': 11,
'Draft': 12,
'Trash': 13,
'Spam': 14,
'Archive': 15,
'NotSpam': 80,
'User': 99
Inbox: 10,
SentItems: 11,
Draft: 12,
Trash: 13,
Spam: 14,
Archive: 15,
NotSpam: 80,
User: 99
};
/**
* @enum {number}
*/
export const ServerFolderType = {
'USER': 0,
'INBOX': 1,
'SENT': 2,
'DRAFTS': 3,
'JUNK': 4,
'TRASH': 5,
'IMPORTANT': 10,
'FLAGGED': 11,
'ALL': 12
USER: 0,
INBOX: 1,
SENT: 2,
DRAFTS: 3,
JUNK: 4,
TRASH: 5,
IMPORTANT: 10,
FLAGGED: 11,
ALL: 12
};
/**
* @enum {string}
*/
export const LoginSignMeTypeAsString = {
'DefaultOff': 'defaultoff',
'DefaultOn': 'defaulton',
'Unused': 'unused'
DefaultOff: 'defaultoff',
DefaultOn: 'defaulton',
Unused: 'unused'
};
/**
* @enum {number}
*/
export const LoginSignMeType = {
'DefaultOff': 0,
'DefaultOn': 1,
'Unused': 2
DefaultOff: 0,
DefaultOn: 1,
Unused: 2
};
/**
* @enum {string}
*/
export const ComposeType = {
'Empty': 'empty',
'Reply': 'reply',
'ReplyAll': 'replyall',
'Forward': 'forward',
'ForwardAsAttachment': 'forward-as-attachment',
'Draft': 'draft',
'EditAsNew': 'editasnew'
Empty: 'empty',
Reply: 'reply',
ReplyAll: 'replyall',
Forward: 'forward',
ForwardAsAttachment: 'forward-as-attachment',
Draft: 'draft',
EditAsNew: 'editasnew'
};
/**
* @enum {number}
*/
export const UploadErrorCode = {
'Normal': 0,
'FileIsTooBig': 1,
'FilePartiallyUploaded': 2,
'FileNoUploaded': 3,
'MissingTempFolder': 4,
'FileOnSaveingError': 5,
'FileType': 98,
'Unknown': 99
Normal: 0,
FileIsTooBig: 1,
FilePartiallyUploaded: 2,
FileNoUploaded: 3,
MissingTempFolder: 4,
FileOnSaveingError: 5,
FileType: 98,
Unknown: 99
};
/**
* @enum {number}
*/
export const SetSystemFoldersNotification = {
'None': 0,
'Sent': 1,
'Draft': 2,
'Spam': 3,
'Trash': 4,
'Archive': 5
None: 0,
Sent: 1,
Draft: 2,
Spam: 3,
Trash: 4,
Archive: 5
};
/**
* @enum {number}
*/
export const ClientSideKeyName = {
'FoldersLashHash': 0,
'MessagesInboxLastHash': 1,
'MailBoxListSize': 2,
'ExpandedFolders': 3,
'FolderListSize': 4,
'MessageListSize': 5,
'LastReplyAction': 6,
'LastSignMe': 7,
'ComposeLastIdentityID': 8,
'MessageHeaderFullInfo': 9,
'MessageAttachmnetControls': 10
FoldersLashHash: 0,
MessagesInboxLastHash: 1,
MailBoxListSize: 2,
ExpandedFolders: 3,
FolderListSize: 4,
MessageListSize: 5,
LastReplyAction: 6,
LastSignMe: 7,
ComposeLastIdentityID: 8,
MessageHeaderFullInfo: 9,
MessageAttachmnetControls: 10
};
/**
* @enum {number}
*/
export const EventKeyCode = {
'Backspace': 8,
'Tab': 9,
'Enter': 13,
'Esc': 27,
'PageUp': 33,
'PageDown': 34,
'Left': 37,
'Right': 39,
'Up': 38,
'Down': 40,
'End': 35,
'Home': 36,
'Space': 32,
'Insert': 45,
'Delete': 46,
'A': 65,
'S': 83
Backspace: 8,
Tab: 9,
Enter: 13,
Esc: 27,
PageUp: 33,
PageDown: 34,
Left: 37,
Right: 39,
Up: 38,
Down: 40,
End: 35,
Home: 36,
Space: 32,
Insert: 45,
Delete: 46,
A: 65,
S: 83
};
/**
* @enum {number}
*/
export const MessageSetAction = {
'SetSeen': 0,
'UnsetSeen': 1,
'SetFlag': 2,
'UnsetFlag': 3
SetSeen: 0,
UnsetSeen: 1,
SetFlag: 2,
UnsetFlag: 3
};
/**
* @enum {number}
*/
export const MessageSelectAction = {
'All': 0,
'None': 1,
'Invert': 2,
'Unseen': 3,
'Seen': 4,
'Flagged': 5,
'Unflagged': 6
All: 0,
None: 1,
Invert: 2,
Unseen: 3,
Seen: 4,
Flagged: 5,
Unflagged: 6
};
/**
* @enum {number}
*/
export const DesktopNotification = {
'Allowed': 0,
'NotAllowed': 1,
'Denied': 2,
'NotSupported': 9
Allowed: 0,
NotAllowed: 1,
Denied: 2,
NotSupported: 9
};
/**
* @enum {number}
*/
export const MessagePriority = {
'Low': 5,
'Normal': 3,
'High': 1
Low: 5,
Normal: 3,
High: 1
};
/**
* @enum {string}
*/
export const EditorDefaultType = {
'Html': 'Html',
'Plain': 'Plain',
'HtmlForced': 'HtmlForced',
'PlainForced': 'PlainForced'
Html: 'Html',
Plain: 'Plain',
HtmlForced: 'HtmlForced',
PlainForced: 'PlainForced'
};
/**
* @enum {number}
*/
export const ServerSecure = {
'None': 0,
'SSL': 1,
'TLS': 2
None: 0,
SSL: 1,
TLS: 2
};
/**
* @enum {number}
*/
export const SearchDateType = {
'All': -1,
'Days3': 3,
'Days7': 7,
'Month': 30
All: -1,
Days3: 3,
Days7: 7,
Month: 30
};
/**
* @enum {number}
*/
export const SaveSettingsStep = {
'Animate': -2,
'Idle': -1,
'TrueResult': 1,
'FalseResult': 0
Animate: -2,
Idle: -1,
TrueResult: 1,
FalseResult: 0
};
/**
* @enum {number}
*/
export const Layout = {
'NoPreview': 0,
'SidePreview': 1,
'BottomPreview': 2
NoPreview: 0,
SidePreview: 1,
BottomPreview: 2
};
/**
* @enum {string}
*/
export const FilterConditionField = {
'From': 'From',
'Recipient': 'Recipient',
'Subject': 'Subject',
'Header': 'Header',
'Size': 'Size'
From: 'From',
Recipient: 'Recipient',
Subject: 'Subject',
Header: 'Header',
Size: 'Size'
};
/**
* @enum {string}
*/
export const FilterConditionType = {
'Contains': 'Contains',
'NotContains': 'NotContains',
'EqualTo': 'EqualTo',
'NotEqualTo': 'NotEqualTo',
'Regex': 'Regex',
'Over': 'Over',
'Under': 'Under'
Contains: 'Contains',
NotContains: 'NotContains',
EqualTo: 'EqualTo',
NotEqualTo: 'NotEqualTo',
Regex: 'Regex',
Over: 'Over',
Under: 'Under'
};
/**
* @enum {string}
*/
export const FiltersAction = {
'None': 'None',
'MoveTo': 'MoveTo',
'Discard': 'Discard',
'Vacation': 'Vacation',
'Reject': 'Reject',
'Forward': 'Forward'
None: 'None',
MoveTo: 'MoveTo',
Discard: 'Discard',
Vacation: 'Vacation',
Reject: 'Reject',
Forward: 'Forward'
};
/**
* @enum {string}
*/
export const FilterRulesType = {
'All': 'All',
'Any': 'Any'
All: 'All',
Any: 'Any'
};
/**
* @enum {number}
*/
export const SignedVerifyStatus = {
'UnknownPublicKeys': -4,
'UnknownPrivateKey': -3,
'Unverified': -2,
'Error': -1,
'None': 0,
'Success': 1
UnknownPublicKeys: -4,
UnknownPrivateKey: -3,
Unverified: -2,
Error: -1,
None: 0,
Success: 1
};
/**
* @enum {number}
*/
export const ContactPropertyType = {
'Unknown': 0,
Unknown: 0,
'FullName': 10,
FullName: 10,
'FirstName': 15,
'LastName': 16,
'MiddleName': 16,
'Nick': 18,
FirstName: 15,
LastName: 16,
MiddleName: 16,
Nick: 18,
'NamePrefix': 20,
'NameSuffix': 21,
NamePrefix: 20,
NameSuffix: 21,
'Email': 30,
'Phone': 31,
'Web': 32,
Email: 30,
Phone: 31,
Web: 32,
'Birthday': 40,
Birthday: 40,
'Facebook': 90,
'Skype': 91,
'GitHub': 92,
Facebook: 90,
Skype: 91,
GitHub: 92,
'Note': 110,
Note: 110,
'Custom': 250
Custom: 250
};
/**
* @enum {number}
*/
export const Ports = {
'Imap': 143,
'ImapSsl': 993,
'Smtp': 25,
'SmtpSsl': 465,
'SmtpStartTls': 587
Imap: 143,
ImapSsl: 993,
Smtp: 25,
SmtpSsl: 465,
SmtpStartTls: 587
};
/**
* @enum {number}
*/
export const Notification = {
'InvalidToken': 101,
'AuthError': 102,
'AccessError': 103,
'ConnectionError': 104,
'CaptchaError': 105,
'SocialFacebookLoginAccessDisable': 106,
'SocialTwitterLoginAccessDisable': 107,
'SocialGoogleLoginAccessDisable': 108,
'DomainNotAllowed': 109,
'AccountNotAllowed': 110,
InvalidToken: 101,
AuthError: 102,
AccessError: 103,
ConnectionError: 104,
CaptchaError: 105,
SocialFacebookLoginAccessDisable: 106,
SocialTwitterLoginAccessDisable: 107,
SocialGoogleLoginAccessDisable: 108,
DomainNotAllowed: 109,
AccountNotAllowed: 110,
'AccountTwoFactorAuthRequired': 120,
'AccountTwoFactorAuthError': 121,
AccountTwoFactorAuthRequired: 120,
AccountTwoFactorAuthError: 121,
'CouldNotSaveNewPassword': 130,
'CurrentPasswordIncorrect': 131,
'NewPasswordShort': 132,
'NewPasswordWeak': 133,
'NewPasswordForbidden': 134,
CouldNotSaveNewPassword: 130,
CurrentPasswordIncorrect: 131,
NewPasswordShort: 132,
NewPasswordWeak: 133,
NewPasswordForbidden: 134,
'ContactsSyncError': 140,
ContactsSyncError: 140,
'CantGetMessageList': 201,
'CantGetMessage': 202,
'CantDeleteMessage': 203,
'CantMoveMessage': 204,
'CantCopyMessage': 205,
CantGetMessageList: 201,
CantGetMessage: 202,
CantDeleteMessage: 203,
CantMoveMessage: 204,
CantCopyMessage: 205,
'CantSaveMessage': 301,
'CantSendMessage': 302,
'InvalidRecipients': 303,
CantSaveMessage: 301,
CantSendMessage: 302,
InvalidRecipients: 303,
'CantSaveFilters': 351,
'CantGetFilters': 352,
'FiltersAreNotCorrect': 355,
CantSaveFilters: 351,
CantGetFilters: 352,
FiltersAreNotCorrect: 355,
'CantCreateFolder': 400,
'CantRenameFolder': 401,
'CantDeleteFolder': 402,
'CantSubscribeFolder': 403,
'CantUnsubscribeFolder': 404,
'CantDeleteNonEmptyFolder': 405,
CantCreateFolder: 400,
CantRenameFolder: 401,
CantDeleteFolder: 402,
CantSubscribeFolder: 403,
CantUnsubscribeFolder: 404,
CantDeleteNonEmptyFolder: 405,
'CantSaveSettings': 501,
'CantSavePluginSettings': 502,
CantSaveSettings: 501,
CantSavePluginSettings: 502,
'DomainAlreadyExists': 601,
DomainAlreadyExists: 601,
'CantInstallPackage': 701,
'CantDeletePackage': 702,
'InvalidPluginPackage': 703,
'UnsupportedPluginPackage': 704,
CantInstallPackage: 701,
CantDeletePackage: 702,
InvalidPluginPackage: 703,
UnsupportedPluginPackage: 704,
'LicensingServerIsUnavailable': 710,
'LicensingExpired': 711,
'LicensingBanned': 712,
LicensingServerIsUnavailable: 710,
LicensingExpired: 711,
LicensingBanned: 712,
'DemoSendMessageError': 750,
'DemoAccountError': 751,
DemoSendMessageError: 750,
DemoAccountError: 751,
'AccountAlreadyExists': 801,
'AccountDoesNotExist': 802,
AccountAlreadyExists: 801,
AccountDoesNotExist: 802,
'MailServerError': 901,
'ClientViewError': 902,
'InvalidInputArgument': 903,
MailServerError: 901,
ClientViewError: 902,
InvalidInputArgument: 903,
'AjaxFalse': 950,
'AjaxAbort': 951,
'AjaxParse': 952,
'AjaxTimeout': 953,
AjaxFalse: 950,
AjaxAbort: 951,
AjaxParse: 952,
AjaxTimeout: 953,
'UnknownNotification': 999,
'UnknownError': 999
UnknownNotification: 999,
UnknownError: 999
,getKeyByValue: function(v) { return Object.keys(this).find(key => this[key] === v); }
};

View file

@ -1,41 +0,0 @@
import * as Plugins from 'Common/Plugins';
const SUBS = {};
/**
* @param {string|Object} name
* @param {Function} func
* @param {Object=} context
*/
export function sub(name, func, context) {
if (typeof name === 'object') {
context = func || null;
func = null;
Object.entries(name).forEach(([subFunc, subName]) => {
sub(subName, subFunc, context);
});
} else {
if (undefined === SUBS[name]) {
SUBS[name] = [];
}
SUBS[name].push([func, context]);
}
}
/**
* @param {string} name
* @param {Array=} args
*/
export function pub(name, args) {
Plugins.runHook('rl-pub', [name, args]);
if (undefined !== SUBS[name]) {
SUBS[name].forEach(items => {
if (items[0]) {
items[0].apply(items[1] || null, args || []);
}
});
}
}

View file

@ -1,114 +1,65 @@
import { i18n } from 'Common/Translator';
let _moment = null;
let d;
/**
* @returns {moment}
*/
function momentNow() {
if (!d) {
d = setTimeout(()=>d=0, 500);
_moment = new Date();
}
return _moment;
}
/**
* @returns {number}
*/
export function momentNowUnix() {
return momentNow().getTime() / 1000;
}
/**
* @param {Object} m
* @returns {string}
*/
function formatCustomShortDate(m) {
const now = momentNow();
if (m && now) {
switch (true) {
case 4 >= (now.getTime() - m.getTime()) / 3600000:
return m.fromNow();
case now.format('L') === m.format('L'):
return i18n('MESSAGE_LIST/TODAY_AT', {
TIME: m.format('LT')
});
case new Date(now.getTime() - 86400000) // subtract 1 day
.format('L') === m.format('L'):
return i18n('MESSAGE_LIST/YESTERDAY_AT', {
TIME: m.format('LT')
});
case now.getFullYear() === m.getFullYear():
return m.format('d M.');
// no default
let d,
_moment = null,
momentNow = () => {
if (!d) {
d = setTimeout(()=>d=0, 500);
_moment = new Date();
}
}
return _moment;
};
return m ? m.format('LL') : '';
}
/**
* @param {number} timeStampInUTC
* @param {string} formatStr
* @returns {string}
*/
export function format(timeStampInUTC, formatStr) {
let m = null,
result = '';
const now = Date.now() / 1000;
const now = momentNowUnix();
timeStampInUTC = 0 < timeStampInUTC ? Math.min(now, timeStampInUTC) : (0 === timeStampInUTC ? now : 0);
timeStampInUTC = 0 < timeStampInUTC ? timeStampInUTC : 0 === timeStampInUTC ? now : 0;
timeStampInUTC = now < timeStampInUTC ? now : timeStampInUTC;
m = 0 < timeStampInUTC ? new Date(timeStampInUTC * 1000) : null;
if (m && 1970 === m.getFullYear()) {
m = null;
}
if (m) {
if (31536000 < timeStampInUTC) {
const m = new Date(timeStampInUTC * 1000);
switch (formatStr) {
case 'FROMNOW':
result = m.fromNow();
break;
return m.fromNow();
case 'SHORT':
result = formatCustomShortDate(m);
break;
if (4 >= (now - timeStampInUTC) / 3600)
return m.fromNow();
if (momentNow().format('Ymd') === m.format('Ymd'))
return i18n('MESSAGE_LIST/TODAY_AT', {TIME: m.format('LT')});
if (new Date((now - 86400) * 1000).format('Ymd') === m.format('Ymd'))
return i18n('MESSAGE_LIST/YESTERDAY_AT', {TIME: m.format('LT')});
if (momentNow().getFullYear() === m.getFullYear())
return m.format('d M.');
return m.format('LL');
case 'FULL':
result = m.format('LLL');
break;
return m.format('LLL');
default:
result = m.format(formatStr);
break;
return m.format(formatStr);
}
}
return result;
return '';
}
/**
* @param {Object} element
* @returns {void}
*/
export function momentToNode(element) {
let key = '',
time = 0;
const $el = jQuery(element);
export function timeToNode(element, time) {
try {
time = time || (Date.parse(element.dateTime) / 1000);
if (time) {
let key, m = new Date(time * 1000);
element.dateTime = m.format('Y-m-d\\TH:i:s');
time = $el.data('moment-time');
if (time) {
key = $el.data('moment-format');
if (key) {
$el.text(format(time, key));
}
key = element.dataset.momentFormat;
if (key) {
element.textContent = format(time, key);
}
key = $el.data('moment-format-title');
if (key) {
$el.attr('title', format(time, key));
key = element.dataset.momentFormatTitle;
if (key) {
element.title = format(time, key);
}
}
} catch (e) {
// prevent knockout crashes
console.error(e);
}
}
@ -117,8 +68,6 @@ export function momentToNode(element) {
*/
export function reload() {
setTimeout(() =>
jQuery('.moment', document).each((index, item) => {
momentToNode(item);
})
document.querySelectorAll('[data-bind*="moment:"]').forEach(element => timeToNode(element))
, 1);
}

View file

@ -55,7 +55,7 @@ class Selector {
var d, o = this;
this.itemSelectedThrottle = (item)=>{
// debounce
d && clearTimeout(d);
clearTimeout(d);
d = setTimeout(()=>o.itemSelected(item), 300);
};

View file

@ -845,7 +845,7 @@ export function selectElement(element) {
var dv;
export const detectDropdownVisibility = ()=>{
// leading debounce
dv && clearTimeout(dv);
clearTimeout(dv);
dv = setTimeout(()=>
dropdownVisibility(!!GlobalsData.aBootstrapDropdowns.find(item => item.hasClass('open')))
, 50);
@ -1223,7 +1223,7 @@ export function mailToHelper(mailToUrl, PopupComposeViewModel) {
var wr;
export const windowResize = timeout => {
wr && clearTimeout(wr);
clearTimeout(wr);
if (undefined === timeout || null === timeout) {
$win.trigger('resize');
} else {