mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-30 12:39:20 +03:00
isArray to native Array.isArray
isUnd(*) to native undefined === *
isFunc to native typeof * === 'function'
isObject to native typeof * === 'object'
microtime() to native Date().getTime();
noop to native ()=>{}
noopFalse to native ()=>false
noopTrue to native ()=>true
boolToAjax to native *?'1':'0'
Underscore.js to native
This commit is contained in:
parent
fa39c7ecba
commit
ea48f5060b
72 changed files with 551 additions and 775 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import ko from 'ko';
|
||||
|
||||
import { StorageResultType, Notification } from 'Common/Enums';
|
||||
import { trim, isUnd } from 'Common/Utils';
|
||||
import { trim } from 'Common/Utils';
|
||||
import { RAINLOOP_TRIAL_KEY } from 'Common/Consts';
|
||||
import { i18n, getNotification } from 'Common/Translator';
|
||||
|
||||
|
|
@ -89,7 +89,7 @@ class ActivatePopupView extends AbstractViewNext {
|
|||
onShow(isTrial) {
|
||||
this.domain(Settings.settingsGet('AdminDomain'));
|
||||
if (!this.activateProcess()) {
|
||||
isTrial = isUnd(isTrial) ? false : !!isTrial;
|
||||
isTrial = undefined === isTrial ? false : !!isTrial;
|
||||
|
||||
this.key(isTrial ? RAINLOOP_TRIAL_KEY : '');
|
||||
this.activateText('');
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import ko from 'ko';
|
|||
import key from 'key';
|
||||
|
||||
import { KeyState } from 'Common/Enums';
|
||||
import { isFunc } from 'Common/Utils';
|
||||
import { i18n } from 'Common/Translator';
|
||||
|
||||
import { popup } from 'Knoin/Knoin';
|
||||
|
|
@ -46,7 +45,7 @@ class AskPopupView extends AbstractViewNext {
|
|||
yesClick() {
|
||||
this.cancelCommand();
|
||||
|
||||
if (isFunc(this.fYesAction)) {
|
||||
if (typeof this.fYesAction === 'function') {
|
||||
this.fYesAction.call(null);
|
||||
}
|
||||
}
|
||||
|
|
@ -54,7 +53,7 @@ class AskPopupView extends AbstractViewNext {
|
|||
noClick() {
|
||||
this.cancelCommand();
|
||||
|
||||
if (isFunc(this.fNoAction)) {
|
||||
if (typeof this.fNoAction === 'function') {
|
||||
this.fNoAction.call(null);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
import window from 'window';
|
||||
import _ from '_';
|
||||
import $ from '$';
|
||||
import ko from 'ko';
|
||||
import key from 'key';
|
||||
|
|
@ -19,18 +17,15 @@ import {
|
|||
|
||||
import {
|
||||
trim,
|
||||
isArray,
|
||||
isNormal,
|
||||
delegateRun,
|
||||
isNonEmptyArray,
|
||||
clearBqSwitcher,
|
||||
replySubjectAdd,
|
||||
encodeHtml,
|
||||
noopFalse,
|
||||
inFocus,
|
||||
delegateRunOnDestroy,
|
||||
pInt,
|
||||
isUnd
|
||||
pInt
|
||||
} from 'Common/Utils';
|
||||
|
||||
import { UNUSED_OPTION_VALUE } from 'Common/Consts';
|
||||
|
|
@ -291,8 +286,8 @@ class ComposePopupView extends AbstractViewNext {
|
|||
}
|
||||
});
|
||||
|
||||
this.attachmentsInProcess.subscribe((value) => {
|
||||
if (this.attachmentsInProcessError() && isArray(value) && value.length) {
|
||||
this.attachmentsInProcess.subscribe(value => {
|
||||
if (this.attachmentsInProcessError() && isNonEmptyArray(value)) {
|
||||
this.attachmentsInProcessError(false);
|
||||
}
|
||||
});
|
||||
|
|
@ -333,7 +328,12 @@ class ComposePopupView extends AbstractViewNext {
|
|||
this.bDisabeCloseOnEsc = true;
|
||||
this.sDefaultKeyScope = KeyState.Compose;
|
||||
|
||||
this.tryToClosePopup = _.debounce(this.tryToClosePopup.bind(this), Magics.Time200ms);
|
||||
// debounce
|
||||
var d, fn = this.tryToClosePopup.bind(this);
|
||||
this.tryToClosePopup = ()=>{
|
||||
d && clearTimeout(d);
|
||||
d = setTimeout(fn, Magics.Time200ms);
|
||||
};
|
||||
|
||||
this.emailsSource = this.emailsSource.bind(this);
|
||||
this.autosaveFunction = this.autosaveFunction.bind(this);
|
||||
|
|
@ -367,7 +367,7 @@ class ComposePopupView extends AbstractViewNext {
|
|||
if (!this.emptyToError() && !this.attachmentsInErrorError() && !this.attachmentsInProcessError()) {
|
||||
if (SettingsStore.replySameFolder()) {
|
||||
if (
|
||||
isArray(this.aDraftInfo) &&
|
||||
Array.isArray(this.aDraftInfo) &&
|
||||
3 === this.aDraftInfo.length &&
|
||||
isNormal(this.aDraftInfo[2]) &&
|
||||
this.aDraftInfo[2].length
|
||||
|
|
@ -386,7 +386,7 @@ class ComposePopupView extends AbstractViewNext {
|
|||
this.sendError(false);
|
||||
this.sending(true);
|
||||
|
||||
if (isArray(this.aDraftInfo) && 3 === this.aDraftInfo.length) {
|
||||
if (Array.isArray(this.aDraftInfo) && 3 === this.aDraftInfo.length) {
|
||||
const flagsCache = getMessageFlagsFromCache(this.aDraftInfo[2], this.aDraftInfo[1]);
|
||||
if (flagsCache) {
|
||||
if ('forward' === this.aDraftInfo[0]) {
|
||||
|
|
@ -531,12 +531,12 @@ class ComposePopupView extends AbstractViewNext {
|
|||
}
|
||||
|
||||
autosaveStart() {
|
||||
window.clearTimeout(this.iTimer);
|
||||
this.iTimer = window.setTimeout(this.autosaveFunction, Magics.Time1m);
|
||||
clearTimeout(this.iTimer);
|
||||
this.iTimer = setTimeout(this.autosaveFunction, Magics.Time1m);
|
||||
}
|
||||
|
||||
autosaveStop() {
|
||||
window.clearTimeout(this.iTimer);
|
||||
clearTimeout(this.iTimer);
|
||||
}
|
||||
|
||||
emailsSource(oData, fResponse) {
|
||||
|
|
@ -672,7 +672,7 @@ class ComposePopupView extends AbstractViewNext {
|
|||
this.draftFolder(oData.Result.NewFolder);
|
||||
this.draftUid(oData.Result.NewUid);
|
||||
|
||||
this.savedTime(window.Math.round(new window.Date().getTime() / 1000));
|
||||
this.savedTime(Math.round(new Date().getTime() / 1000));
|
||||
|
||||
if (this.bFromDraft) {
|
||||
setFolderHash(this.draftFolder(), '');
|
||||
|
|
@ -907,9 +907,9 @@ class ComposePopupView extends AbstractViewNext {
|
|||
oMessageOrArray = oMessageOrArray || null;
|
||||
if (oMessageOrArray && isNormal(oMessageOrArray)) {
|
||||
message =
|
||||
isArray(oMessageOrArray) && 1 === oMessageOrArray.length
|
||||
Array.isArray(oMessageOrArray) && 1 === oMessageOrArray.length
|
||||
? oMessageOrArray[0]
|
||||
: !isArray(oMessageOrArray)
|
||||
: !Array.isArray(oMessageOrArray)
|
||||
? oMessageOrArray
|
||||
: null;
|
||||
}
|
||||
|
|
@ -1207,7 +1207,7 @@ class ComposePopupView extends AbstractViewNext {
|
|||
onBuild() {
|
||||
this.initUploader();
|
||||
|
||||
key('ctrl+q, command+q, ctrl+w, command+w', KeyState.Compose, noopFalse);
|
||||
key('ctrl+q, command+q, ctrl+w, command+w', KeyState.Compose, ()=>false);
|
||||
|
||||
key('`', KeyState.Compose, () => {
|
||||
if (this.oEditor && !this.oEditor.hasFocus() && !inFocus()) {
|
||||
|
|
@ -1250,9 +1250,14 @@ class ComposePopupView extends AbstractViewNext {
|
|||
});
|
||||
|
||||
Events.sub('window.resize.real', this.resizerTrigger);
|
||||
Events.sub('window.resize.real', _.debounce(this.resizerTrigger, Magics.Time50ms));
|
||||
var d, o = this;
|
||||
Events.sub('window.resize.real', ()=>{
|
||||
// debounce
|
||||
d && clearTimeout(d);
|
||||
d = setTimeout(o.resizerTrigger, Magics.Time50ms);
|
||||
});
|
||||
|
||||
window.setInterval(() => {
|
||||
setInterval(() => {
|
||||
if (this.modalVisibility() && this.oEditor) {
|
||||
this.oEditor.resize();
|
||||
}
|
||||
|
|
@ -1322,13 +1327,13 @@ class ComposePopupView extends AbstractViewNext {
|
|||
}
|
||||
|
||||
if (item) {
|
||||
item.progress(window.Math.floor((loaded / total) * 100));
|
||||
item.progress(Math.floor((loaded / total) * 100));
|
||||
}
|
||||
})
|
||||
.on('onSelect', (sId, oData) => {
|
||||
this.dragAndDropOver(false);
|
||||
|
||||
const fileName = isUnd(oData.FileName) ? '' : oData.FileName.toString(),
|
||||
const fileName = undefined === oData.FileName ? '' : oData.FileName.toString(),
|
||||
size = isNormal(oData.Size) ? pInt(oData.Size) : null,
|
||||
attachment = new ComposeAttachmentModel(sId, fileName, size);
|
||||
|
||||
|
|
@ -1394,7 +1399,7 @@ class ComposePopupView extends AbstractViewNext {
|
|||
attachment.initByUploadJson(attachmentJson);
|
||||
}
|
||||
|
||||
if (isUnd(uploadCache[id])) {
|
||||
if (undefined === uploadCache[id]) {
|
||||
delete uploadCache[id];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import $ from '$';
|
|||
import ko from 'ko';
|
||||
import key from 'key';
|
||||
|
||||
import { pString, log, isUnd, trim, defautOptionsAfterRender } from 'Common/Utils';
|
||||
import { pString, log, trim, defautOptionsAfterRender } from 'Common/Utils';
|
||||
|
||||
import { Magics, KeyState } from 'Common/Enums';
|
||||
import { i18n } from 'Common/Translator';
|
||||
|
|
@ -102,7 +102,7 @@ class ComposeOpenPgpPopupView extends AbstractViewNext {
|
|||
this.addOptionClass = (domOption, item) => {
|
||||
this.defautOptionsAfterRender(domOption, item);
|
||||
|
||||
if (item && !isUnd(item.class) && domOption) {
|
||||
if (item && undefined !== item.class && domOption) {
|
||||
$(domOption).addClass(item.class);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -22,8 +22,7 @@ import {
|
|||
windowResizeCallback,
|
||||
isNonEmptyArray,
|
||||
fakeMd5,
|
||||
pInt,
|
||||
isUnd
|
||||
pInt
|
||||
} from 'Common/Utils';
|
||||
|
||||
import { CONTACTS_PER_PAGE } from 'Common/Consts';
|
||||
|
|
@ -649,8 +648,8 @@ class ContactsPopupView extends AbstractViewNext {
|
|||
}
|
||||
|
||||
onShow(bBackToCompose, sLastComposeFocusedField) {
|
||||
this.bBackToCompose = isUnd(bBackToCompose) ? false : !!bBackToCompose;
|
||||
this.sLastComposeFocusedField = isUnd(sLastComposeFocusedField) ? '' : sLastComposeFocusedField;
|
||||
this.bBackToCompose = undefined === bBackToCompose ? false : !!bBackToCompose;
|
||||
this.sLastComposeFocusedField = undefined === sLastComposeFocusedField ? '' : sLastComposeFocusedField;
|
||||
|
||||
routeOff();
|
||||
this.reloadContactList(true);
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
import _ from '_';
|
||||
import ko from 'ko';
|
||||
|
||||
import { SetSystemFoldersNotification, Magics } from 'Common/Enums';
|
||||
import { UNUSED_OPTION_VALUE } from 'Common/Consts';
|
||||
import { folderListOptionsBuilder, noop, defautOptionsAfterRender } from 'Common/Utils';
|
||||
import { folderListOptionsBuilder, defautOptionsAfterRender } from 'Common/Utils';
|
||||
import { initOnStartOrLangChange, i18n } from 'Common/Translator';
|
||||
|
||||
import FolderStore from 'Stores/User/Folder';
|
||||
|
|
@ -56,6 +55,7 @@ class FolderSystemPopupView extends AbstractViewNext {
|
|||
this.trashFolder = FolderStore.trashFolder;
|
||||
this.archiveFolder = FolderStore.archiveFolder;
|
||||
|
||||
var d;
|
||||
const fSetSystemFolders = () => {
|
||||
Settings.settingsSet('SentFolder', FolderStore.sentFolder());
|
||||
Settings.settingsSet('DraftFolder', FolderStore.draftFolder());
|
||||
|
|
@ -63,17 +63,21 @@ class FolderSystemPopupView extends AbstractViewNext {
|
|||
Settings.settingsSet('TrashFolder', FolderStore.trashFolder());
|
||||
Settings.settingsSet('ArchiveFolder', FolderStore.archiveFolder());
|
||||
},
|
||||
fSaveSystemFolders = _.debounce(() => {
|
||||
fSetSystemFolders();
|
||||
Remote.saveSystemFolders(noop, {
|
||||
SentFolder: FolderStore.sentFolder(),
|
||||
DraftFolder: FolderStore.draftFolder(),
|
||||
SpamFolder: FolderStore.spamFolder(),
|
||||
TrashFolder: FolderStore.trashFolder(),
|
||||
ArchiveFolder: FolderStore.archiveFolder(),
|
||||
NullFolder: 'NullFolder'
|
||||
});
|
||||
}, Magics.Time1s),
|
||||
fSaveSystemFolders = ()=>{
|
||||
// debounce
|
||||
d && clearTimeout(d);
|
||||
d = setTimeout(()=>{
|
||||
fSetSystemFolders();
|
||||
Remote.saveSystemFolders(()=>{}, {
|
||||
SentFolder: FolderStore.sentFolder(),
|
||||
DraftFolder: FolderStore.draftFolder(),
|
||||
SpamFolder: FolderStore.spamFolder(),
|
||||
TrashFolder: FolderStore.trashFolder(),
|
||||
ArchiveFolder: FolderStore.archiveFolder(),
|
||||
NullFolder: 'NullFolder'
|
||||
});
|
||||
}, Magics.Time1s);
|
||||
},
|
||||
fCallback = () => {
|
||||
fSetSystemFolders();
|
||||
fSaveSystemFolders();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import _ from '_';
|
||||
import key from 'key';
|
||||
|
||||
import { KeyState, Magics } from 'Common/Enums';
|
||||
|
|
@ -17,32 +16,39 @@ class KeyboardShortcutsHelpPopupView extends AbstractViewNext {
|
|||
}
|
||||
|
||||
onBuild(dom) {
|
||||
var t;
|
||||
key(
|
||||
'tab, shift+tab, left, right',
|
||||
KeyState.PopupKeyboardShortcutsHelp,
|
||||
_.throttle((event, handler) => {
|
||||
if (event && handler) {
|
||||
const $tabs = dom.find('.nav.nav-tabs > li'),
|
||||
isNext = handler && ('tab' === handler.shortcut || 'right' === handler.shortcut);
|
||||
(event, handler)=>{
|
||||
// throttle
|
||||
if (!t) {
|
||||
t = setTimeout(()=>{
|
||||
t = 0;
|
||||
if (event && handler) {
|
||||
const $tabs = dom.find('.nav.nav-tabs > li'),
|
||||
isNext = handler && ('tab' === handler.shortcut || 'right' === handler.shortcut);
|
||||
|
||||
let index = $tabs.index($tabs.filter('.active'));
|
||||
if (!isNext && 0 < index) {
|
||||
index -= 1;
|
||||
} else if (isNext && index < $tabs.length - 1) {
|
||||
index += 1;
|
||||
} else {
|
||||
index = isNext ? 0 : $tabs.length - 1;
|
||||
}
|
||||
let index = $tabs.index($tabs.filter('.active'));
|
||||
if (!isNext && 0 < index) {
|
||||
index -= 1;
|
||||
} else if (isNext && index < $tabs.length - 1) {
|
||||
index += 1;
|
||||
} else {
|
||||
index = isNext ? 0 : $tabs.length - 1;
|
||||
}
|
||||
|
||||
$tabs
|
||||
.eq(index)
|
||||
.find('a[data-toggle="tab"]')
|
||||
.tab('show');
|
||||
return false;
|
||||
$tabs
|
||||
.eq(index)
|
||||
.find('a[data-toggle="tab"]')
|
||||
.tab('show');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}, Magics.Time100ms);
|
||||
}
|
||||
|
||||
return true;
|
||||
}, Magics.Time100ms)
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import _ from '_';
|
||||
import ko from 'ko';
|
||||
import key from 'key';
|
||||
|
||||
|
|
@ -43,7 +42,12 @@ class PluginPopupView extends AbstractViewNext {
|
|||
this.bDisabeCloseOnEsc = true;
|
||||
this.sDefaultKeyScope = KeyState.All;
|
||||
|
||||
this.tryToClosePopup = _.debounce(this.tryToClosePopup.bind(this), Magics.Time200ms);
|
||||
var d, fn = this.tryToClosePopup.bind(this);
|
||||
this.tryToClosePopup = ()=>{
|
||||
// debounce
|
||||
d && clearTimeout(d);
|
||||
d = setTimeout(fn, Magics.Time200ms);
|
||||
};
|
||||
}
|
||||
|
||||
@command((self) => self.hasConfiguration())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue