diff --git a/assets/js/darkmode.js b/assets/js/darkmode.js index dd460432..d5411721 100644 --- a/assets/js/darkmode.js +++ b/assets/js/darkmode.js @@ -49,7 +49,7 @@ } function updateToggleButtons(theme) { - const toggleButtons = document.querySelectorAll(".a-theme-toggle"); + const toggleButtons = document.querySelectorAll(".o-header__theme-toggle"); toggleButtons.forEach((button) => { let icon; @@ -78,7 +78,7 @@ const savedTheme = getSavedTheme(); updateToggleButtons(savedTheme); - const toggleButtons = document.querySelectorAll(".a-theme-toggle"); + const toggleButtons = document.querySelectorAll(".o-header__theme-toggle"); toggleButtons.forEach((button) => { button.addEventListener("click", toggleTheme); }); diff --git a/assets/js/main.js b/assets/js/main.js index fba26f98..b2b525c6 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -6,4 +6,5 @@ import "./contentNavigation.js"; import "./anchorlinks.js"; import "./dropdown.js"; import "./darkmode.js"; +import "./search.js"; import "./interactiveMap.js"; diff --git a/assets/js/search.js b/assets/js/search.js new file mode 100644 index 00000000..00387e3f --- /dev/null +++ b/assets/js/search.js @@ -0,0 +1,94 @@ +const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent); +const isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0; + +const initSearch = () => { + const search = document.getElementById("search"); + const searchButtons = document.querySelectorAll(".o-header__search"); + const isHome = document.querySelector(".o-startpage"); + const overlay = document.getElementById("overlay"); + let placeholderText = search.dataset.placeholder; + let searchLabelText = search.dataset.label; + + if (!isMobile) { + if (isMac) { + placeholderText += " (⌘ + K)"; + } else { + placeholderText += " (CTRL + K)"; + } + } + + new PagefindUI({ + element: "#search", + highlightParam: "highlight", + showSubResults: true, + translations: { + placeholder: placeholderText, + search_label: searchLabelText, + }, + }); + + const searchElement = search.querySelector("input"); + + const closeSearch = () => { + search.querySelector(".pagefind-ui__search-clear").click(); + overlay.classList.remove("overlay--show", "overlay--show-lv5"); + search.classList.remove("o-search--show"); + }; + + // Scroll to search on click + if (search && isHome) { + search.addEventListener("click", function () { + overlay.classList.add("overlay--show", "overlay--show-lv5"); + search.scrollIntoView({ behavior: "smooth", block: "start" }); + }); + } + + function showSearchOnContentPage() { + search.classList.add("o-search--show"); + overlay.classList.add("overlay--show", "overlay--show-lv5"); + searchElement.focus(); + } + + function showSearchOnStartPage() { + overlay.classList.add("overlay--show", "overlay--show-lv5"); + searchElement.focus(); + search.scrollIntoView({ behavior: "smooth", block: "start" }); + } + + searchButtons.forEach((button) => { + if (isHome) { + button.addEventListener("click", showSearchOnStartPage); + } else { + button.addEventListener("click", showSearchOnContentPage); + } + }); + + // Open search on Ctrl + K or Cmd + K + document.addEventListener("keydown", (e) => { + if ((e.ctrlKey || e.metaKey) && e.key === "k") { + e.preventDefault(); + if (isHome) { + showSearchOnStartPage(); + } else { + showSearchOnContentPage(); + } + } + }); + + // Close search on ESC + document.addEventListener("keydown", (e) => { + if (e.key === "Escape") { + closeSearch(); + } + }); + + overlay.addEventListener("click", closeSearch); +}; + +if (document.readyState === "interactive") { + initSearch(); +} else { + window.addEventListener("DOMContentLoaded", () => { + initSearch(); + }); +} diff --git a/assets/sass/_variables.scss b/assets/sass/_variables.scss index 9c312a39..9e3eda6f 100644 --- a/assets/sass/_variables.scss +++ b/assets/sass/_variables.scss @@ -16,7 +16,7 @@ $color-onLight: #000000; $color-table-border: #5b5b5b; html { - --pagefind-ui-scale: 1; + --pagefind-ui-scale: 1 !important; --pagefind-ui-text: #000; --link-default: #{$link-default}; --link-hovered: #{$link-hovered}; diff --git a/assets/sass/contentNavigation.scss b/assets/sass/contentNavigation.scss index 7bb9df14..26d63ab3 100644 --- a/assets/sass/contentNavigation.scss +++ b/assets/sass/contentNavigation.scss @@ -108,7 +108,6 @@ bottom: 0; left: 0; width: 100%; - max-height: 100vh; gap: 0; overflow: hidden; flex-flow: column; @@ -191,15 +190,3 @@ display: none; } } - -.overlay--show { - backdrop-filter: blur(4px); - background-color: rgba(0, 0, 0, 0.6); - position: fixed; - inset: 0; - z-index: 3; -} - -body:has(.overlay--show) { - overflow: hidden; -} diff --git a/assets/sass/navigation.scss b/assets/sass/navigation.scss index 50c57542..fe916b4e 100644 --- a/assets/sass/navigation.scss +++ b/assets/sass/navigation.scss @@ -4,7 +4,7 @@ top: 0; box-shadow: 0 0.4rem 1rem 0 rgba(0, 0, 0, 0.1); background-color: var(--bg-default); - z-index: 5; + z-index: 7; height: 6rem; padding-left: calc((100vw - 100%) / 2); border-bottom: var(--border); @@ -286,7 +286,7 @@ body:has(.o-header__nav--open) { overflow: hidden; } -.a-theme-toggle { +.o-header__button { padding: 1rem; border: none; background: transparent; @@ -298,21 +298,21 @@ body:has(.o-header__nav--open) { &:hover { color: var(--link-hovered); } +} - &--desktop { - display: none; +.o-header__item--desktop { + display: none; - @media (min-width: #{$breakpoint-md}) { - display: inline-flex; - } + @media (min-width: #{$breakpoint-md}) { + display: inline-flex; } +} - &--mobile { - display: inline-flex; +.o-header__item--mobile { + display: inline-flex; - @media (min-width: #{$breakpoint-md}) { - display: none; - } + @media (min-width: #{$breakpoint-md}) { + display: none; } } diff --git a/assets/sass/search.scss b/assets/sass/search.scss index 6db0dd3f..0e07aa12 100644 --- a/assets/sass/search.scss +++ b/assets/sass/search.scss @@ -1,20 +1,36 @@ #search { width: 100%; - height: 6rem; display: flex; - z-index: 2; + z-index: 6; + + @media print { + display: none; + } .pagefind-ui__search-input, - .pagefind-ui__message, - .pagefind-ui__search-clear { + .pagefind-ui__message { font-family: "Roboto", Arial, Helvetica, sans-serif; + font-weight: 400; } - .pagefind-ui__search-input { - z-index: 3; + .pagefind-ui__message { + padding: 1rem; + } + + .pagefind-ui__results-area { + margin-top: 0; + } + + .pagefind-ui__results li:last-child { + border-bottom: none; + } + + input.pagefind-ui__search-input { + z-index: 6; outline: 0.2rem solid transparent; border: var(--border); box-shadow: var(--box-shadow); + border-radius: var(--border-radius-l); @include focus-indicator(0.2rem); @@ -22,14 +38,19 @@ opacity: 0.7; color: var(--color-body); } + + // This selector is used to identify if search results are visible + &:has( + + .pagefind-ui__search-clear + + .pagefind-ui__drawer + .pagefind-ui__results-area + ) { + border-radius: var(--border-radius-l) var(--border-radius-l) 0 0; + } } - .pagefind-ui__search-clear { - z-index: 3; - height: auto; - padding: 1rem; - top: 1rem; - margin-right: 0.7rem; + button.pagefind-ui__search-clear { + display: none; } .pagefind-ui__suppressed { @@ -37,19 +58,40 @@ } .pagefind-ui__form::before { - z-index: 4; + z-index: 7; } .pagefind-ui__drawer { background-color: var(--bg-default); - padding: 0 1rem 1rem 1rem; + padding: 0 1rem; overscroll-behavior: contain; - height: 35rem; - top: 0.4rem; overflow-y: scroll; - position: relative; - border-radius: var(--pagefind-ui-border-radius); - z-index: 3; + position: absolute; + top: 7rem; + width: 100%; + z-index: 6; + max-height: 50vh; + border: var(--border); + border-radius: 0 0 var(--border-radius-l) var(--border-radius-l); + } + + .pagefind-ui__result { + padding: 2rem 0; + margin: 0 1rem; + border-top: 0.2rem solid grey; + } + + .pagefind-ui__result-inner, + .pagefind-ui__result-thumb { + margin-top: 0; + } + + .pagefind-ui__result-thumb { + width: 10rem; + + @media (max-width: #{$breakpoint-md}) { + display: none; + } } .pagefind-ui__result-link { @@ -81,11 +123,13 @@ color: var(--color-body); } - .pagefind-ui__button { + button.pagefind-ui__button { border: 0.2rem solid var(--link-default); border-radius: var(--border-radius-m); background: transparent; color: var(--body-color); + margin-top: 0; + margin-bottom: 1rem; &:hover, &:focus { @@ -94,18 +138,19 @@ } } -.curtain { - background-color: rgba(0, 0, 0, 0.8); - z-index: 2; - transition: opacity 0.3s ease; - opacity: 0; -} +.o-search { + &--contentpage { + position: absolute; + display: none; + opacity: 0; + visibility: hidden; + transition: opacity 0.5s ease; + } -main:has(#search:focus-within), -main:has(.pagefind-ui__drawer:not(.pagefind-ui__hidden)) { - .curtain { + &--show { + display: block; opacity: 1; - position: fixed; - inset: 0; + visibility: visible; + z-index: 6; } } diff --git a/assets/sass/styles.scss b/assets/sass/styles.scss index d6021f5f..b5eebf69 100644 --- a/assets/sass/styles.scss +++ b/assets/sass/styles.scss @@ -119,6 +119,7 @@ main { width: 100%; margin-left: auto; margin-right: auto; + position: relative; } .o-card { @@ -382,3 +383,23 @@ details > summary { content: " (" attr(href) ") "; } } + +.overlay--show { + backdrop-filter: blur(4px); + background-color: rgba(0, 0, 0, 0.6); + position: fixed; + inset: 0; + z-index: 3; + + @media print { + display: none; + } +} + +.overlay--show-lv5 { + z-index: 5; +} + +body:has(.overlay--show) { + overflow: hidden; +} diff --git a/i18n/de.yaml b/i18n/de.yaml index 19a09d29..b8d97ce8 100644 --- a/i18n/de.yaml +++ b/i18n/de.yaml @@ -20,10 +20,6 @@ contentNavigation: title: Inhaltsübersicht countries: overview: Länder mit FIP Akzeptanz - selection: - aria-label: Land auswählen - dropdown-label: Verfügbare Länder - title: Länder without-fip: Länder ohne FIP Akzeptanz country: many: Länder @@ -55,16 +51,31 @@ interactiveMap: language-switcher: aria-label: Sprache wechseln dropdown-label: Verfügbare Sprachen -menu-close: Schließen -menu-open: Menü +menu: + close: + label: Schließen + title: Menü schließen + country-dropdown: + aria-label: Länder-Dropdown öffnen + dropdown-label: Verfügbare Länder + label: Länder + title: Länder-Dropdown öffnen + open: + label: Menü + title: Menü öffnen + operator-dropdown: + aria-label: Betreiber-Dropdown öffnen + dropdown-label: Verfügbare Betreiber + label: Betreiber + title: Betreiber-Dropdown öffnen + search: Suche öffnen + theme: + switch-to-auto: Zu automatischem Modus wechseln + switch-to-dark: Zu dunklem Modus wechseln + switch-to-light: Zu hellem Modus wechseln navigate-to-country: Gehe zu Land news-headline: Was gibt's Neues? news-other: Weitere News -operators: - selection: - aria-label: Betreiber auswählen - dropdown-label: Verfügbare Betreiber - title: Betreiber operators_without_fip: Betreiber ohne FIP related: countries: Verwandte Länder @@ -86,10 +97,6 @@ support: vorbei, um Inhalte beizutragen. Alternativ kannst du uns auch über das Kontaktformular schreiben. title: Unterstütze uns -theme: - switch-to-auto: Zu automatischem Modus wechseln - switch-to-dark: Zu dunklem Modus wechseln - switch-to-light: Zu hellem Modus wechseln toc_name: Inhalt updateDate: aria-label: Öffne die Commit-Verlauf der Seite diff --git a/i18n/en.yaml b/i18n/en.yaml index 9cc61fa6..9f6f1caf 100644 --- a/i18n/en.yaml +++ b/i18n/en.yaml @@ -19,10 +19,6 @@ contentNavigation: title: Content overview countries: overview: Countries with FIP acceptance - selection: - aria-label: Select a country - dropdown-label: Available countries - title: Countries without-fip: Countries without FIP acceptance country: many: countries @@ -54,16 +50,31 @@ interactiveMap: language-switcher: aria-label: Switch language dropdown-label: Available languages -menu-close: Close -menu-open: Menu +menu: + close: + label: Close + title: Close menu + country-dropdown: + aria-label: Open Country-Dropdown + dropdown-label: Available countries + label: Countries + title: Open Country-Dropdown + open: + label: Menu + title: Open Menu + operator-dropdown: + aria-label: Open Operator-Dropdown + dropdown-label: Available operators + label: Operators + title: Open Operator-Dropdown + search: Open search + theme: + switch-to-auto: Switch to auto mode + switch-to-dark: Switch to dark mode + switch-to-light: Switch to light mode navigate-to-country: Navigate to country news-headline: What's new? news-other: Other News -operators: - selection: - aria-label: Select an operator - dropdown-label: Available operators - title: Operators operators_without_fip: Operators without FIP related: countries: Related Countries @@ -82,10 +93,6 @@ support: to contribute content. Alternatively, you can also write to us via the contact form. title: Support Us -theme: - switch-to-auto: Switch to auto mode - switch-to-dark: Switch to dark mode - switch-to-light: Switch to light mode toc_name: Contents updateDate: aria-label: Open the commit history of the page diff --git a/i18n/fr.yaml b/i18n/fr.yaml index ac252b1f..73e25e2d 100644 --- a/i18n/fr.yaml +++ b/i18n/fr.yaml @@ -19,10 +19,6 @@ contentNavigation: title: Aperçu du contenu countries: overview: Pays acceptation FIP - selection: - aria-label: Sélectionner un pays - dropdown-label: Pays disponibles - title: Pays without-fip: Pays sans acceptation FIP country: many: pays @@ -54,16 +50,31 @@ interactiveMap: language-switcher: aria-label: Changer de langue dropdown-label: Langues disponibles -menu-close: Fermer -menu-open: Menu +menu: + close: + label: Fermer + title: Fermer le menu + country-dropdown: + aria-label: Menu déroulant du pays ouvert + dropdown-label: Pays disponibles + label: Pays + title: Menu déroulant du pays ouvert + open: + label: Menu + title: Ouvrir le menu + operator-dropdown: + aria-label: Ouvrir la liste déroulante de l'opérateur + dropdown-label: Opérateurs disponibles + label: Opérateurs + title: Ouvrir la liste déroulante de l'opérateur + search: Ouvrir la recherche + theme: + switch-to-auto: Passer en mode automatique + switch-to-dark: Passer en mode sombre + switch-to-light: Passer en mode clair navigate-to-country: Aller au pays news-headline: Quoi de neuf ? news-other: Autres actualités -operators: - selection: - aria-label: Sélectionner un opérateur - dropdown-label: Opérateurs disponibles - title: Opérateurs operators_without_fip: Opérateurs sans FIP related: countries: Pays associés @@ -82,10 +93,6 @@ support: GitHub pour contribuer au contenu. Vous pouvez également nous écrire via le formulaire de contact. title: Soutenez-nous -theme: - switch-to-auto: Passer en mode automatique - switch-to-dark: Passer en mode sombre - switch-to-light: Passer en mode clair toc_name: Sommaire updateDate: aria-label: Ouvrir l'historique des commits de la page diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 9cb621d9..ccbb5bd7 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -16,6 +16,14 @@ {{ end }}" >