snappymail/dev/Knoin/AbstractViewNext.js

60 lines
1.2 KiB
JavaScript
Raw Normal View History

import ko from 'ko';
import { inFocus } from 'Common/Utils';
import { KeyState } from 'Common/Enums';
import { keyScope } from 'Common/Globals';
2019-07-05 03:19:24 +08:00
export class AbstractViewNext {
2016-09-10 06:38:16 +08:00
bDisabeCloseOnEsc = false;
sDefaultKeyScope = KeyState.None;
sCurrentKeyScope = KeyState.None;
2020-10-02 18:40:33 +08:00
viewModelVisible = false;
2019-07-05 03:19:24 +08:00
modalVisibility = ko.observable(false).extend({ rateLimit: 0 });
2016-09-10 06:38:16 +08:00
viewModelName = '';
viewModelNames = [];
viewModelDom = null;
/**
* @returns {void}
*/
storeAndSetKeyScope() {
this.sCurrentKeyScope = keyScope();
keyScope(this.sDefaultKeyScope);
}
/**
* @returns {void}
*/
restoreKeyScope() {
keyScope(this.sCurrentKeyScope);
}
/**
* @returns {void}
*/
registerPopupKeyDown() {
addEventListener('keydown', event => {
2019-07-05 03:19:24 +08:00
if (event && this.modalVisibility && this.modalVisibility()) {
if (!this.bDisabeCloseOnEsc && 'Escape' == event.key) {
this.cancelCommand && this.cancelCommand();
return false;
} else if ('Backspace' == event.key && !inFocus()) {
return false;
}
}
return true;
});
}
cancelCommand() {} // eslint-disable-line no-empty-function
closeCommand() {} // eslint-disable-line no-empty-function
querySelector(selectors) {
2020-08-27 21:45:47 +08:00
return this.viewModelDom.querySelector(selectors);
}
}