Replace timeOutAction() with debounce

Replace delegateRun()
Revert my throttle/debounce setTimeout() to Function.prototype[throttle/debounce]
This commit is contained in:
djmaze 2020-08-18 20:24:17 +02:00
parent f6a55898c7
commit 97a73c6639
28 changed files with 225 additions and 372 deletions

View file

@ -59,7 +59,7 @@ This fork uses downsized/simplified versions of scripts and has no support for I
The result is faster and smaller download code (good for mobile networks). The result is faster and smaller download code (good for mobile networks).
Things might work in Edge 16-18, Firefox 50-62 and Chrome 54-68 due to one polyfill for array.flat(). Things might work in Edge 18, Firefox 50-62 and Chrome 54-68 due to one polyfill for array.flat().
* Replaced jQuery with jQuery.slim * Replaced jQuery with jQuery.slim
* Replaced ProgressJS with simple native dropin * Replaced ProgressJS with simple native dropin
@ -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 | |js/* |1.14.0 |native |
|----------- |--------: |--------: | |----------- |--------: |--------: |
|admin.js |2.130.942 |1.089.940 | |admin.js |2.130.942 |1.082.985 |
|app.js |4.184.455 |2.774.461 | |app.js |4.184.455 |2.751.154 |
|boot.js | 671.522 | 44.029 | |boot.js | 671.522 | 43.995 |
|libs.js | 647.614 | 316.107 | |libs.js | 647.614 | 316.876 |
|polyfills.js | 325.834 | 0 | |polyfills.js | 325.834 | 0 |
|TOTAL |7.960.367 |4.224.537 | |TOTAL |7.960.367 |4.195.010 |
|js/min/* |1.14.0 |native |gzip 1.14 |gzip | |js/min/* |1.14.0 |native |gzip 1.14 |gzip |
|--------------- |--------: |--------: |--------: |--------: | |--------------- |--------: |--------: |--------: |--------: |
|admin.min.js | 252.147 | 148.234 | 73.657 | 42.376 | |admin.min.js | 252.147 | 147.526 | 73.657 | 42.213 |
|app.min.js | 511.202 | 371.731 |140.462 | 97.432 | |app.min.js | 511.202 | 369.396 |140.462 | 97.130 |
|boot.min.js | 66.007 | 5.589 | 22.567 | 2.332 | |boot.min.js | 66.007 | 5.579 | 22.567 | 2.328 |
|libs.min.js | 572.545 | 300.211 |176.720 | 92.699 | |libs.min.js | 572.545 | 300.520 |176.720 | 92.825 |
|polyfills.min.js | 32.452 | 0 | 11.312 | 0 | |polyfills.min.js | 32.452 | 0 | 11.312 | 0 |
|TOTAL |1.434.353 | 825.765 |424.718 |234.839 | |TOTAL |1.434.353 | 823.015 |424.718 |234.496 |
608.588 bytes (189.879 gzip) is not much, but it feels faster. 611.338 bytes (190.222 gzip) is not much, but it feels faster.
|css/* |1.14.0 |native | |css/* |1.14.0 |native |

View file

@ -31,25 +31,18 @@ class AbstractApp extends AbstractBoot {
this.isLocalAutocomplete = true; this.isLocalAutocomplete = true;
this.lastErrorTime = 0; this.lastErrorTime = 0;
var t;
addEventListener( addEventListener(
'resize', 'resize',
()=>{ (()=>{
// throttle const iH = $win.height(),
if (!t) { iW = $win.height();
t = setTimeout(()=>{
const iH = $win.height(),
iW = $win.height();
if ($win.__sizes[0] !== iH || $win.__sizes[1] !== iW) { if ($win.__sizes[0] !== iH || $win.__sizes[1] !== iW) {
$win.__sizes[0] = iH; $win.__sizes[0] = iH;
$win.__sizes[1] = iW; $win.__sizes[1] = iW;
dispatchEvent(new CustomEvent('resize.real')); dispatchEvent(new CustomEvent('resize.real'));
}
t = 0;
}, 50);
} }
} }).throttle(50)
); );
const $doc = document; const $doc = document;
@ -64,12 +57,7 @@ class AbstractApp extends AbstractBoot {
} }
}); });
var d; const fn = (()=>dispatchEvent(new CustomEvent('rl.auto-logout-refresh'))).debounce(5000);
const fn = ()=>{
// debounce
clearTimeout(d);
d = setTimeout(()=>dispatchEvent(new CustomEvent('rl.auto-logout-refresh')), 5000);
}
$doc.addEventListener('mousemove', fn); $doc.addEventListener('mousemove', fn);
$doc.addEventListener('keypress', fn); $doc.addEventListener('keypress', fn);

View file

@ -81,16 +81,14 @@ import { AbstractApp } from 'App/Abstract';
const doc = document; const doc = document;
if (!window.ResizeObserver) { if (!window.ResizeObserver) {
let rot;
window.ResizeObserver = class { window.ResizeObserver = class {
constructor(callback) { constructor(callback) {
callback = callback.debounce(250);
this.observer = new MutationObserver(mutations => { this.observer = new MutationObserver(mutations => {
let i = mutations.length; let i = mutations.length;
while (i--) { while (i--) {
if ('style' == mutations[i].attributeName) { if ('style' == mutations[i].attributeName) {
// debounce callback();
clearTimeout(rot);
rot = setTimeout(callback, 250);
break; break;
} }
} }
@ -113,15 +111,11 @@ class AppUser extends AbstractApp {
this.moveCache = {}; this.moveCache = {};
let qd, o = this; this.quotaDebounce = this.quota.debounce(30000);
this.quotaDebounce = ()=>{
// debounce
clearTimeout(qd);
qd = setTimeout(o.quota, 30000);
};
this.moveOrDeleteResponseHelper = this.moveOrDeleteResponseHelper.bind(this); this.moveOrDeleteResponseHelper = this.moveOrDeleteResponseHelper.bind(this);
this.messagesMoveTrigger = this.messagesMoveTrigger.debounce(500);
// wakeUp // wakeUp
const interval = 3600000; // 60m const interval = 3600000; // 60m
var lastTime = (new Date()).getTime(); var lastTime = (new Date()).getTime();
@ -262,30 +256,25 @@ class AppUser extends AbstractApp {
} }
messagesMoveTrigger() { messagesMoveTrigger() {
// debounce const sTrashFolder = FolderStore.trashFolder(),
const o = this; sSpamFolder = FolderStore.spamFolder();
clearTimeout(o.mt);
o.mt = setTimeout(()=>{
const sTrashFolder = FolderStore.trashFolder(),
sSpamFolder = FolderStore.spamFolder();
Object.values(o.moveCache).forEach(item => { Object.values(this.moveCache).forEach(item => {
const isSpam = sSpamFolder === item.To, const isSpam = sSpamFolder === item.To,
isTrash = sTrashFolder === item.To, isTrash = sTrashFolder === item.To,
isHam = !isSpam && sSpamFolder === item.From && getFolderInboxName() === item.To; isHam = !isSpam && sSpamFolder === item.From && getFolderInboxName() === item.To;
Remote.messagesMove( Remote.messagesMove(
o.moveOrDeleteResponseHelper, this.moveOrDeleteResponseHelper,
item.From, item.From,
item.To, item.To,
item.Uid, item.Uid,
isSpam ? 'SPAM' : isHam ? 'HAM' : '', isSpam ? 'SPAM' : isHam ? 'HAM' : '',
isSpam || isTrash isSpam || isTrash
); );
}); });
o.moveCache = {}; this.moveCache = {};
}, 500);
} }
messagesMoveHelper(fromFolderFullNameRaw, toFolderFullNameRaw, uidsForMove) { messagesMoveHelper(fromFolderFullNameRaw, toFolderFullNameRaw, uidsForMove) {

View file

@ -145,7 +145,7 @@ class CookieDriver {
try { try {
const storageResult = Cookies.getJSON(CLIENT_SIDE_STORAGE_INDEX_NAME); const storageResult = Cookies.getJSON(CLIENT_SIDE_STORAGE_INDEX_NAME);
result = storageResult && undefined !== storageResult[key] ? storageResult[key] : null; result = storageResult && null != storageResult[key] ? storageResult[key] : null;
} catch (e) {} // eslint-disable-line no-empty } catch (e) {} // eslint-disable-line no-empty
return result; return result;

View file

@ -47,7 +47,7 @@ class LocalStorageDriver {
const storageValue = this.s.getItem(CLIENT_SIDE_STORAGE_INDEX_NAME) || null, const storageValue = this.s.getItem(CLIENT_SIDE_STORAGE_INDEX_NAME) || null,
storageResult = null === storageValue ? null : JSON.parse(storageValue); storageResult = null === storageValue ? null : JSON.parse(storageValue);
return storageResult && undefined !== storageResult[key] ? storageResult[key] : null; return storageResult && null != storageResult[key] ? storageResult[key] : null;
} catch (e) {} // eslint-disable-line no-empty } catch (e) {} // eslint-disable-line no-empty
return null; return null;

View file

@ -32,16 +32,7 @@ class HtmlEditor {
this.element = element; this.element = element;
this.$element = jQuery(element); this.$element = jQuery(element);
// throttle this.resize = this.resizeEditor.throttle(100);
var t, o = this;
this.resize = ()=>{
if (!t) {
t = setTimeout(()=>{
o.resizeEditor();
t = 0;
}, 100);
}
};
this.init(); this.init();
} }

View file

@ -88,6 +88,6 @@ export function runSettingsViewModelHooks(admin) {
*/ */
export function settingsGet(pluginSection, name) { export function settingsGet(pluginSection, name) {
let plugins = Settings.settingsGet('Plugins'); let plugins = Settings.settingsGet('Plugins');
plugins = plugins && undefined !== plugins[pluginSection] ? plugins[pluginSection] : null; plugins = plugins && null != plugins[pluginSection] ? plugins[pluginSection] : null;
return plugins ? (undefined === plugins[name] ? null : plugins[name]) : null; return plugins ? (null == plugins[name] ? null : plugins[name]) : null;
} }

View file

@ -52,12 +52,7 @@ class Selector {
this.focusedItem = koFocusedItem || ko.observable(null); this.focusedItem = koFocusedItem || ko.observable(null);
this.selectedItem = koSelectedItem || ko.observable(null); this.selectedItem = koSelectedItem || ko.observable(null);
var d, o = this; this.itemSelectedThrottle = (item=>this.itemSelected(item)).debounce(300);
this.itemSelectedThrottle = (item)=>{
// debounce
clearTimeout(d);
d = setTimeout(()=>o.itemSelected(item), 300);
};
this.listChecked.subscribe((items) => { this.listChecked.subscribe((items) => {
if (items.length) { if (items.length) {

View file

@ -94,7 +94,7 @@ export function i18n(key, valueList, defaulValue) {
result = undefined === defaulValue ? key : defaulValue; result = undefined === defaulValue ? key : defaulValue;
} }
if (undefined !== valueList && null !== valueList) { if (null != valueList) {
for (valueName in valueList) { for (valueName in valueList) {
if (Object.prototype.hasOwnProperty.call(valueList, valueName)) { if (Object.prototype.hasOwnProperty.call(valueList, valueName)) {
result = result.replace('%' + valueName + '%', valueList[valueName]); result = result.replace('%' + valueName + '%', valueList[valueName]);

View file

@ -124,17 +124,6 @@ export function splitPlainText(text, len = 100) {
return prefix + result; return prefix + result;
} }
const timeOutAction = (() => {
const timeOuts = {};
return (action, fFunction, timeOut) => {
timeOuts[action] = undefined === timeOuts[action] ? 0 : timeOuts[action];
clearTimeout(timeOuts[action]);
timeOuts[action] = setTimeout(fFunction, timeOut);
};
})();
export { timeOutAction };
/** /**
* @param {any} m * @param {any} m
* @returns {any} * @returns {any}
@ -258,27 +247,6 @@ export function friendlySize(sizeInBytes) {
return sizeInBytes + 'B'; return sizeInBytes + 'B';
} }
/**
* @param {?} object
* @param {string} methodName
* @param {Array=} params
* @param {number=} delay = 0
*/
export function delegateRun(object, methodName, params, delay = 0) {
if (object && object[methodName]) {
delay = pInt(delay);
params = isArray(params) ? params : [];
if (0 >= delay) {
object[methodName](...params);
} else {
setTimeout(() => {
object[methodName](...params);
}, delay);
}
}
}
/** /**
* @param {(Object|null|undefined)} context * @param {(Object|null|undefined)} context
* @param {Function} fExecute * @param {Function} fExecute
@ -830,14 +798,9 @@ export function selectElement(element) {
sel.addRange(range); sel.addRange(range);
} }
var dv; export const detectDropdownVisibility = (()=>
export const detectDropdownVisibility = ()=>{ dropdownVisibility(!!GlobalsData.aBootstrapDropdowns.find(item => item.hasClass('open')))
// leading debounce ).debounce(50);
clearTimeout(dv);
dv = setTimeout(()=>
dropdownVisibility(!!GlobalsData.aBootstrapDropdowns.find(item => item.hasClass('open')))
, 50);
};
/** /**
* @param {boolean=} delay = false * @param {boolean=} delay = false
@ -881,11 +844,9 @@ export function getConfigurationFromScriptTag(configuration) {
export function delegateRunOnDestroy(objectOrObjects) { export function delegateRunOnDestroy(objectOrObjects) {
if (objectOrObjects) { if (objectOrObjects) {
if (isArray(objectOrObjects)) { if (isArray(objectOrObjects)) {
objectOrObjects.forEach(item => { objectOrObjects.forEach(item => delegateRunOnDestroy(item));
delegateRunOnDestroy(item); } else {
}); objectOrObjects.onDestroy && objectOrObjects.onDestroy();
} else if (objectOrObjects && objectOrObjects.onDestroy) {
objectOrObjects.onDestroy();
} }
} }
} }
@ -1199,8 +1160,8 @@ export function mailToHelper(mailToUrl, PopupComposeViewModel) {
to, to,
cc, cc,
bcc, bcc,
undefined === params.subject ? null : pString(decodeURIComponent(params.subject)), null == params.subject ? null : pString(decodeURIComponent(params.subject)),
undefined === params.body ? null : plainToHtml(pString(decodeURIComponent(params.body))) null == params.body ? null : plainToHtml(pString(decodeURIComponent(params.body)))
]); ]);
return true; return true;
@ -1212,7 +1173,7 @@ export function mailToHelper(mailToUrl, PopupComposeViewModel) {
var wr; var wr;
export const windowResize = timeout => { export const windowResize = timeout => {
clearTimeout(wr); clearTimeout(wr);
if (undefined === timeout || null === timeout) { if (null == timeout) {
$win.trigger('resize'); $win.trigger('resize');
} else { } else {
wr = setTimeout(()=>$win.trigger('resize'), timeout); wr = setTimeout(()=>$win.trigger('resize'), timeout);

View file

@ -1,6 +1,6 @@
import ko from 'ko'; import ko from 'ko';
import { delegateRun, inFocus } from 'Common/Utils'; import { inFocus } from 'Common/Utils';
import { KeyState, EventKeyCode } from 'Common/Enums'; import { KeyState, EventKeyCode } from 'Common/Enums';
import { keyScope } from 'Common/Globals'; import { keyScope } from 'Common/Globals';
@ -38,7 +38,7 @@ export class AbstractViewNext {
addEventListener('keydown', (event) => { addEventListener('keydown', (event) => {
if (event && this.modalVisibility && this.modalVisibility()) { if (event && this.modalVisibility && this.modalVisibility()) {
if (!this.bDisabeCloseOnEsc && EventKeyCode.Esc === event.keyCode) { if (!this.bDisabeCloseOnEsc && EventKeyCode.Esc === event.keyCode) {
delegateRun(this, 'cancelCommand'); this.cancelCommand && this.cancelCommand();
return false; return false;
} else if (EventKeyCode.Backspace === event.keyCode && !inFocus()) { } else if (EventKeyCode.Backspace === event.keyCode && !inFocus()) {
return false; return false;

View file

@ -3,7 +3,7 @@ import ko from 'ko';
import { runHook } from 'Common/Plugins'; import { runHook } from 'Common/Plugins';
import { $htmlCL, VIEW_MODELS, popupVisibilityNames } from 'Common/Globals'; import { $htmlCL, VIEW_MODELS, popupVisibilityNames } from 'Common/Globals';
import { pString, createCommandLegacy, delegateRun, isNonEmptyArray } from 'Common/Utils'; import { pString, createCommandLegacy, isNonEmptyArray } from 'Common/Utils';
let currentScreen = null, let currentScreen = null,
defaultScreenName = ''; defaultScreenName = '';
@ -90,7 +90,7 @@ export function routeOn() {
* @returns {?Object} * @returns {?Object}
*/ */
export function screen(screenName) { export function screen(screenName) {
return screenName && undefined !== SCREENS[screenName] ? SCREENS[screenName] : null; return screenName && null != SCREENS[screenName] ? SCREENS[screenName] : null;
} }
/** /**
@ -181,10 +181,10 @@ export function buildViewModel(ViewModelClass, vmScreen) {
vm.onShowTrigger(!vm.onShowTrigger()); vm.onShowTrigger(!vm.onShowTrigger());
} }
delegateRun(vm, 'onShowWithDelay', [], 500); vm.onShowWithDelay && setTimeout(()=>vm.onShowWithDelay, 500);
} else { } else {
delegateRun(vm, 'onHide'); vm.onHide && vm.onHide();
delegateRun(vm, 'onHideWithDelay', [], 500); vm.onHideWithDelay && setTimeout(()=>vm.onHideWithDelay, 500);
if (vm.onHideTrigger) { if (vm.onHideTrigger) {
vm.onHideTrigger(!vm.onHideTrigger()); vm.onHideTrigger(!vm.onHideTrigger());
@ -213,7 +213,7 @@ export function buildViewModel(ViewModelClass, vmScreen) {
vm vm
); );
delegateRun(vm, 'onBuild', [vmDom]); vm.onBuild && vm.onBuild(vmDom);
if (vm && ViewType.Popup === position) { if (vm && ViewType.Popup === position) {
vm.registerPopupKeyDown(); vm.registerPopupKeyDown();
} }
@ -238,11 +238,13 @@ export function showScreenPopup(ViewModelClassToShow, params = []) {
buildViewModel(ModalView); buildViewModel(ModalView);
if (ModalView.__vm && ModalView.__dom) { if (ModalView.__vm && ModalView.__dom) {
delegateRun(ModalView.__vm, 'onBeforeShow', params || []); params = params || [];
ModalView.__vm.onBeforeShow && ModalView.__vm.onBeforeShow(...params);
ModalView.__vm.modalVisibility(true); ModalView.__vm.modalVisibility(true);
delegateRun(ModalView.__vm, 'onShow', params || []); ModalView.__vm.onShow && ModalView.__vm.onShow(...params);
vmRunHook('view-model-on-show', ModalView, params || []); vmRunHook('view-model-on-show', ModalView, params || []);
} }
@ -259,7 +261,7 @@ export function warmUpScreenPopup(ViewModelClassToShow) {
buildViewModel(ModalView); buildViewModel(ModalView);
if (ModalView.__vm && ModalView.__dom) { if (ModalView.__vm && ModalView.__dom) {
delegateRun(ModalView.__vm, 'onWarmUp'); ModalView.__vm.onWarmUp && ModalView.__vm.onWarmUp();
} }
} }
} }
@ -309,14 +311,14 @@ export function screenOnRoute(screenName, subPart) {
}); });
} }
delegateRun(vmScreen, 'onBuild'); vmScreen.onBuild && vmScreen.onBuild();
} }
setTimeout(() => { setTimeout(() => {
// hide screen // hide screen
if (currentScreen && !isSameScreen) { if (currentScreen && !isSameScreen) {
delegateRun(currentScreen, 'onHide'); currentScreen.onHide && currentScreen.onHide();
delegateRun(currentScreen, 'onHideWithDelay', [], 500); currentScreen.onHideWithDelay && setTimeout(()=>currentScreen.onHideWithDelay(), 500);
if (currentScreen.onHideTrigger) { if (currentScreen.onHideTrigger) {
currentScreen.onHideTrigger(!currentScreen.onHideTrigger()); currentScreen.onHideTrigger(!currentScreen.onHideTrigger());
@ -332,8 +334,8 @@ export function screenOnRoute(screenName, subPart) {
ViewModelClass.__dom.hide(); ViewModelClass.__dom.hide();
ViewModelClass.__vm.viewModelVisibility(false); ViewModelClass.__vm.viewModelVisibility(false);
delegateRun(ViewModelClass.__vm, 'onHide'); ViewModelClass.__vm.onHide && ViewModelClass.__vm.onHide();
delegateRun(ViewModelClass.__vm, 'onHideWithDelay', [], 500); ViewModelClass.__vm.onHideWithDelay && setTimeout(()=>ViewModelClass.__vm.onHideWithDelay(), 500);
if (ViewModelClass.__vm.onHideTrigger) { if (ViewModelClass.__vm.onHideTrigger) {
ViewModelClass.__vm.onHideTrigger(!ViewModelClass.__vm.onHideTrigger()); ViewModelClass.__vm.onHideTrigger(!ViewModelClass.__vm.onHideTrigger());
@ -348,7 +350,7 @@ export function screenOnRoute(screenName, subPart) {
// show screen // show screen
if (currentScreen && !isSameScreen) { if (currentScreen && !isSameScreen) {
delegateRun(currentScreen, 'onShow'); currentScreen.onShow && currentScreen.onShow();
if (currentScreen.onShowTrigger) { if (currentScreen.onShowTrigger) {
currentScreen.onShowTrigger(!currentScreen.onShowTrigger()); currentScreen.onShowTrigger(!currentScreen.onShowTrigger());
} }
@ -362,17 +364,18 @@ export function screenOnRoute(screenName, subPart) {
ViewModelClass.__dom && ViewModelClass.__dom &&
ViewType.Popup !== ViewModelClass.__vm.viewModelPosition ViewType.Popup !== ViewModelClass.__vm.viewModelPosition
) { ) {
delegateRun(ViewModelClass.__vm, 'onBeforeShow'); ViewModelClass.__vm.onBeforeShow && ViewModelClass.__vm.onBeforeShow();
ViewModelClass.__dom.show(); ViewModelClass.__dom.show();
ViewModelClass.__vm.viewModelVisibility(true); ViewModelClass.__vm.viewModelVisibility(true);
delegateRun(ViewModelClass.__vm, 'onShow'); ViewModelClass.__vm.onShow && ViewModelClass.__vm.onShow();
if (ViewModelClass.__vm.onShowTrigger) { if (ViewModelClass.__vm.onShowTrigger) {
ViewModelClass.__vm.onShowTrigger(!ViewModelClass.__vm.onShowTrigger()); ViewModelClass.__vm.onShowTrigger(!ViewModelClass.__vm.onShowTrigger());
} }
delegateRun(ViewModelClass.__vm, 'onShowWithDelay', [], 200); ViewModelClass.__vm.onShowWithDelay && setTimeout(()=>ViewModelClass.__vm.onShowWithDelay, 200);
vmRunHook('view-model-on-show', ViewModelClass); vmRunHook('view-model-on-show', ViewModelClass);
} }
}); });
@ -415,7 +418,7 @@ export function startScreens(screensClasses) {
vmScreen.__start(); vmScreen.__start();
runHook('screen-pre-start', [vmScreen.screenName(), vmScreen]); runHook('screen-pre-start', [vmScreen.screenName(), vmScreen]);
delegateRun(vmScreen, 'onStart'); vmScreen.onStart && vmScreen.onStart();
runHook('screen-post-start', [vmScreen.screenName(), vmScreen]); runHook('screen-post-start', [vmScreen.screenName(), vmScreen]);
} }
}); });
@ -526,30 +529,23 @@ function commandDecorator(canExecute = true) {
* @returns {Function} * @returns {Function}
*/ */
function settingsMenuKeysHandler($items) { function settingsMenuKeysHandler($items) {
// throttle return ((event, handler)=>{
var t; const up = handler && 'up' === handler.shortcut;
return (event, handler)=>{
if (!t) {
t = setTimeout(()=>{
const up = handler && 'up' === handler.shortcut;
if (event && $items.length) { if (event && $items.length) {
let index = $items.index($items.filter('.selected')); let index = $items.index($items.filter('.selected'));
if (up && 0 < index) { if (up && 0 < index) {
index -= 1; index -= 1;
} else if (!up && index < $items.length - 1) { } else if (!up && index < $items.length - 1) {
index += 1; index += 1;
} }
const resultHash = $items.eq(index).attr('href'); const resultHash = $items.eq(index).attr('href');
if (resultHash) { if (resultHash) {
setHash(resultHash, false, true); setHash(resultHash, false, true);
} }
}
t = 0;
}, 200);
} }
}; }).throttle(200);
} }
export { export {

View file

@ -37,7 +37,7 @@ class AbstractAjaxPromises extends AbstractBasicPromises {
ajaxRequest(action, isPost, timeOut, params, additionalGetString, fTrigger) { ajaxRequest(action, isPost, timeOut, params, additionalGetString, fTrigger) {
additionalGetString = undefined === additionalGetString ? '' : pString(additionalGetString); additionalGetString = pString(additionalGetString);
let init = { let init = {
mode: 'same-origin', mode: 'same-origin',
@ -65,7 +65,7 @@ class AbstractAjaxPromises extends AbstractBasicPromises {
} }
}; };
buildFormData(formData, params); buildFormData(formData, params);
init.body = (new URLSearchParams(formData)).toString(); init.body = new URLSearchParams(formData);
} }
runHook('ajax-default-request', [action, params, additionalGetString]); runHook('ajax-default-request', [action, params, additionalGetString]);

View file

@ -163,7 +163,7 @@ class AbstractAjaxRemote {
} }
}; };
buildFormData(formData, params); buildFormData(formData, params);
init.body = (new URLSearchParams(formData)).toString(); init.body = new URLSearchParams(formData);
} }
if (window.AbortController) { if (window.AbortController) {

View file

@ -1,7 +1,7 @@
import ko from 'ko'; import ko from 'ko';
import { VIEW_MODELS } from 'Common/Globals'; import { VIEW_MODELS } from 'Common/Globals';
import { delegateRun, windowResize, pString } from 'Common/Utils'; import { windowResize, pString } from 'Common/Utils';
import { settings } from 'Common/Links'; import { settings } from 'Common/Links';
import { setHash } from 'Knoin/Knoin'; import { setHash } from 'Knoin/Knoin';
@ -94,7 +94,7 @@ class AbstractSettingsScreen extends AbstractScreen {
settingsScreen settingsScreen
); );
delegateRun(settingsScreen, 'onBuild', [viewModelDom]); settingsScreen.onBuild && settingsScreen.onBuild(viewModelDom);
} else { } else {
console.log('Cannot find sub settings view model position: SettingsSubScreen'); console.log('Cannot find sub settings view model position: SettingsSubScreen');
} }
@ -105,7 +105,7 @@ class AbstractSettingsScreen extends AbstractScreen {
setTimeout(() => { setTimeout(() => {
// hide // hide
if (o.oCurrentSubScreen) { if (o.oCurrentSubScreen) {
delegateRun(o.oCurrentSubScreen, 'onHide'); o.oCurrentSubScreen.onHide && o.oCurrentSubScreen.onHide();
o.oCurrentSubScreen.viewModelDom.hide(); o.oCurrentSubScreen.viewModelDom.hide();
} }
// -- // --
@ -114,10 +114,10 @@ class AbstractSettingsScreen extends AbstractScreen {
// show // show
if (o.oCurrentSubScreen) { if (o.oCurrentSubScreen) {
delegateRun(o.oCurrentSubScreen, 'onBeforeShow'); o.oCurrentSubScreen.onBeforeShow && o.oCurrentSubScreen.onBeforeShow();
o.oCurrentSubScreen.viewModelDom.show(); o.oCurrentSubScreen.viewModelDom.show();
delegateRun(o.oCurrentSubScreen, 'onShow'); o.oCurrentSubScreen.onShow && o.oCurrentSubScreen.onShow();
delegateRun(o.oCurrentSubScreen, 'onShowWithDelay', [], 200); o.oCurrentSubScreen.onShowWithDelay && setTimeout(() => o.oCurrentSubScreen.onShowWithDelay(), 200);
o.menu().forEach(item => { o.menu().forEach(item => {
item.selected( item.selected(
@ -141,7 +141,7 @@ class AbstractSettingsScreen extends AbstractScreen {
onHide() { onHide() {
if (this.oCurrentSubScreen && this.oCurrentSubScreen.viewModelDom) { if (this.oCurrentSubScreen && this.oCurrentSubScreen.viewModelDom) {
delegateRun(this.oCurrentSubScreen, 'onHide'); this.oCurrentSubScreen.onHide && this.oCurrentSubScreen.onHide();
this.oCurrentSubScreen.viewModelDom.hide(); this.oCurrentSubScreen.viewModelDom.hide();
} }
} }

View file

@ -4,7 +4,7 @@ import { MESSAGES_PER_PAGE_VALUES } from 'Common/Consts';
import { SaveSettingsStep, EditorDefaultType, Layout } from 'Common/Enums'; import { SaveSettingsStep, EditorDefaultType, Layout } from 'Common/Enums';
import { settingsSaveHelperSimpleFunction, convertLangName, timeOutAction } from 'Common/Utils'; import { settingsSaveHelperSimpleFunction, convertLangName } from 'Common/Utils';
import { i18n, trigger as translatorTrigger, reload as translatorReload } from 'Common/Translator'; import { i18n, trigger as translatorTrigger, reload as translatorReload } from 'Common/Translator';
@ -121,46 +121,28 @@ class GeneralUserSettings {
this.useCheckboxesInList.subscribe(Remote.saveSettingsHelper('UseCheckboxesInList', v=>v?'1':'0')); this.useCheckboxesInList.subscribe(Remote.saveSettingsHelper('UseCheckboxesInList', v=>v?'1':'0'));
this.enableDesktopNotification.subscribe((value) => { this.enableDesktopNotification.subscribe((value =>
timeOutAction( Remote.saveSettings(null, {
'SaveDesktopNotifications', 'DesktopNotifications': value ? 1 : 0
() => { })
Remote.saveSettings(null, { ).debounce(3000));
'DesktopNotifications': value ? '1' : '0'
});
},
3000
);
});
this.enableSoundNotification.subscribe((value) => { this.enableSoundNotification.subscribe((value =>
timeOutAction( Remote.saveSettings(null, {
'SaveSoundNotification', 'SoundNotification': value ? 1 : 0
() => { })
Remote.saveSettings(null, { ).debounce(3000));
'SoundNotification': value ? '1' : '0'
});
},
3000
);
});
this.replySameFolder.subscribe((value) => { this.replySameFolder.subscribe((value =>
timeOutAction( Remote.saveSettings(null, {
'SaveReplySameFolder', 'ReplySameFolder': value ? 1 : 0
() => { })
Remote.saveSettings(null, { ).debounce(3000));
'ReplySameFolder': value ? '1' : '0'
});
},
3000
);
});
this.useThreads.subscribe((value) => { this.useThreads.subscribe((value) => {
MessageStore.messageList([]); MessageStore.messageList([]);
Remote.saveSettings(null, { Remote.saveSettings(null, {
'UseThreads': value ? '1' : '0' 'UseThreads': value ? 1 : 0
}); });
}); });

View file

@ -9,7 +9,7 @@ APP_SETTINGS = null != APP_SETTINGS ? APP_SETTINGS : {};
* @returns {*} * @returns {*}
*/ */
export function settingsGet(name) { export function settingsGet(name) {
return undefined === SETTINGS[name] ? null : SETTINGS[name]; return null == SETTINGS[name] ? null : SETTINGS[name];
} }
/** /**
@ -25,7 +25,7 @@ export function settingsSet(name, value) {
* @returns {*} * @returns {*}
*/ */
export function appSettingsGet(name) { export function appSettingsGet(name) {
return undefined === APP_SETTINGS[name] ? null : APP_SETTINGS[name]; return null == APP_SETTINGS[name] ? null : APP_SETTINGS[name];
} }
/** /**

View file

@ -112,16 +112,7 @@ class MessageUserStore {
this.onMessageResponse = this.onMessageResponse.bind(this); this.onMessageResponse = this.onMessageResponse.bind(this);
// throttle this.purgeMessageBodyCacheThrottle = this.purgeMessageBodyCache.throttle(30000);
var t, o = this;
this.purgeMessageBodyCacheThrottle = ()=>{
if (!t) {
t = setTimeout(()=>{
o.purgeMessageBodyCache();
t = 0;
}, 30000);
}
};
} }
computers() { computers() {
@ -203,20 +194,15 @@ class MessageUserStore {
this.messageListCompleteLoadingThrottleForAnimation(value); this.messageListCompleteLoadingThrottleForAnimation(value);
}); });
var d;
this.messageList.subscribe( this.messageList.subscribe(
(list)=>{ (list=> {
// debounce list.forEach(item =>
clearTimeout(d); item && item.newForAnimation() && item.newForAnimation(false)
d = setTimeout(()=>list.forEach(item => { )
if (item && item.newForAnimation()) { }).debounce(500)
item.newForAnimation(false);
}
}), 500);
}
); );
this.message.subscribe((message) => { this.message.subscribe(message => {
if (message) { if (message) {
if (Layout.NoPreview === SettingsStore.layout()) { if (Layout.NoPreview === SettingsStore.layout()) {
AppStore.focusedState(Focused.MessageView); AppStore.focusedState(Focused.MessageView);
@ -229,9 +215,7 @@ class MessageUserStore {
} }
}); });
this.messageLoading.subscribe((value) => { this.messageLoading.subscribe(value => this.messageLoadingThrottle(value));
this.messageLoadingThrottle(value);
});
this.messagesBodiesDom.subscribe((dom) => { this.messagesBodiesDom.subscribe((dom) => {
if (dom && !(dom instanceof $)) { if (dom && !(dom instanceof $)) {
@ -239,7 +223,7 @@ class MessageUserStore {
} }
}); });
this.messageListEndFolder.subscribe((folder) => { this.messageListEndFolder.subscribe(folder => {
const message = this.message(); const message = this.message();
if (message && folder && folder !== message.folderFullNameRaw) { if (message && folder && folder !== message.folderFullNameRaw) {
this.message(null); this.message(null);
@ -745,7 +729,7 @@ class MessageUserStore {
iCount = pInt(data.Result.MessageResultCount), iCount = pInt(data.Result.MessageResultCount),
iOffset = pInt(data.Result.Offset); iOffset = pInt(data.Result.Offset);
const folder = getFolderFromCacheList(null != data.Result.Folder ? data.Result.Folder : ''); const folder = getFolderFromCacheList(data.Result.Folder);
if (folder && !cached) { if (folder && !cached) {
folder.interval = Date.now() / 1000; folder.interval = Date.now() / 1000;

View file

@ -1,5 +1,4 @@
import ko from 'ko'; import ko from 'ko';
import { delegateRun } from 'Common/Utils';
import PgpStore from 'Stores/User/Pgp'; import PgpStore from 'Stores/User/Pgp';
@ -83,7 +82,7 @@ class AddOpenPgpKeyPopupView extends AbstractViewNext {
return false; return false;
} }
delegateRun(this, 'cancelCommand'); this.cancelCommand && this.cancelCommand();
return true; return true;
} }

View file

@ -12,7 +12,6 @@ import {
} from 'Common/Enums'; } from 'Common/Enums';
import { import {
delegateRun,
isNonEmptyArray, isNonEmptyArray,
clearBqSwitcher, clearBqSwitcher,
replySubjectAdd, replySubjectAdd,
@ -85,7 +84,7 @@ class ComposePopupView extends AbstractViewNext {
this.sLastFocusedField = 'to'; this.sLastFocusedField = 'to';
this.resizerTrigger = this.resizerTrigger.bind(this); this.resizerTrigger = this.resizerTrigger.debounce(50).bind(this);
this.allowContacts = !!AppStore.contactsIsAllowed(); this.allowContacts = !!AppStore.contactsIsAllowed();
this.allowFolders = !!Settings.capa(Capa.Folders); this.allowFolders = !!Settings.capa(Capa.Folders);
@ -148,17 +147,9 @@ class ComposePopupView extends AbstractViewNext {
} }
}); });
this.savedError.subscribe((value) => { this.savedError.subscribe(value => !value && this.savedErrorDesc(''));
if (!value) {
this.savedErrorDesc('');
}
});
this.sendSuccessButSaveError.subscribe((value) => { this.sendSuccessButSaveError.subscribe(value => !value && this.savedErrorDesc(''));
if (!value) {
this.savedErrorDesc('');
}
});
this.savedTime = ko.observable(0); this.savedTime = ko.observable(0);
this.savedTimeText = ko.computed(() => this.savedTimeText = ko.computed(() =>
@ -297,9 +288,6 @@ class ComposePopupView extends AbstractViewNext {
this.canBeSentOrSaved = ko.computed(() => !this.sending() && !this.saving()); this.canBeSentOrSaved = ko.computed(() => !this.sending() && !this.saving());
this.sendMessageResponse = this.sendMessageResponse.bind(this);
this.saveMessageResponse = this.saveMessageResponse.bind(this);
setInterval(() => { setInterval(() => {
if ( if (
this.modalVisibility() && this.modalVisibility() &&
@ -318,20 +306,10 @@ class ComposePopupView extends AbstractViewNext {
this.showBcc.subscribe(this.resizerTrigger); this.showBcc.subscribe(this.resizerTrigger);
this.showReplyTo.subscribe(this.resizerTrigger); this.showReplyTo.subscribe(this.resizerTrigger);
this.onMessageUploadAttachments = this.onMessageUploadAttachments.bind(this);
this.bDisabeCloseOnEsc = true; this.bDisabeCloseOnEsc = true;
this.sDefaultKeyScope = KeyState.Compose; this.sDefaultKeyScope = KeyState.Compose;
// debounce this.tryToClosePopup = this.tryToClosePopup.debounce(200);
var d, fn = this.tryToClosePopup.bind(this);
this.tryToClosePopup = ()=>{
clearTimeout(d);
d = setTimeout(fn, 200);
};
this.emailsSource = this.emailsSource.bind(this);
this.autosaveFunction = this.autosaveFunction.bind(this);
this.iTimer = 0; this.iTimer = 0;
} }
@ -424,7 +402,7 @@ class ComposePopupView extends AbstractViewNext {
setFolderHash(sSentFolder, ''); setFolderHash(sSentFolder, '');
Remote.sendMessage( Remote.sendMessage(
this.sendMessageResponse, this.sendMessageResponse.bind(this),
this.getMessageRequestParams(sSentFolder) this.getMessageRequestParams(sSentFolder)
); );
} }
@ -448,7 +426,7 @@ class ComposePopupView extends AbstractViewNext {
setFolderHash(FolderStore.draftFolder(), ''); setFolderHash(FolderStore.draftFolder(), '');
Remote.saveMessage( Remote.saveMessage(
this.saveMessageResponse, this.saveMessageResponse.bind(this),
this.getMessageRequestParams(FolderStore.draftFolder()) this.getMessageRequestParams(FolderStore.draftFolder())
); );
} }
@ -517,7 +495,7 @@ class ComposePopupView extends AbstractViewNext {
autosaveStart() { autosaveStart() {
clearTimeout(this.iTimer); clearTimeout(this.iTimer);
this.iTimer = setTimeout(this.autosaveFunction, 60000); this.iTimer = setTimeout(()=>this.autosaveFunction(), 60000);
} }
autosaveStop() { autosaveStop() {
@ -525,9 +503,7 @@ class ComposePopupView extends AbstractViewNext {
} }
emailsSource(oData, fResponse) { emailsSource(oData, fResponse) {
getApp().getAutocomplete(oData.term, (aData) => { getApp().getAutocomplete(oData.term, aData => fResponse(aData.map(oEmailItem => oEmailItem.toLine(false))));
fResponse(aData.map(oEmailItem => oEmailItem.toLine(false)));
});
} }
openOpenPgpPopup() { openOpenPgpPopup() {
@ -615,9 +591,7 @@ class ComposePopupView extends AbstractViewNext {
if (StorageResultType.Success === statusResult && data && data.Result) { if (StorageResultType.Success === statusResult && data && data.Result) {
result = true; result = true;
if (this.modalVisibility()) { this.modalVisibility() && this.closeCommand && this.closeCommand();
delegateRun(this, 'closeCommand');
}
} }
if (this.modalVisibility() && !result) { if (this.modalVisibility() && !result) {
@ -1096,7 +1070,7 @@ class ComposePopupView extends AbstractViewNext {
const downloads = this.getAttachmentsDownloadsForUpload(); const downloads = this.getAttachmentsDownloadsForUpload();
if (isNonEmptyArray(downloads)) { if (isNonEmptyArray(downloads)) {
Remote.messageUploadAttachments(this.onMessageUploadAttachments, downloads); Remote.messageUploadAttachments(()=>this.onMessageUploadAttachments(), downloads);
} }
if (identity) { if (identity) {
@ -1147,13 +1121,13 @@ class ComposePopupView extends AbstractViewNext {
const PopupsAskViewModel = require('View/Popup/Ask'); const PopupsAskViewModel = require('View/Popup/Ask');
if (!isPopupVisible(PopupsAskViewModel) && this.modalVisibility()) { if (!isPopupVisible(PopupsAskViewModel) && this.modalVisibility()) {
if (this.bSkipNextHide || (this.isEmptyForm() && !this.draftUid())) { if (this.bSkipNextHide || (this.isEmptyForm() && !this.draftUid())) {
delegateRun(this, 'closeCommand'); this.closeCommand && this.closeCommand();
} else { } else {
showScreenPopup(PopupsAskViewModel, [ showScreenPopup(PopupsAskViewModel, [
i18n('POPUPS_ASK/DESC_WANT_CLOSE_THIS_WINDOW'), i18n('POPUPS_ASK/DESC_WANT_CLOSE_THIS_WINDOW'),
() => { () => {
if (this.modalVisibility()) { if (this.modalVisibility()) {
delegateRun(this, 'closeCommand'); this.closeCommand && this.closeCommand();
} }
} }
]); ]);
@ -1206,12 +1180,7 @@ class ComposePopupView extends AbstractViewNext {
return false; return false;
}); });
var d, o = this; addEventListener('resize.real', this.resizerTrigger);
addEventListener('resize.real', ()=>{
// debounce
clearTimeout(d);
d = setTimeout(o.resizerTrigger, 50);
});
setInterval(() => { setInterval(() => {
if (this.modalVisibility() && this.oEditor) { if (this.modalVisibility() && this.oEditor) {

View file

@ -2,7 +2,7 @@ import ko from 'ko';
import { FiltersAction, FilterConditionField, FilterConditionType } from 'Common/Enums'; import { FiltersAction, FilterConditionField, FilterConditionType } from 'Common/Enums';
import { bMobileDevice } from 'Common/Globals'; import { bMobileDevice } from 'Common/Globals';
import { defautOptionsAfterRender, delegateRun } from 'Common/Utils'; import { defautOptionsAfterRender } from 'Common/Utils';
import { i18n, initOnStartOrLangChange } from 'Common/Translator'; import { i18n, initOnStartOrLangChange } from 'Common/Translator';
import FilterStore from 'Stores/User/Filter'; import FilterStore from 'Stores/User/Filter';
@ -59,13 +59,9 @@ class FilterPopupView extends AbstractViewNext {
return false; return false;
} }
if (this.fTrueCallback) { this.fTrueCallback && this.fTrueCallback(this.filter());
this.fTrueCallback(this.filter());
}
if (this.modalVisibility()) { this.modalVisibility() && this.closeCommand && this.closeCommand();
delegateRun(this, 'closeCommand');
}
} }
return true; return true;

View file

@ -55,7 +55,6 @@ class FolderSystemPopupView extends AbstractViewNext {
this.trashFolder = FolderStore.trashFolder; this.trashFolder = FolderStore.trashFolder;
this.archiveFolder = FolderStore.archiveFolder; this.archiveFolder = FolderStore.archiveFolder;
var d;
const fSetSystemFolders = () => { const fSetSystemFolders = () => {
Settings.settingsSet('SentFolder', FolderStore.sentFolder()); Settings.settingsSet('SentFolder', FolderStore.sentFolder());
Settings.settingsSet('DraftFolder', FolderStore.draftFolder()); Settings.settingsSet('DraftFolder', FolderStore.draftFolder());
@ -63,21 +62,17 @@ class FolderSystemPopupView extends AbstractViewNext {
Settings.settingsSet('TrashFolder', FolderStore.trashFolder()); Settings.settingsSet('TrashFolder', FolderStore.trashFolder());
Settings.settingsSet('ArchiveFolder', FolderStore.archiveFolder()); Settings.settingsSet('ArchiveFolder', FolderStore.archiveFolder());
}, },
fSaveSystemFolders = ()=>{ fSaveSystemFolders = (()=>{
// debounce fSetSystemFolders();
clearTimeout(d); Remote.saveSystemFolders(()=>{}, {
d = setTimeout(()=>{ SentFolder: FolderStore.sentFolder(),
fSetSystemFolders(); DraftFolder: FolderStore.draftFolder(),
Remote.saveSystemFolders(()=>{}, { SpamFolder: FolderStore.spamFolder(),
SentFolder: FolderStore.sentFolder(), TrashFolder: FolderStore.trashFolder(),
DraftFolder: FolderStore.draftFolder(), ArchiveFolder: FolderStore.archiveFolder(),
SpamFolder: FolderStore.spamFolder(), NullFolder: 'NullFolder'
TrashFolder: FolderStore.trashFolder(), });
ArchiveFolder: FolderStore.archiveFolder(), }).debounce(1000),
NullFolder: 'NullFolder'
});
}, 1000);
},
fCallback = () => { fCallback = () => {
fSetSystemFolders(); fSetSystemFolders();
fSaveSystemFolders(); fSaveSystemFolders();

View file

@ -14,39 +14,29 @@ class KeyboardShortcutsHelpPopupView extends AbstractViewNext {
} }
onBuild(dom) { onBuild(dom) {
var t;
key( key(
'tab, shift+tab, left, right', 'tab, shift+tab, left, right',
KeyState.PopupKeyboardShortcutsHelp, KeyState.PopupKeyboardShortcutsHelp,
(event, handler)=>{ ((event, handler)=>{
// throttle if (event && handler) {
if (!t) { const $tabs = dom.find('.nav.nav-tabs > li'),
t = setTimeout(()=>{ isNext = handler && ('tab' === handler.shortcut || 'right' === handler.shortcut);
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')); let index = $tabs.index($tabs.filter('.active'));
if (!isNext && 0 < index) { if (!isNext && 0 < index) {
index -= 1; index -= 1;
} else if (isNext && index < $tabs.length - 1) { } else if (isNext && index < $tabs.length - 1) {
index += 1; index += 1;
} else { } else {
index = isNext ? 0 : $tabs.length - 1; index = isNext ? 0 : $tabs.length - 1;
} }
$tabs $tabs
.eq(index) .eq(index)
.find('a[data-toggle="tab"]') .find('a[data-toggle="tab"]')
.tab('show'); .tab('show');
return false;
}
return true;
}, 100);
} }
} }).throttle(100)
); );
} }
} }

View file

@ -1,6 +1,6 @@
import ko from 'ko'; import ko from 'ko';
import { delegateRun, pInt } from 'Common/Utils'; import { pInt } from 'Common/Utils';
import PgpStore from 'Stores/User/Pgp'; import PgpStore from 'Stores/User/Pgp';
@ -69,7 +69,7 @@ class NewOpenPgpKeyPopupView extends AbstractViewNext {
openpgpKeyring.store(); openpgpKeyring.store();
getApp().reloadOpenPgpKeys(); getApp().reloadOpenPgpKeys();
delegateRun(this, 'cancelCommand'); this.cancelCommand && this.cancelCommand();
} }
}) })
.catch((e) => { .catch((e) => {

View file

@ -1,7 +1,6 @@
import ko from 'ko'; import ko from 'ko';
import { KeyState, StorageResultType, Notification } from 'Common/Enums'; import { KeyState, StorageResultType, Notification } from 'Common/Enums';
import { isNonEmptyArray, delegateRun } from 'Common/Utils';
import { getNotification, i18n } from 'Common/Translator'; import { getNotification, i18n } from 'Common/Translator';
import Remote from 'Remote/Admin/Ajax'; import Remote from 'Remote/Admin/Ajax';
@ -41,12 +40,7 @@ class PluginPopupView extends AbstractViewNext {
this.bDisabeCloseOnEsc = true; this.bDisabeCloseOnEsc = true;
this.sDefaultKeyScope = KeyState.All; this.sDefaultKeyScope = KeyState.All;
var d, fn = this.tryToClosePopup.bind(this); this.tryToClosePopup = this.tryToClosePopup.debounce(200);
this.tryToClosePopup = ()=>{
// debounce
clearTimeout(d);
d = setTimeout(fn, 200);
};
} }
@command((self) => self.hasConfiguration()) @command((self) => self.hasConfiguration())
@ -89,7 +83,7 @@ class PluginPopupView extends AbstractViewNext {
this.readme(oPlugin.Readme); this.readme(oPlugin.Readme);
const config = oPlugin.Config; const config = oPlugin.Config;
if (isNonEmptyArray(config)) { if (Array.isArray(config) && config.length) {
this.configures( this.configures(
config.map(item => ({ config.map(item => ({
'value': ko.observable(item[0]), 'value': ko.observable(item[0]),
@ -110,11 +104,7 @@ class PluginPopupView extends AbstractViewNext {
if (!isPopupVisible(PopupsAskViewModel)) { if (!isPopupVisible(PopupsAskViewModel)) {
showScreenPopup(PopupsAskViewModel, [ showScreenPopup(PopupsAskViewModel, [
i18n('POPUPS_ASK/DESC_WANT_CLOSE_THIS_WINDOW'), i18n('POPUPS_ASK/DESC_WANT_CLOSE_THIS_WINDOW'),
() => { () => this.modalVisibility() && this.cancelCommand && this.cancelCommand()
if (this.modalVisibility()) {
delegateRun(this, 'cancelCommand');
}
}
]); ]);
} }
} }

View file

@ -539,20 +539,13 @@ class MessageViewMailBoxUserView extends AbstractViewNext {
this.showFullInfo.subscribe(fCheckHeaderHeight); this.showFullInfo.subscribe(fCheckHeaderHeight);
this.message.subscribe(fCheckHeaderHeight); this.message.subscribe(fCheckHeaderHeight);
var t;
addEventListener( addEventListener(
'resize', 'resize',
()=>{ (()=>{
// throttle setTimeout(fCheckHeaderHeight, 1);
if (!t) { setTimeout(fCheckHeaderHeight, 200);
t = setTimeout(()=>{ setTimeout(fCheckHeaderHeight, 500);
setTimeout(fCheckHeaderHeight, 1); }).throttle(50)
setTimeout(fCheckHeaderHeight, 200);
setTimeout(fCheckHeaderHeight, 500);
t = 0;
}, 50);
}
}
); );
this.showFullInfo.subscribe((value) => { this.showFullInfo.subscribe((value) => {

34
dev/prototype-function.js vendored Normal file
View file

@ -0,0 +1,34 @@
/**
* Every time the function is executed,
* it will delay the execution with the given amount of milliseconds.
*/
if (!Function.prototype.debounce) {
Function.prototype.debounce = function(ms) {
let func = this, timer;
return function(...args) {
timer && clearTimeout(timer);
timer = setTimeout(()=>{
func.apply(this, args)
timer = 0;
}, ms);
};
};
}
/**
* No matter how many times the event is executed,
* the function will be executed only once, after the given amount of milliseconds.
*/
if (!Function.prototype.throttle) {
Function.prototype.throttle = function(ms) {
let func = this, timer;
return function(...args) {
if (!timer) {
timer = setTimeout(()=>{
func.apply(this, args)
timer = 0;
}, ms);
}
};
};
}

View file

@ -81,6 +81,7 @@ config.paths.js = {
'vendors/qr.js/qr.min.js', // fixed (license) 'vendors/qr.js/qr.min.js', // fixed (license)
'vendors/bootstrap/js/bootstrap.min.js', // fixed 'vendors/bootstrap/js/bootstrap.min.js', // fixed
'dev/prototype-date.js', 'dev/prototype-date.js',
'dev/prototype-function.js',
'node_modules/knockout/build/output/knockout-latest.js', 'node_modules/knockout/build/output/knockout-latest.js',
'node_modules/knockout-sortable/build/knockout-sortable.min.js ', 'node_modules/knockout-sortable/build/knockout-sortable.min.js ',
'node_modules/simplestatemanager/dist/ssm.min.js', 'node_modules/simplestatemanager/dist/ssm.min.js',