Aggiunge menu lingua dropdown e base i18n IT/EN/TH.
Introduce routing multilingua con locale tailandese, selettore lingua a tendina con icone bandiera SVG e gestione chiusura click-outside/Esc, oltre a integrazione Turnstile lato form contatti. Made-with: Cursor
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
interface ContactFormCfg {
|
||||
actionUrl: string;
|
||||
mailto: string;
|
||||
turnstileSiteKey: string;
|
||||
notifySubject: string;
|
||||
successRedirect: string;
|
||||
fieldName: string;
|
||||
@ -18,6 +19,7 @@ function readCfg(): ContactFormCfg {
|
||||
return {
|
||||
actionUrl: '',
|
||||
mailto: '',
|
||||
turnstileSiteKey: '',
|
||||
notifySubject: '',
|
||||
successRedirect: '',
|
||||
fieldName: 'name',
|
||||
@ -39,6 +41,23 @@ function bind(): void {
|
||||
const err = document.getElementById('nx-contact-form-error');
|
||||
if (err) err.classList.add('hidden');
|
||||
|
||||
const hasTurnstile =
|
||||
typeof cfg.turnstileSiteKey === 'string' && cfg.turnstileSiteKey.length > 0;
|
||||
if (cfg.actionUrl && hasTurnstile) {
|
||||
const token = form.querySelector<HTMLInputElement>(
|
||||
'input[name="cf-turnstile-response"]',
|
||||
)?.value;
|
||||
if (!token) {
|
||||
e.preventDefault();
|
||||
if (err) {
|
||||
err.textContent =
|
||||
'Completa il controllo anti-spam prima di inviare il messaggio.';
|
||||
err.classList.remove('hidden');
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (cfg.actionUrl) {
|
||||
return;
|
||||
}
|
||||
|
||||
32
src/scripts/nx-lang-dropdown.ts
Normal file
32
src/scripts/nx-lang-dropdown.ts
Normal file
@ -0,0 +1,32 @@
|
||||
function bindLanguageDropdown(): void {
|
||||
const dropdowns = Array.from(
|
||||
document.querySelectorAll<HTMLDetailsElement>('details[data-lang-dropdown]'),
|
||||
);
|
||||
if (!dropdowns.length) return;
|
||||
|
||||
document.addEventListener('click', (event) => {
|
||||
const target = event.target as Node | null;
|
||||
dropdowns.forEach((dd) => {
|
||||
if (!dd.open) return;
|
||||
if (target && dd.contains(target)) return;
|
||||
dd.open = false;
|
||||
});
|
||||
});
|
||||
|
||||
document.addEventListener('keydown', (event) => {
|
||||
if (event.key !== 'Escape') return;
|
||||
dropdowns.forEach((dd) => {
|
||||
dd.open = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof document !== 'undefined') {
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', bindLanguageDropdown, {
|
||||
once: true,
|
||||
});
|
||||
} else {
|
||||
bindLanguageDropdown();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user