Fichiers
site-principal/news/reglages.js
T
2026-11-08 22:23:21 +01:00

452 lignes
27 KiB
JavaScript
Brut Annotations Historique

Ce fichier contient des caractères Unicode ambigus.
Ce fichier contient des caractères Unicode qui peuvent être confondus avec d'autres caractères. Si vous pensez que c'est intentionnel, vous pouvez ignorer cet avertissement. Utilisez le bouton Échappe pour les dévoiler.
/* news/reglages.js : bouton Paramètres (engrenage) + panneau de réglages. Sans bibliothèque.
* Placé dans le DOM à la fin de <body>, jamais dans Accueil / Portfolio / Réalisations / L'envers du décor.
* Contenu : (a) flux News (niveau + thèmes), (b) langue. Pas de thème sombre, pas de « fun fact ».
* Les choix sont mémorisés dans localStorage (clé « gastinel-actus »), avec try/catch : sans stockage, tout marche
* pour la page en cours. Le composant News (news/actus.js) est prévenu par l'évènement « gastinel:prefs ».
* Première visite de /news/ : une invite « Quel flux veux-tu ? » s'ouvre une fois, puis se range.
* À venir (non codé) : connexion Gastinel Hub et abonnement par mail, voir le rapport.
*/
(function () {
'use strict';
var STORE_KEY = 'gastinel-actus';
var THEME_IDS = ['audiovisuel', 'applications', 'technique', 'site', 'meteo', 'minecraft', 'mind', 'hub', 'vie-locale'];
var LEVEL_IDS = ['simple', 'normal', 'developpeur'];
var LANGS = [['fr', '/', 'Français'], ['en', '/en/', 'English'], ['de', '/de/', 'Deutsch'], ['it', '/it/', 'Italiano'], ['es', '/es/', 'Español']];
var T = {
fr: {
themeH: 'Thème', themes2: [['clair', 'Clair', 'Par défaut.'], ['sombre', 'Sombre', 'Fond foncé, moins de lumière le soir.']],
foot: 'Paramètres d’accessibilité', btn: 'Paramètres', close: 'Fermer', title: 'Paramètres',
newsH: 'Flux News', levelH: 'Niveau de détail', themesH: 'Thèmes', allThemes: 'Tous les thèmes',
levels: { simple: ['Simple', 'Des mots faciles, très court.'], normal: ['Normal', 'Pour tout le monde (par défaut).'], developpeur: ['Développeur', 'Plus de détails techniques.'] },
themes: ['Audiovisuel', 'Applications', 'Technique et projets', 'Mises à jour du site', 'Météo', 'Minecraft', 'Mind et IA', 'Hub et comptes', 'Vie locale à Lans'],
note: 'Tes choix restent dans ce navigateur. Sans choix : niveau normal, tous les thèmes.',
noStore: 'Ton navigateur ne peut pas mémoriser tes choix : ils valent seulement jusqu’à la fermeture de cette page.',
noneChecked: 'Aucun thème coché : tous les thèmes sont affichés.',
langH: 'Langue', newsLink: 'Voir les news', frOnly: '',
inviteTitle: 'Quel flux veux-tu ?', inviteIntro: 'Choisis le niveau et les thèmes des news. Tu pourras changer plus tard avec le bouton Paramètres.',
ok: 'Valider', later: 'Plus tard'
},
en: {
themeH: 'Theme', themes2: [['clair', 'Light', 'Default.'], ['sombre', 'Dark', 'Dark background, less light at night.']],
foot: 'Accessibility settings', btn: 'Settings', close: 'Close', title: 'Settings',
newsH: 'News feed', levelH: 'Level of detail', themesH: 'Topics', allThemes: 'All topics',
levels: { simple: ['Simple', 'Easy words, very short.'], normal: ['Normal', 'For everyone (default).'], developpeur: ['Developer', 'More technical details.'] },
themes: ['Audiovisual', 'Apps', 'Tech and projects', 'Site updates', 'Weather', 'Minecraft', 'Mind and AI', 'Hub and accounts', 'Local life in Lans'],
note: 'Your choices stay in this browser. By default: normal level, all topics.',
noStore: 'Your browser cannot remember your choices: they only last until you close this page.',
noneChecked: 'No topic ticked: all topics are shown.',
langH: 'Language', newsLink: 'See the news', frOnly: 'The News page is in French.',
inviteTitle: 'Which feed do you want?', inviteIntro: 'Choose the level and topics of the news. You can change them later with the Settings button.',
ok: 'Save', later: 'Later'
},
de: {
themeH: 'Design', themes2: [['clair', 'Hell', 'Standard.'], ['sombre', 'Dunkel', 'Dunkler Hintergrund, weniger Licht am Abend.']],
foot: 'Einstellungen zur Barrierefreiheit', btn: 'Einstellungen', close: 'Schließen', title: 'Einstellungen',
newsH: 'News-Feed', levelH: 'Detailstufe', themesH: 'Themen', allThemes: 'Alle Themen',
levels: { simple: ['Einfach', 'Leichte Wörter, ganz kurz.'], normal: ['Normal', 'Für alle (Standard).'], developpeur: ['Entwickler', 'Mehr technische Details.'] },
themes: ['Audiovisuell', 'Apps', 'Technik und Projekte', 'Website-Updates', 'Wetter', 'Minecraft', 'Mind und KI', 'Hub und Konten', 'Lokales aus Lans'],
note: 'Deine Auswahl bleibt in diesem Browser. Standard: Stufe Normal, alle Themen.',
noStore: 'Dein Browser kann deine Auswahl nicht speichern: sie gilt nur, bis du diese Seite schließt.',
noneChecked: 'Kein Thema gewählt: Es werden alle Themen angezeigt.',
langH: 'Sprache', newsLink: 'News ansehen', frOnly: 'Die News-Seite ist auf Französisch.',
inviteTitle: 'Welchen Feed möchtest du?', inviteIntro: 'Wähle Stufe und Themen der News. Du kannst sie später über die Schaltfläche Einstellungen ändern.',
ok: 'Speichern', later: 'Später'
},
it: {
themeH: 'Tema', themes2: [['clair', 'Chiaro', 'Predefinito.'], ['sombre', 'Scuro', 'Sfondo scuro, meno luce la sera.']],
foot: 'Impostazioni di accessibilità', btn: 'Impostazioni', close: 'Chiudi', title: 'Impostazioni',
newsH: 'Feed News', levelH: 'Livello di dettaglio', themesH: 'Temi', allThemes: 'Tutti i temi',
levels: { simple: ['Semplice', 'Parole facili, molto breve.'], normal: ['Normale', 'Per tutti (predefinito).'], developpeur: ['Sviluppatore', 'Più dettagli tecnici.'] },
themes: ['Audiovisivo', 'App', 'Tecnica e progetti', 'Aggiornamenti del sito', 'Meteo', 'Minecraft', 'Mind e IA', 'Hub e account', 'Vita locale a Lans'],
note: 'Le tue scelte restano in questo browser. Predefinito: livello normale, tutti i temi.',
noStore: 'Il tuo browser non può ricordare le scelte: valgono solo fino alla chiusura di questa pagina.',
noneChecked: 'Nessun tema selezionato: vengono mostrati tutti i temi.',
langH: 'Lingua', newsLink: 'Vedi le news', frOnly: 'La pagina News è in francese.',
inviteTitle: 'Quale feed vuoi?', inviteIntro: 'Scegli il livello e i temi delle news. Potrai cambiarli dopo con il pulsante Impostazioni.',
ok: 'Salva', later: 'Più tardi'
},
es: {
themeH: 'Tema', themes2: [['clair', 'Claro', 'Por defecto.'], ['sombre', 'Oscuro', 'Fondo oscuro, menos luz por la noche.']],
foot: 'Ajustes de accesibilidad', btn: 'Ajustes', close: 'Cerrar', title: 'Ajustes',
newsH: 'Feed de News', levelH: 'Nivel de detalle', themesH: 'Temas', allThemes: 'Todos los temas',
levels: { simple: ['Simple', 'Palabras fáciles, muy breve.'], normal: ['Normal', 'Para todos (por defecto).'], developpeur: ['Desarrollador', 'Más detalles técnicos.'] },
themes: ['Audiovisual', 'Apps', 'Técnica y proyectos', 'Novedades del sitio', 'Tiempo', 'Minecraft', 'Mind e IA', 'Hub y cuentas', 'Vida local en Lans'],
note: 'Tus elecciones se quedan en este navegador. Por defecto: nivel normal, todos los temas.',
noStore: 'Tu navegador no puede recordar tus elecciones: solo valen hasta cerrar esta página.',
noneChecked: 'Ningún tema marcado: se muestran todos los temas.',
langH: 'Idioma', newsLink: 'Ver las news', frOnly: 'La página News está en francés.',
inviteTitle: '¿Qué feed quieres?', inviteIntro: 'Elige el nivel y los temas de las news. Podrás cambiarlos luego con el botón Ajustes.',
ok: 'Guardar', later: 'Más tarde'
}
};
var lang = String(document.documentElement.getAttribute('lang') || 'fr').slice(0, 2).toLowerCase();
if (!Object.prototype.hasOwnProperty.call(T, lang)) lang = 'fr';
var L = T[lang];
var onNewsPage = document.documentElement.hasAttribute('data-news') || /^\/news(\/|$)/.test(location.pathname);
/* News a son propre sous-domaine (aperçu LAN : port 8772 ; site : port 8779). Les liens « /news/… » du site
* et « / » ou « /#… » de la page News sont réécrits au clic vers l'autre adresse. */
var lan = location.port === '8779' || location.port === '8772';
var NEWS_URL = lan ? location.protocol + '//' + location.hostname + ':8772/' : 'https://news.gastinel.me/';
var MAIN_URL = lan ? location.protocol + '//' + location.hostname + ':8779/' : 'https://gastinel.me/';
document.addEventListener('click', function (e) {
var a = e.target && e.target.closest ? e.target.closest('a[href]') : null;
if (!a) return;
var h = a.getAttribute('href');
if (onNewsPage && (a.hasAttribute('data-main') || h === '/' || h.indexOf('/#') === 0)) a.href = MAIN_URL + h.slice(1);
else if (!onNewsPage && h.indexOf('/news/') === 0) a.href = NEWS_URL + h.slice(6);
}, true);
/* ---------- Réglages ---------- */
var storageOk = true;
var state = { level: 'normal', themes: null, asked: false, theme: 'clair' };
/* Thème : clé à part, commune à tous les sites Gastinel (« gastinel-theme » = « clair » ou « sombre »). */
var THEME_KEY = 'gastinel-theme';
/* Cookie de préférence (même nom) partagé par les sous-domaines de gastinel.me : exempté de consentement
* selon la CNIL (réglage demandé par la personne), durée limitée à moins de 13 mois (390 jours). */
var ON_GASTINEL = /(^|\.)gastinel\.me$/.test(location.hostname);
function readThemeCookie() {
var m = document.cookie.match(/(?:^|;\s*)gastinel-theme=(clair|sombre)/);
return m ? m[1] : null;
}
function writeThemeCookie(v) {
if (!ON_GASTINEL) return;
document.cookie = THEME_KEY + '=' + v + '; domain=.gastinel.me; path=/; max-age=' + (390 * 86400) + '; SameSite=Lax; Secure';
}
function load() {
var c = readThemeCookie();
if (c) state.theme = c;
else try { if (window.localStorage.getItem(THEME_KEY) === 'sombre') state.theme = 'sombre'; } catch (e) { storageOk = false; }
try {
var raw = window.localStorage.getItem(STORE_KEY);
if (!raw) return;
var p = JSON.parse(raw);
if (p && typeof p === 'object') {
if (LEVEL_IDS.indexOf(p.level) >= 0) state.level = p.level;
if (Array.isArray(p.themes)) {
var list = p.themes.filter(function (t) { return THEME_IDS.indexOf(t) >= 0; });
state.themes = list.length ? list : null;
}
state.asked = p.asked === true;
}
} catch (e) { storageOk = false; }
}
function probeStorage() {
try {
window.localStorage.setItem('gastinel-probe', '1');
window.localStorage.removeItem('gastinel-probe');
} catch (e) { storageOk = false; }
}
function save() {
try {
window.localStorage.setItem(STORE_KEY, JSON.stringify({ level: state.level, themes: state.themes, asked: state.asked }));
window.localStorage.setItem(THEME_KEY, state.theme);
} catch (e) { storageOk = false; }
writeThemeCookie(state.theme);
try {
document.dispatchEvent(new CustomEvent('gastinel:prefs', { detail: { level: state.level, themes: state.themes } }));
} catch (e) { /* vieux navigateur : le composant relira le stockage au prochain chargement */ }
}
/* ---------- Petits outils DOM ---------- */
function el(tag, cls, text) {
var e = document.createElement(tag);
if (cls) e.className = cls;
if (text != null) e.textContent = text;
return e;
}
var SVGNS = 'http://www.w3.org/2000/svg';
function gear() {
var s = document.createElementNS(SVGNS, 'svg');
s.setAttribute('viewBox', '0 0 24 24');
s.setAttribute('aria-hidden', 'true');
s.setAttribute('focusable', 'false');
var p = document.createElementNS(SVGNS, 'path');
p.setAttribute('d', 'M19.14 12.94c.04-.3.06-.61.06-.94s-.02-.64-.07-.94l2.03-1.58a.49.49 0 0 0 .12-.61l-1.92-3.32a.49.49 0 0 0-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54a.484.484 0 0 0-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.05.3-.09.63-.09.94s.02.64.07.94l-2.03 1.58a.49.49 0 0 0-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6z');
s.appendChild(p);
return s;
}
var CSS = '' +
'.rg-btn{position:fixed;right:max(14px,env(safe-area-inset-right));bottom:max(14px,env(safe-area-inset-bottom));z-index:9500;width:46px;height:46px;padding:0;border-radius:50%;border:2px solid #242424;background:#fff;color:#242424;display:flex;align-items:center;justify-content:center;cursor:pointer;box-shadow:0 4px 14px rgba(0,0,0,.22);opacity:.88;transition:opacity .2s,background .2s,color .2s}' +
'.rg-foot{color:#fff;font:inherit;text-decoration:none;cursor:pointer}.rg-foot:hover{text-decoration:underline}.rg-foot:focus-visible{outline:2px solid #fff;outline-offset:2px}' +
'.rg-btn:hover,.rg-btn:focus-visible{opacity:1;background:#242424;color:#fff}' +
'.rg-btn:focus-visible{outline:3px solid #1e4d8b;outline-offset:3px}' +
'.rg-btn svg{width:24px;height:24px;fill:currentColor}' +
'.rg-veil{position:fixed;inset:0;z-index:9600;background:rgba(0,0,0,.4);display:flex;align-items:flex-end;justify-content:flex-end;padding:14px}' +
'.rg-veil[hidden]{display:none}' +
'.rg-dialog{background:#fff;color:#1a1d21;font:16px/1.5 var(--font-sans,Inter,system-ui,-apple-system,"Segoe UI",Roboto,Arial,sans-serif);width:380px;max-width:100%;max-height:calc(100vh - 28px);max-height:calc(100dvh - 28px);overflow-y:auto;border-radius:12px;border:2px solid #242424;box-shadow:0 12px 40px rgba(0,0,0,.35);padding:18px 20px 20px;box-sizing:border-box;text-align:left}' +
'.rg-dialog *{box-sizing:border-box}' +
'.rg-dialog:focus{outline:none}' +
'.rg-top{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:6px}' +
'.rg-h{font-size:1.25rem;font-weight:700;margin:0;line-height:1.3;color:#1a1d21;letter-spacing:0;text-transform:none}' +
'.rg-x{font:inherit;font-size:1.4rem;line-height:1;width:44px;height:44px;border-radius:50%;border:2px solid #242424;background:#fff;color:#242424;cursor:pointer;flex:none;padding:0}' +
'.rg-x:hover{background:#eceef1}' +
'.rg-sec{margin:14px 0 0;padding:14px 0 0;border:0;border-top:1px solid #e5e7eb;min-width:0}' +
'.rg-sec:first-of-type{border-top:0;padding-top:0}' +
'.rg-sh{font-size:1rem;font-weight:700;margin:0 0 8px;padding:0;color:#1a1d21;text-transform:none;letter-spacing:0}' +
'.rg-fs{border:0;margin:0 0 10px;padding:0;min-width:0}' +
'.rg-lg{font-size:.9rem;font-weight:700;color:#4b5563;padding:0;margin:0 0 4px}' +
'.rg-opt{display:flex;align-items:flex-start;gap:10px;padding:8px 6px;min-height:44px;border-radius:8px;cursor:pointer}' +
'.rg-opt:hover{background:#f3f4f6}' +
'.rg-opt input{width:20px;height:20px;margin:2px 0 0;flex:none;accent-color:#242424;cursor:pointer}' +
'.rg-opt input:focus-visible{outline:3px solid #1e4d8b;outline-offset:2px}' +
'.rg-opt span{display:block}.rg-opt small{display:block;color:#4b5563;font-size:.85rem;line-height:1.35}' +
'.rg-note{font-size:.85rem;color:#4b5563;margin:8px 0 0}' +
'.rg-warn{font-size:.85rem;color:#7a4b00;background:#fff4d6;border-left:4px solid #e0b100;padding:8px 10px;border-radius:4px;margin:8px 0 0}' +
'.rg-langs{list-style:none;margin:0;padding:0;display:flex;flex-wrap:wrap;gap:8px}' +
'.rg-langs a{display:inline-flex;align-items:center;min-height:44px;padding:8px 14px;border-radius:999px;border:2px solid #242424;color:#242424;background:#fff;text-decoration:none;font-weight:600;font-size:.95rem}' +
'.rg-langs a:hover{background:#eceef1}' +
'.rg-langs a[aria-current="true"]{background:#242424;color:#fff}' +
'.rg-langs a:focus-visible,.rg-link:focus-visible,.rg-act:focus-visible,.rg-x:focus-visible{outline:3px solid #1e4d8b;outline-offset:3px}' +
'.rg-link{display:inline-block;margin-top:8px;padding:8px 0;color:#1e4d8b;font-weight:600}' +
'.rg-actions{display:flex;flex-wrap:wrap;gap:10px;margin-top:16px}' +
'.rg-act{font:inherit;font-weight:700;min-height:44px;padding:9px 20px;border-radius:999px;border:2px solid #242424;background:#fff;color:#242424;cursor:pointer}' +
'.rg-act.rg-primary{background:#242424;color:#fff}' +
'@media(max-width:600px){.rg-veil{padding:0}.rg-dialog{width:100%;border-radius:14px 14px 0 0;max-height:88vh;max-height:88dvh;border-width:2px 0 0}}' +
'@media(prefers-reduced-motion:reduce){.rg-btn{transition:none}}' +
'@media print{.rg-btn,.rg-veil{display:none!important}}' +
'html.theme-sombre{filter:invert(.92) hue-rotate(180deg);background:#fff}' +
'html.theme-sombre img,html.theme-sombre video,html.theme-sombre iframe,html.theme-sombre picture,html.theme-sombre .rg-photo,html.theme-sombre [style*="background-image"],html.theme-sombre .leaflet-container{filter:invert(1) hue-rotate(180deg)}' +
'html.theme-sombre .global-footer,html.theme-sombre .actus-bouton-zone{filter:invert(1) hue-rotate(180deg)}';
/* ---------- Panneau ---------- */
var btn, veil, dialog, opener = null, mode = 'settings', built = false;
var levelInputs = {}, themeInputs = {}, allBtn = null, warnEl = null, noneEl = null;
function syncForm() {
LEVEL_IDS.forEach(function (id) { levelInputs[id].checked = state.level === id; });
THEME_IDS.forEach(function (id) { themeInputs[id].checked = !state.themes || state.themes.indexOf(id) >= 0; });
if (noneEl) noneEl.hidden = true;
}
function readThemes() {
var sel = THEME_IDS.filter(function (id) { return themeInputs[id].checked; });
if (sel.length === 0) { noneEl.hidden = false; state.themes = null; }
else { noneEl.hidden = true; state.themes = sel.length === THEME_IDS.length ? null : sel; }
}
function newsSection() {
var sec = el('section', 'rg-sec');
sec.setAttribute('aria-labelledby', 'rg-news-h');
var h = el('h3', 'rg-sh', L.newsH); h.id = 'rg-news-h';
sec.appendChild(h);
var fs1 = el('fieldset', 'rg-fs');
fs1.appendChild(el('legend', 'rg-lg', L.levelH));
LEVEL_IDS.forEach(function (id) {
var lab = el('label', 'rg-opt');
var inp = el('input'); inp.type = 'radio'; inp.name = 'rg-level'; inp.value = id;
inp.addEventListener('change', function () { if (inp.checked) { state.level = id; save(); } });
levelInputs[id] = inp;
var tx = el('span'); tx.appendChild(document.createTextNode(L.levels[id][0]));
tx.appendChild(el('small', null, L.levels[id][1]));
lab.appendChild(inp); lab.appendChild(tx);
fs1.appendChild(lab);
});
sec.appendChild(fs1);
var fs2 = el('fieldset', 'rg-fs');
fs2.appendChild(el('legend', 'rg-lg', L.themesH));
THEME_IDS.forEach(function (id, i) {
var lab = el('label', 'rg-opt');
var inp = el('input'); inp.type = 'checkbox'; inp.value = id;
inp.addEventListener('change', function () { readThemes(); save(); });
themeInputs[id] = inp;
lab.appendChild(inp); lab.appendChild(el('span', null, L.themes[i]));
fs2.appendChild(lab);
});
allBtn = el('button', 'rg-act', L.allThemes);
allBtn.type = 'button';
allBtn.addEventListener('click', function () {
state.themes = null; syncForm(); save();
});
fs2.appendChild(allBtn);
noneEl = el('p', 'rg-note', L.noneChecked); noneEl.hidden = true; noneEl.setAttribute('role', 'status');
fs2.appendChild(noneEl);
sec.appendChild(fs2);
sec.appendChild(el('p', 'rg-note', L.note));
warnEl = el('p', 'rg-warn', L.noStore); warnEl.hidden = storageOk; warnEl.setAttribute('role', 'status');
sec.appendChild(warnEl);
return sec;
}
/* Thème : clair par défaut, sombre seulement si la personne le choisit (proposition du 26/10). */
function applyTheme() {
document.documentElement.classList.toggle('theme-sombre', state.theme === 'sombre');
if (state.theme !== 'sombre') return;
/* Les photos posées en fond CSS (carrousel, bandeaux) sont remises à l'endroit. */
Array.prototype.forEach.call(document.querySelectorAll('body *'), function (e) {
if (e.classList.contains('rg-photo') || e.closest('.rg-photo')) return;
var bg = getComputedStyle(e).backgroundImage;
if (bg && bg.indexOf('url(') >= 0) e.classList.add('rg-photo');
});
}
function themeSection() {
var sec = el('section', 'rg-sec');
sec.setAttribute('aria-labelledby', 'rg-theme-h');
var h = el('h3', 'rg-sh', L.themeH); h.id = 'rg-theme-h';
sec.appendChild(h);
L.themes2.forEach(function (t) {
var lab = el('label', 'rg-opt');
var inp = el('input'); inp.type = 'radio'; inp.name = 'rg-theme'; inp.value = t[0];
inp.checked = state.theme === t[0];
inp.addEventListener('change', function () { if (inp.checked) { state.theme = t[0]; applyTheme(); save(); } });
var tx = el('span'); tx.appendChild(document.createTextNode(t[1])); tx.appendChild(el('small', null, t[2]));
lab.appendChild(inp); lab.appendChild(tx); sec.appendChild(lab);
});
return sec;
}
function langSection() {
var sec = el('section', 'rg-sec');
sec.setAttribute('aria-labelledby', 'rg-lang-h');
var h = el('h3', 'rg-sh', L.langH); h.id = 'rg-lang-h';
sec.appendChild(h);
var ul = el('ul', 'rg-langs');
LANGS.forEach(function (l) {
var li = el('li');
var a = el('a', null, l[2]);
a.href = l[1]; a.setAttribute('hreflang', l[0]); a.setAttribute('lang', l[0]);
if (l[0] === lang) a.setAttribute('aria-current', 'true');
li.appendChild(a); ul.appendChild(li);
});
sec.appendChild(ul);
if (L.frOnly) sec.appendChild(el('p', 'rg-note', L.frOnly));
if (!onNewsPage) {
var a2 = el('a', 'rg-link', L.newsLink); a2.href = '/news/';
if (lang !== 'fr') a2.setAttribute('lang', 'fr');
sec.appendChild(a2);
}
return sec;
}
function build() {
if (built) return;
built = true;
var st = el('style'); st.id = 'rg-css'; st.textContent = CSS; document.head.appendChild(st);
/* Page News : petit bouton rond en bas à droite. Ailleurs : lien texte dans le pied de page (demande de Théo, 26/10). */
var foot = onNewsPage ? null : document.querySelector('.footer-bottom');
if (foot) {
btn = el('a', 'rg-foot', L.foot);
btn.href = '#';
btn.setAttribute('role', 'button');
foot.appendChild(document.createTextNode(' | '));
foot.appendChild(btn);
btn.addEventListener('click', function (e) { e.preventDefault(); openPanel('settings', btn); });
} else {
btn = el('button', 'rg-btn');
btn.type = 'button';
btn.setAttribute('aria-label', L.btn);
btn.setAttribute('title', L.btn);
btn.appendChild(gear());
btn.addEventListener('click', function () { openPanel('settings', btn); });
document.body.appendChild(btn);
}
btn.setAttribute('aria-haspopup', 'dialog');
btn.setAttribute('aria-expanded', 'false');
veil = el('div', 'rg-veil'); veil.hidden = true;
veil.addEventListener('mousedown', function (e) { if (e.target === veil) closePanel(); });
dialog = el('div', 'rg-dialog');
dialog.setAttribute('role', 'dialog');
dialog.setAttribute('aria-modal', 'true');
dialog.setAttribute('aria-labelledby', 'rg-title');
dialog.tabIndex = -1;
veil.appendChild(dialog);
document.body.appendChild(veil);
}
/* (Re)construit le contenu du panneau selon le mode : « settings » ou « invite ». */
function fill() {
dialog.textContent = '';
levelInputs = {}; themeInputs = {};
var top = el('div', 'rg-top');
var h = el('h2', 'rg-h', mode === 'invite' ? L.inviteTitle : (onNewsPage ? L.title : L.foot)); h.id = 'rg-title';
top.appendChild(h);
var x = el('button', 'rg-x'); x.type = 'button'; x.setAttribute('aria-label', L.close); x.textContent = '×';
x.addEventListener('click', closePanel);
top.appendChild(x);
dialog.appendChild(top);
if (mode === 'invite') dialog.appendChild(el('p', 'rg-note', L.inviteIntro));
if (onNewsPage || mode === 'invite') dialog.appendChild(newsSection());
if (mode === 'invite') {
var act = el('div', 'rg-actions');
var ok = el('button', 'rg-act rg-primary', L.ok); ok.type = 'button';
ok.addEventListener('click', closePanel);
var later = el('button', 'rg-act', L.later); later.type = 'button';
later.addEventListener('click', closePanel);
act.appendChild(ok); act.appendChild(later);
dialog.appendChild(act);
} else {
dialog.appendChild(themeSection());
/* Sites sans traductions (ex. statistiques) : <html data-reglages="theme"> = thème seulement. */
if (document.documentElement.getAttribute('data-reglages') !== 'theme') dialog.appendChild(langSection());
}
if (onNewsPage || mode === 'invite') syncForm();
}
function focusables() {
var nodes = dialog.querySelectorAll('a[href],button:not([disabled]),input:not([disabled])');
return Array.prototype.filter.call(nodes, function (n) { return n.offsetParent !== null || n === document.activeElement; });
}
function onKey(e) {
if (veil.hidden) return;
if (e.key === 'Escape' || e.key === 'Esc') { e.preventDefault(); closePanel(); return; }
if (e.key !== 'Tab') return;
var f = focusables();
if (!f.length) { e.preventDefault(); dialog.focus(); return; }
var first = f[0], last = f[f.length - 1], a = document.activeElement;
if (!dialog.contains(a)) { e.preventDefault(); first.focus(); }
else if (e.shiftKey && (a === first || a === dialog)) { e.preventDefault(); last.focus(); }
else if (!e.shiftKey && a === last) { e.preventDefault(); first.focus(); }
}
function openPanel(m, from) {
build();
if (!veil.hidden) return;
mode = m;
opener = from || document.activeElement;
fill();
veil.hidden = false;
btn.setAttribute('aria-expanded', 'true');
var target = levelInputs[state.level] || dialog.querySelector('input:checked') || dialog;
target.focus();
document.addEventListener('keydown', onKey, true);
}
function closePanel() {
if (veil.hidden) return;
var wasInvite = mode === 'invite';
veil.hidden = true;
btn.setAttribute('aria-expanded', 'false');
document.removeEventListener('keydown', onKey, true);
if (wasInvite || !state.asked) { state.asked = true; save(); }
var back = opener && opener !== document.body && document.contains(opener) ? opener : btn;
try { back.focus(); } catch (e) { /* rien */ }
opener = null;
}
/* Le composant News peut demander l'ouverture (bouton « Changer mon flux »). */
document.addEventListener('gastinel:open-reglages', function () { build(); openPanel('settings', document.activeElement); });
function start() {
probeStorage();
load();
applyTheme();
window.addEventListener('load', applyTheme);
build();
if (onNewsPage && storageOk && !state.asked) {
/* première visite de /news/ : l'invite s'ouvre une fois, puis se range */
openPanel('invite', null);
}
}
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', start); else start();
})();