Escape stops cancelling its own exit
Browse files at this commitd28fea9fc08bb61e8e989761cad94ebde0b354ddParent: 6f21f90- fix
- escape stops cancelling its own exit
2 changed files +12 -4
crates/izlek-web/src/detail.rsmodified+11 -4
| @@ -685,7 +685,12 @@ async fn avatar(cx: &Cx, person: &Person, extra: &str) -> Result { | |||
| 685 | /// `__izlekLeaving` is one navigation per document, `pageshow` releases it. | 685 | /// `__izlekLeaving` is one navigation per document, `pageshow` releases it. |
| 686 | /// Focused native media controls swallow `Escape` before the page ever | 686 | /// Focused native media controls swallow `Escape` before the page ever |
| 687 | /// sees the key, so focus landing on the viewer's audio/video is moved | 687 | /// sees the key, so focus landing on the viewer's audio/video is moved |
| 688 | -/// straight back to the panel. | 688 | +/// straight back to the panel. Every branch that navigates must |
| 689 | +/// `preventDefault()` first: a real Escape's browser default is | ||
| 690 | +/// stop-loading, which cancels the navigation the handler just started | ||
| 691 | +/// (and would leave `__izlekLeaving` latched true, deadening every | ||
| 692 | +/// later press). Synthetic keys carry no default, so only a live | ||
| 693 | +/// keyboard ever showed it. | ||
| 689 | async fn escape_closes(cx: &Cx) -> Result { | 694 | async fn escape_closes(cx: &Cx) -> Result { |
| 690 | use topcoat::view::Unescaped; | 695 | use topcoat::view::Unescaped; |
| 691 | const JS: &str = "\ | 696 | const JS: &str = "\ |
| @@ -694,12 +699,14 @@ async fn escape_closes(cx: &Cx) -> Result { | |||
| 694 | if (document.querySelector('.datepick-pop .edit-toggle:checked')) { return; } \ | 699 | if (document.querySelector('.datepick-pop .edit-toggle:checked')) { return; } \ |
| 695 | var viewer = document.querySelector('.viewer-scrim'); \ | 700 | var viewer = document.querySelector('.viewer-scrim'); \ |
| 696 | if (viewer) { \ | 701 | if (viewer) { \ |
| 702 | + e.preventDefault(); \ | ||
| 697 | if (!window.__izlekLeaving) { window.__izlekLeaving = true; window.location.href = viewer.querySelector('.viewer-close').getAttribute('href'); } \ | 703 | if (!window.__izlekLeaving) { window.__izlekLeaving = true; window.location.href = viewer.querySelector('.viewer-close').getAttribute('href'); } \ |
| 698 | e.stopImmediatePropagation(); \ | 704 | e.stopImmediatePropagation(); \ |
| 699 | return; \ | 705 | return; \ |
| 700 | } \ | 706 | } \ |
| 701 | var confirm = document.querySelector('details.confirm-details[open]'); \ | 707 | var confirm = document.querySelector('details.confirm-details[open]'); \ |
| 702 | if (confirm && window.location.search.indexOf('confirm=delete') !== -1) { \ | 708 | if (confirm && window.location.search.indexOf('confirm=delete') !== -1) { \ |
| 709 | + e.preventDefault(); \ | ||
| 703 | if (!window.__izlekLeaving) { window.__izlekLeaving = true; window.location.href = '/'; } \ | 710 | if (!window.__izlekLeaving) { window.__izlekLeaving = true; window.location.href = '/'; } \ |
| 704 | e.stopImmediatePropagation(); \ | 711 | e.stopImmediatePropagation(); \ |
| 705 | return; \ | 712 | return; \ |
| @@ -715,9 +722,9 @@ async fn escape_closes(cx: &Cx) -> Result { | |||
| 715 | e.stopImmediatePropagation(); \ | 722 | e.stopImmediatePropagation(); \ |
| 716 | return; \ | 723 | return; \ |
| 717 | } \ | 724 | } \ |
| 718 | - if (document.querySelector('.modal-scrim') && !window.__izlekLeaving) { \ | 725 | + if (document.querySelector('.modal-scrim')) { \ |
| 719 | - window.__izlekLeaving = true; \ | 726 | + e.preventDefault(); \ |
| 720 | - window.location.href = '/'; \ | 727 | + if (!window.__izlekLeaving) { window.__izlekLeaving = true; window.location.href = '/'; } \ |
| 721 | e.stopImmediatePropagation(); \ | 728 | e.stopImmediatePropagation(); \ |
| 722 | } \ | 729 | } \ |
| 723 | }, true); \ | 730 | }, true); \ |
crates/izlek-web/src/layout.rsmodified+1 -0
| @@ -69,6 +69,7 @@ pub async fn escape_script(cx: &Cx) -> Result { | |||
| 69 | var composer = document.querySelector('details.rule-new[open]'); \ | 69 | var composer = document.querySelector('details.rule-new[open]'); \ |
| 70 | if (composer) { composer.removeAttribute('open'); e.stopImmediatePropagation(); return; } \ | 70 | if (composer) { composer.removeAttribute('open'); e.stopImmediatePropagation(); return; } \ |
| 71 | if (document.querySelector('.rule-new-body[action=\"/api/update_rule\"]')) { \ | 71 | if (document.querySelector('.rule-new-body[action=\"/api/update_rule\"]')) { \ |
| 72 | + e.preventDefault(); \ | ||
| 72 | window.location.href = '/rules'; \ | 73 | window.location.href = '/rules'; \ |
| 73 | e.stopImmediatePropagation(); \ | 74 | e.stopImmediatePropagation(); \ |
| 74 | } \ | 75 | } \ |