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;...@@ -3148,6 +3148,22 @@ var zigAnalysis;
3148 domSearch.blur();3148 domSearch.blur();
3149 }3149 }
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
3151 function onSearchKeyDown(ev) {3167 function onSearchKeyDown(ev) {
3152 switch (getKeyString(ev)) {3168 switch (getKeyString(ev)) {
3153 case "Enter":3169 case "Enter":
...@@ -3164,13 +3180,8 @@ var zigAnalysis;...@@ -3164,13 +3180,8 @@ var zigAnalysis;
3164 ev.stopPropagation();3180 ev.stopPropagation();
3165 return;3181 return;
3166 case "Esc":3182 case "Esc":
3167 domSearch.value = "";3183 onEscape(ev);
3168 domSearch.blur();3184 return
3169 curSearchIndex = -1;
3170 ev.preventDefault();
3171 ev.stopPropagation();
3172 startSearch();
3173 return;
3174 case "Up":3185 case "Up":
3175 moveSearchCursor(-1);3186 moveSearchCursor(-1);
3176 ev.preventDefault();3187 ev.preventDefault();
...@@ -3245,19 +3256,18 @@ var zigAnalysis;...@@ -3245,19 +3256,18 @@ var zigAnalysis;
3245 function onWindowKeyDown(ev) {3256 function onWindowKeyDown(ev) {
3246 switch (getKeyString(ev)) {3257 switch (getKeyString(ev)) {
3247 case "Esc":3258 case "Esc":
3248 if (!domHelpModal.classList.contains("hidden")) {3259 onEscape(ev);
3249 domHelpModal.classList.add("hidden");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();
3250 ev.preventDefault();3266 ev.preventDefault();
3251 ev.stopPropagation();3267 ev.stopPropagation();
3268 startAsyncSearch();
3252 }3269 }
3253 break;3270 break;
3254 case "s":
3255 domSearch.focus();
3256 domSearch.select();
3257 ev.preventDefault();
3258 ev.stopPropagation();
3259 startAsyncSearch();
3260 break;
3261 case "?":3271 case "?":
3262 ev.preventDefault();3272 ev.preventDefault();
3263 ev.stopPropagation();3273 ev.stopPropagation();
...@@ -3273,6 +3283,7 @@ var zigAnalysis;...@@ -3273,6 +3283,7 @@ var zigAnalysis;
3273 domHelpModal.style.top =3283 domHelpModal.style.top =
3274 window.innerHeight / 2 - domHelpModal.clientHeight / 2 + "px";3284 window.innerHeight / 2 - domHelpModal.clientHeight / 2 + "px";
3275 domHelpModal.focus();3285 domHelpModal.focus();
3286 domSearch.blur();
3276 }3287 }
32773288
3278 function clearAsyncSearch() {3289 function clearAsyncSearch() {