Drop cancelCommand in favor of closeCommand and improve AbstractViewPopup handling

This commit is contained in:
the-djmaze 2022-02-24 22:40:17 +01:00
parent 06b5b83588
commit 2edd55f01f
36 changed files with 82 additions and 118 deletions

View file

@ -57,36 +57,30 @@ export class AbstractViewPopup extends AbstractView
constructor(name)
{
super('Popups' + name, ViewType.Popup);
if (name in Scope) {
this.keyScope.scope = Scope[name];
}
this.bDisabeCloseOnEsc = false;
this.keyScope.scope = name;
this.modalVisibility = ko.observable(false).extend({ rateLimit: 0 });
}
/*
onShowWithDelay() {}
onHideWithDelay() {}
cancelCommand() {}
closeCommand() {}
*/
/**
* @returns {void}
*/
registerPopupKeyDown() {
addEventListener('keydown', event => {
if (event && this.modalVisibility()) {
if (!this.bDisabeCloseOnEsc && 'Escape' == event.key) {
this.cancelCommand();
return false;
} else if ('Backspace' == event.key && !inFocus()) {
return false;
}
this.onClose = this.onClose.debounce(200);
shortcuts.add('escape,close', '', name, () => {
if (this.modalVisibility() && this.onClose()) {
this.closeCommand();
return false;
}
return true;
});
shortcuts.add('backspace', '', name, inFocus());
}
onClose() {
return true;
}
/*
afterShow() {}
afterHide() {}
closeCommand() {}
*/
}
AbstractViewPopup.showModal = function(params = []) {

View file

@ -48,7 +48,7 @@ const
ViewModelClass.__dom = vmDom;
if (ViewType.Popup === position) {
vm.cancelCommand = vm.closeCommand = createCommand(() => hideScreenPopup(ViewModelClass));
vm.closeCommand = createCommand(() => hideScreenPopup(ViewModelClass));
// Firefox / Safari HTMLDialogElement not defined
if (!vmDom.showModal) {
@ -75,10 +75,10 @@ const
if (e.target === vmDom) {
if (vmDom.classList.contains('animate')) {
autofocus(vmDom);
vm.onShowWithDelay && vm.onShowWithDelay();
vm.afterShow && vm.afterShow();
} else {
vmDom.close();
vm.onHideWithDelay && vm.onHideWithDelay();
vm.afterHide && vm.afterHide();
}
}
};
@ -115,12 +115,7 @@ const
}
*/
});
if ('ontransitionend' in vmDom) {
vmDom.addEventListener('transitionend', endShowHide);
} else {
// For Edge < 79 and mobile browsers
vm.modalVisibility.subscribe(() => ()=>setTimeout(endShowHide({target:vmDom}), 500));
}
vmDom.addEventListener('transitionend', endShowHide);
}
ko.applyBindingAccessorsToNode(
@ -133,9 +128,6 @@ const
);
vm.onBuild && vm.onBuild(vmDom);
if (vm && ViewType.Popup === position) {
vm.registerPopupKeyDown();
}
fireEvent('rl-view-model', vm);
} else {