authorgravatar for r00ster91@proton.meWooster <r00ster91@proton.me> 2022-08-14 11:49:44+02:00
committergravatar for r00ster91@proton.meWooster <r00ster91@proton.me> 2022-08-14 11:54:51+02:00
log8f6f4bc7caf09a4399a5f2b1fdf5c966b89bab15
treec277456c6cb293958d39ce06b860178c5c3ee156
parent9900413eb12a3eea74fff74025ae8c33d9425439

feat: make modal more restrictive and more Esc freedom

This makes it so that you can no longer interact with the search bar or the results or anything while the modal is open. That's why it's a "modal" and not a "dialog". It also makes it so that you can now always press Esc to return to the results or the main page. Previously this was only possible when the search field was active.

1 files changed, 27 insertions(+), 16 deletions(-)

lib/docs/main.js+27-16
......@@ -3148,6 +3148,22 @@ var zigAnalysis;
31483148 domSearch.blur();
31493149 }
31503150
3151 function onEscape(ev) {
3152 if (!domHelpModal.classList.contains("hidden")) {
3153 domHelpModal.classList.add("hidden");
3154 ev.preventDefault();
3155 ev.stopPropagation();
3156 } else {
3157 domSearch.value = "";
3158 domSearch.blur();
3159 domSearchPlaceholder.classList.remove("hidden");
3160 curSearchIndex = -1;
3161 ev.preventDefault();
3162 ev.stopPropagation();
3163 startSearch();
3164 }
3165 }
3166
31513167 function onSearchKeyDown(ev) {
31523168 switch (getKeyString(ev)) {
31533169 case "Enter":
......@@ -3164,13 +3180,8 @@ var zigAnalysis;
31643180 ev.stopPropagation();
31653181 return;
31663182 case "Esc":
3167 domSearch.value = "";
3168 domSearch.blur();
3169 curSearchIndex = -1;
3170 ev.preventDefault();
3171 ev.stopPropagation();
3172 startSearch();
3173 return;
3183 onEscape(ev);
3184 return
31743185 case "Up":
31753186 moveSearchCursor(-1);
31763187 ev.preventDefault();
......@@ -3245,19 +3256,18 @@ var zigAnalysis;
32453256 function onWindowKeyDown(ev) {
32463257 switch (getKeyString(ev)) {
32473258 case "Esc":
3248 if (!domHelpModal.classList.contains("hidden")) {
3249 domHelpModal.classList.add("hidden");
3259 onEscape(ev);
3260 break;
3261 case "s":
3262 if (domHelpModal.classList.contains("hidden")) {
3263 // TODO: scroll the page to the very top
3264 domSearch.focus();
3265 domSearch.select();
32503266 ev.preventDefault();
32513267 ev.stopPropagation();
3268 startAsyncSearch();
32523269 }
32533270 break;
3254 case "s":
3255 domSearch.focus();
3256 domSearch.select();
3257 ev.preventDefault();
3258 ev.stopPropagation();
3259 startAsyncSearch();
3260 break;
32613271 case "?":
32623272 ev.preventDefault();
32633273 ev.stopPropagation();
......@@ -3273,6 +3283,7 @@ var zigAnalysis;
32733283 domHelpModal.style.top =
32743284 window.innerHeight / 2 - domHelpModal.clientHeight / 2 + "px";
32753285 domHelpModal.focus();
3286 domSearch.blur();
32763287 }
32773288
32783289 function clearAsyncSearch() {