diff --git a/css/style.css b/css/style.css index c7a4b23..d70071e 100644 --- a/css/style.css +++ b/css/style.css @@ -200,7 +200,7 @@ body > hr { grid-template-rows: 1fr; } -#search-section:has( ~ #result-panel.empty) { +#search-section:has( ~ dialog:not([open])) { position: fixed; bottom: 5px; left: 5px; @@ -240,6 +240,38 @@ body > hr { /* PANEL */ +#result-panel-dialog { + display: block; + position: relative; + padding: 0; + margin: 0; + border: none; + width: 100%; +} + +#result-panel-dialog:not([open]) { + display: none; +} + +#result-panel-dialog #close-result-panel-btn { + position: sticky; + top: 0px; + right: 0px; + padding: 15px; + border: none; + background: none; + cursor: pointer; + z-index: 100; + margin-left: auto; + margin-bottom: calc( ( 1.5em + 30px ) * -1); + display: block; +} + +#close-result-panel-btn img { + height: 1.5em; + display: block; +} + #result-panel { background: black; border-image: url("../assets/neon-border-image.svg") 12; @@ -248,11 +280,6 @@ body > hr { color: white; } -#result-panel.empty, -#result-panel:empty{ - display:none; -} - #result-panel > * { padding: 1em; margin: 0; diff --git a/icons/close.svg b/icons/close.svg new file mode 100644 index 0000000..fd47460 --- /dev/null +++ b/icons/close.svg @@ -0,0 +1,53 @@ + + + + diff --git a/index.html b/index.html index 6c88e83..3ec06cf 100644 --- a/index.html +++ b/index.html @@ -26,6 +26,11 @@ - + + + + diff --git a/js/index.js b/js/index.js index 0d43fea..5eea888 100644 --- a/js/index.js +++ b/js/index.js @@ -25,6 +25,13 @@ const search_form = document.getElementById("search-section") search_form.elements["query"].addEventListener("change", () => search_form.requestSubmit()) search_form.elements["query"].addEventListener("input", () => search_form.requestSubmit()) +function showDefaultMapState(){ + MAP.unhighlight_all() + for(let feature of places.featuresShownOnEmptyMap){ + MAP.show(feature) + } +} + window.addEventListener("hashchange", () => { let place_id = decodeURIComponent(location.hash.substring(1)) if (place_id) { @@ -72,10 +79,8 @@ window.addEventListener("hashchange", () => { } } } else { - MAP.unhighlight_all() - for(let feature of places.featuresShownOnEmptyMap){ - MAP.show(feature) - } + document.getElementById("result-panel").replaceChildren(null) + showDefaultMapState() } }) window.dispatchEvent(new Event("hashchange")) @@ -119,6 +124,7 @@ search_form.addEventListener("submit", e => { } else { document.getElementById("search-result")?.remove() + showDefaultMapState() } } @@ -193,3 +199,37 @@ document.getElementById("result-panel").addEventListener("activePanelChange", e } } }) + +{ + const RESULT_PANEL = document.getElementById("result-panel") + /** @type {HTMLDialogElement} */ + const RESULT_DIALOG = document.getElementById("result-panel-dialog") + + function udpateDialogState(){ + if(RESULT_PANEL.children.length > 0) { + // BUG d'accessibilitĂ©: Il ne faut pas modifier le focus lors de l'ouverture d'une modale + // Il est preferable de ne pas ouvrir la modale avant d'ĂȘtre sur que l'utilisateur·ice veux vraiment y aller + let active_element = document.activeElement; + RESULT_DIALOG.show() + if(active_element){ + active_element.focus() + } + } else { + RESULT_DIALOG.close() + } + } + + // Oberve changes in modal DOM + new MutationObserver(udpateDialogState).observe(RESULT_PANEL, { + childList: true + }) + + // Empty result panel on close + document.getElementById("close-result-panel-btn").addEventListener("click", e => { + updateActiveFeature(null) + document.getElementById("result-panel").replaceChildren() + }) + + //Init + udpateDialogState() +} \ No newline at end of file