mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-10-18 12:41:54 +08:00
refactor(client): fix global event handling for modal
This commit is contained in:
parent
8f6376e537
commit
e2cd875c03
@ -131,7 +131,7 @@ export default class RevisionsDialog extends BasicWidget {
|
|||||||
this.$list = this.$widget.find(".revision-list");
|
this.$list = this.$widget.find(".revision-list");
|
||||||
this.$listDropdown = this.$widget.find(".revision-list-dropdown");
|
this.$listDropdown = this.$widget.find(".revision-list-dropdown");
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
this.listDropdown = bootstrap.Dropdown.getOrCreateInstance(this.$listDropdown);
|
this.listDropdown = bootstrap.Dropdown.getOrCreateInstance(this.$listDropdown, { autoClose: false });
|
||||||
this.$content = this.$widget.find(".revision-content");
|
this.$content = this.$widget.find(".revision-content");
|
||||||
this.$title = this.$widget.find(".revision-title");
|
this.$title = this.$widget.find(".revision-title");
|
||||||
this.$titleButtons = this.$widget.find(".revision-title-buttons");
|
this.$titleButtons = this.$widget.find(".revision-title-buttons");
|
||||||
@ -142,23 +142,9 @@ export default class RevisionsDialog extends BasicWidget {
|
|||||||
this.listDropdown.show();
|
this.listDropdown.show();
|
||||||
|
|
||||||
this.$listDropdown.parent().on("hide.bs.dropdown", (e) => {
|
this.$listDropdown.parent().on("hide.bs.dropdown", (e) => {
|
||||||
// Prevent closing dropdown by pressing ESC and clicking outside
|
this.modal.hide();
|
||||||
e.preventDefault();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
document.addEventListener(
|
|
||||||
"keydown",
|
|
||||||
(e) => {
|
|
||||||
// Close the revision dialog when revision element is focused and ESC is pressed
|
|
||||||
// TODO: Is this corret?
|
|
||||||
// @ts-ignore
|
|
||||||
if (e.key === "Escape" || ((e.target as HTMLElement)?.classList?.contains(["dropdown-item", "active"]))) {
|
|
||||||
this.modal.hide();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
this.$widget.on("shown.bs.modal", () => {
|
this.$widget.on("shown.bs.modal", () => {
|
||||||
this.$list.find(`[data-revision-id="${this.revisionId}"]`).trigger("focus");
|
this.$list.find(`[data-revision-id="${this.revisionId}"]`).trigger("focus");
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user