Refine shared header language selector
This commit is contained in:
+73
-25
@@ -1,32 +1,80 @@
|
||||
/* Persistent language choice, also available before login. */
|
||||
.language-switch {
|
||||
/* Shared language/account controls, including pages shown before login. */
|
||||
.header-controls {
|
||||
position: relative;
|
||||
z-index: 2000;
|
||||
display: flex;
|
||||
flex-wrap: nowrap;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 6px;
|
||||
min-width: 0;
|
||||
max-width: 100%;
|
||||
margin-left: auto;
|
||||
}
|
||||
.language-switch { position: relative; flex: 0 0 auto; margin: 0; padding: 0; }
|
||||
.language-switch > summary {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex: 0 0 auto;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
gap: 5px;
|
||||
min-height: 44px;
|
||||
padding: 6px 8px;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 9px;
|
||||
color: var(--muted, #57534e);
|
||||
background: transparent;
|
||||
font: 500 .85rem/1.2 system-ui, sans-serif;
|
||||
white-space: nowrap;
|
||||
cursor: pointer;
|
||||
list-style: none;
|
||||
}
|
||||
.language-switch a {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 38px;
|
||||
height: 36px;
|
||||
border: 1px solid var(--border, #30363d);
|
||||
border-radius: 8px;
|
||||
color: var(--text, #222);
|
||||
font-family: system-ui, sans-serif;
|
||||
font-size: 1.2rem;
|
||||
line-height: 1;
|
||||
text-decoration: none;
|
||||
.language-switch > summary::-webkit-details-marker { display: none; }
|
||||
.language-caret { font-size: .7rem; }
|
||||
.language-switch[open] > summary,
|
||||
.language-switch > summary:active { color: var(--text, #f5f5f4); background: var(--surface-hover, #1a1111); border-color: var(--border, #3a3030); }
|
||||
.language-panel {
|
||||
position: absolute;
|
||||
top: calc(100% + 6px);
|
||||
right: 0;
|
||||
z-index: 10000;
|
||||
width: 200px;
|
||||
max-width: calc(100vw - 24px);
|
||||
padding: 6px;
|
||||
border: 1px solid var(--border, #3a3030);
|
||||
border-radius: 10px;
|
||||
color: var(--text, #f5f5f4);
|
||||
background: var(--surface, #101010);
|
||||
box-shadow: 0 14px 35px rgba(0,0,0,.65);
|
||||
}
|
||||
.language-switch a.active { background: #922525; color: #fff; border-color: #c74747; }
|
||||
.language-switch a:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
|
||||
.language-switch a:hover { background: #7f1d1d; }
|
||||
.header-controls { display: flex; align-items: center; justify-content: flex-end; gap: 6px; margin-left: auto; }
|
||||
.header-controls .user-menu { margin-left: 0; }
|
||||
.language-heading { margin: 0; padding: 8px 10px; font-size: .8rem; color: var(--muted, #a8a29e); }
|
||||
.language-panel a { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 8px 10px; border-radius: 6px; color: inherit; font: 400 .9rem/1.3 system-ui, sans-serif; text-decoration: none; }
|
||||
.language-panel a[aria-current] { background: var(--surface-hover, #1a1111); font-weight: 700; }
|
||||
.language-selected { margin-left: auto; }
|
||||
.language-switch summary:focus-visible { outline: 2px solid var(--text, #57534e); outline-offset: 2px; }
|
||||
.language-panel a:focus-visible,
|
||||
.header-controls .user-menu summary:focus-visible { outline: 2px solid var(--text, #f5f5f4); outline-offset: 2px; }
|
||||
@media (hover: hover) {
|
||||
.language-switch > summary:hover { color: var(--text, #f5f5f4); background: var(--surface-hover, #1a1111); border-color: var(--border, #3a3030); }
|
||||
.language-panel a:hover { background: var(--surface-hover, #1a1111); }
|
||||
}
|
||||
/* Both menus anchor to the same right edge, independent of the page header. */
|
||||
.header-controls .language-switch,
|
||||
.header-controls .user-menu { position: static; margin-left: 0; }
|
||||
.header-controls .user-menu { min-width: 0; }
|
||||
.header-controls .user-menu summary { display: flex; align-items: center; gap: 5px; min-height: 44px; max-width: 220px; }
|
||||
.user-menu-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.header-controls .metal-notification { flex-shrink: 0; margin-right: 7px; }
|
||||
.header-controls .user-menu-panel { position: absolute; top: calc(100% + 6px); right: 0; max-width: calc(100vw - 24px); max-height: calc(100dvh - 90px); overflow-y: auto; }
|
||||
.header-inner { gap: 8px; }
|
||||
.header-inner > .logo { min-width: 0; flex-shrink: 1; }
|
||||
.header-inner > .logo .brand-logo { max-width: 100% !important; }
|
||||
.header-inner > .language-switch { margin-left: auto; }
|
||||
.header-actions > .header-controls { flex: 0 0 auto; }
|
||||
.detail-topbar > .header-controls { flex: 0 0 auto; }
|
||||
.detail-topbar { align-items: center; padding-inline: 12px; }
|
||||
.detail-topbar > .back-link { min-width: 0; overflow-wrap: anywhere; }
|
||||
.detail-topbar > .header-controls { flex-shrink: 0; }
|
||||
.registration-header { display: flex; justify-content: flex-end; margin: -36px 0 12px; }
|
||||
@media (max-width: 600px) {
|
||||
.header-controls .user-menu summary { max-width: 30vw; padding: 8px; }
|
||||
.language-switch > summary { padding: 6px; }
|
||||
.detail-topbar { gap: 8px; }
|
||||
}
|
||||
|
||||
@@ -232,7 +232,6 @@ main {
|
||||
|
||||
.logo { max-width: 130px; }
|
||||
.brand-logo { width: 130px !important; max-width: 130px !important; height: 40px !important; max-height: 40px !important; }
|
||||
.header-controls .user-menu summary { max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
|
||||
main {
|
||||
padding: 22px 15px 80px;
|
||||
@@ -248,7 +247,6 @@ main {
|
||||
|
||||
.header-actions { width: 100%; justify-content: flex-start; }
|
||||
.header-actions > a { flex: 1 1 auto; text-align: center; }
|
||||
.header-actions > .header-controls { margin-left: auto; }
|
||||
}
|
||||
form {
|
||||
max-width: 650px;
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/* Native details/summary provides keyboard activation and expanded state. */
|
||||
(() => {
|
||||
const selector = '.language-switch, .header-controls .user-menu';
|
||||
document.addEventListener('toggle', event => {
|
||||
if (!event.target.matches(selector) || !event.target.open) return;
|
||||
document.querySelectorAll(selector).forEach(menu => {
|
||||
if (menu !== event.target) menu.open = false;
|
||||
});
|
||||
}, true);
|
||||
document.addEventListener('click', event => {
|
||||
document.querySelectorAll(selector).forEach(menu => {
|
||||
if (menu.open && !menu.contains(event.target)) menu.open = false;
|
||||
});
|
||||
});
|
||||
document.addEventListener('keydown', event => {
|
||||
if (event.key !== 'Escape') return;
|
||||
document.querySelectorAll(selector).forEach(menu => {
|
||||
if (!menu.open) return;
|
||||
menu.open = false;
|
||||
menu.querySelector('summary').focus();
|
||||
event.preventDefault();
|
||||
});
|
||||
});
|
||||
})();
|
||||
@@ -1,4 +1,14 @@
|
||||
<nav class="language-switch" aria-label="{{ _('Sprache') }}">
|
||||
{% set target_language = 'en' if language() == 'de' else 'de' %}
|
||||
<a class="active" href="{{ language_url(target_language) }}" lang="{{ target_language }}" hreflang="{{ target_language }}" aria-label="{{ _('Zu Englisch wechseln') if target_language == 'en' else _('Zu Deutsch wechseln') }}" title="{{ _('Zu Englisch wechseln') if target_language == 'en' else _('Zu Deutsch wechseln') }}">{{ '🇬🇧' if target_language == 'en' else '🇩🇪' }}</a>
|
||||
<details class="language-switch">
|
||||
<summary aria-label="{{ _('Sprache wechseln') }}: {{ language() | upper }}">
|
||||
<span aria-hidden="true">🌐</span> <span>{{ language() | upper }}</span> <span class="language-caret" aria-hidden="true">▾</span>
|
||||
</summary>
|
||||
<nav class="language-panel" aria-label="{{ _('Sprache') }}">
|
||||
<p class="language-heading"><span aria-hidden="true">🌐</span> {{ _('Sprache') }}</p>
|
||||
{% for code, flag, label in [('de', '🇩🇪', 'Deutsch'), ('en', '🇬🇧', 'English')] %}
|
||||
<a href="{{ language_url(code) }}" lang="{{ code }}" hreflang="{{ code }}"{% if language() == code %} aria-current="true"{% endif %}>
|
||||
<span aria-hidden="true">{{ flag }}</span> <span>{{ label }}</span>{% if language() == code %}<span class="language-selected" aria-hidden="true">✓</span>{% endif %}
|
||||
</a>
|
||||
{% endfor %}
|
||||
</nav>
|
||||
</details>
|
||||
<script src="/static/js/header-controls.js" defer></script>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<details class="user-menu">
|
||||
<summary>☠ {{ user.display_name }}{% if user.notification_count %} <span class="metal-notification" title="{{ user.notification_count }} {{ _('neue Nachricht(en) oder Anfrage(n)') }}" aria-label="{{ _('Neue Benachrichtigungen') }}">🤘<b>{{ user.notification_count }}</b></span>{% endif %}</summary>
|
||||
<summary><span aria-hidden="true">☠</span> <span class="user-menu-name">{{ user.display_name }}</span>{% if user.notification_count %} <span class="metal-notification" title="{{ user.notification_count }} {{ _('neue Nachricht(en) oder Anfrage(n)') }}" aria-label="{{ _('Neue Benachrichtigungen') }}">🤘<b>{{ user.notification_count }}</b></span>{% endif %}</summary>
|
||||
<div class="user-menu-panel">
|
||||
<a href="/profile">{{ _('Mein Profil') }}</a>
|
||||
<a href="/messages">{{ _('Nachrichten') }}{% if user.notification_count %} <span class="metal-notification" title="{{ _('Neue Nachrichten oder Anfragen') }}" aria-label="{{ _('Neue Nachrichten oder Anfragen') }}">🤘<b>{{ user.notification_count }}</b></span>{% endif %}</a>
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
>
|
||||
|
||||
<style>
|
||||
.detail-topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
|
||||
.detail-topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
|
||||
.event-type-badge { display: inline-block; margin-bottom: 8px; padding: 4px 9px; border: 1px solid #4b5563; border-radius: 999px; color: #c4b5fd; font-size: .8rem; font-weight: 700; text-transform: uppercase; }
|
||||
.parent-event-link { color: #c4b5fd; }
|
||||
.flyer-source { display: block; width: 100%; flex: 0 0 100%; margin: 10px 0 0; color: #a8a29e; font-size: .85rem; text-align: center; }
|
||||
|
||||
@@ -21,10 +21,10 @@
|
||||
<style>
|
||||
|
||||
.page-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) auto;
|
||||
align-items: center;
|
||||
gap: 20px;
|
||||
gap: 12px 16px;
|
||||
margin-bottom: 35px;
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
}
|
||||
|
||||
.header-actions {
|
||||
grid-column: 1 / -1;
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
@@ -175,7 +176,7 @@
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.page-header { padding: 24px; border: 1px solid #5f1515; border-left: 4px solid #dc2626; border-radius: 14px; background: linear-gradient(110deg, rgba(10,10,10,.9), rgba(69,10,10,.28)); box-shadow: 0 12px 30px rgba(0,0,0,.3); }
|
||||
.page-header { padding: 16px 20px; border: 1px solid #5f1515; border-left: 4px solid #dc2626; border-radius: 14px; background: linear-gradient(110deg, rgba(10,10,10,.9), rgba(69,10,10,.28)); box-shadow: 0 12px 30px rgba(0,0,0,.3); }
|
||||
.page-header h1 { font-family: "Nimbus Sans Narrow", Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif; letter-spacing: .05em; text-transform: uppercase; text-shadow: 0 2px 18px rgba(185, 28, 28, .45); }
|
||||
.new-concert-button { background: #991b1b; border: 1px solid #dc2626; }
|
||||
.new-concert-button:hover { background: #b91c1c; }
|
||||
@@ -185,13 +186,23 @@
|
||||
.concert-date { color: #ef4444; }
|
||||
.concert-card.linked-event { border-left-color: #dc2626; background: #0d0d0d; }
|
||||
|
||||
@media (min-width: 1024px) {
|
||||
.page-header { grid-template-columns: minmax(0, 1fr) auto auto; }
|
||||
.page-header > .header-controls { grid-column: 3; grid-row: 1; }
|
||||
.page-header > .header-actions { grid-column: 2; grid-row: 1; }
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
|
||||
.page-header {
|
||||
align-items: flex-start;
|
||||
flex-direction: column;
|
||||
padding: 12px;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.page-header .subtitle { display: none; }
|
||||
.page-header h1 { font-size: 1.25rem; overflow-wrap: anywhere; }
|
||||
.page-header .brand-logo { max-width: 100% !important; }
|
||||
|
||||
.new-concert-button {
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
@@ -244,6 +255,8 @@
|
||||
</div>
|
||||
|
||||
|
||||
{% include '_header_controls.html' %}
|
||||
|
||||
<div class="header-actions">
|
||||
|
||||
<a href="{% if archive %}/{% else %}/events/past{% endif %}" class="admin-button">
|
||||
@@ -257,8 +270,6 @@
|
||||
{{ _('+ Veranstaltung hinzufügen') }}
|
||||
</a>
|
||||
|
||||
{% include '_header_controls.html' %}
|
||||
|
||||
</div>
|
||||
|
||||
</header>
|
||||
|
||||
@@ -69,7 +69,9 @@ class TranslationTests(unittest.TestCase):
|
||||
for path, title in [('/datenschutz', 'Privacy policy'), ('/impressum', 'Legal notice')]:
|
||||
page = client.get(path)
|
||||
self.assertIn(title, page.text)
|
||||
self.assertIn('aria-label="Switch to German"', page.text)
|
||||
self.assertIn('aria-label="Switch language: EN"', page.text)
|
||||
self.assertIn('lang="en" hreflang="en" aria-current="true"', page.text)
|
||||
self.assertIn('>Deutsch</span>', page.text)
|
||||
response = client.get('/language/de?next=/login')
|
||||
self.assertIn('Anmelden', response.text)
|
||||
self.assertIn('<html lang="de">', response.text)
|
||||
|
||||
Reference in New Issue
Block a user