feat: design system, layout e componenti di base
- token, font self-hosted (Fraunces e Inter, sottoinsieme latin) con preload - BaseLayout con head completo (SEO, Open Graph, favicon) e JSON-LD dello studio - intestazione con barra superiore, navigazione e sottomenu servizi accessibili - menu mobile con dialog modale e alternativa senza JavaScript - footer con P.IVA, recapiti, servizi, orari e link legali - componenti: Logo, Icon (Lucide inline), Hero, card servizio, scheda professionista, badge abilitazione, card sede, mappa click-to-load, modulo di contatto, banda CTA, breadcrumb, intestazioni di sezione - generate-icons.mjs: marchio, favicon, apple-touch-icon e immagine OG - collection dei servizi e dei link utili con schemi Zod Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016zJ9ZWGKvoKoxYwbmnRKdJ
This commit is contained in:
58 files changed
+5077
-16
No files matched your search
@@ -0,0 +1,132 @@
|
||||
/**
|
||||
* Miglioramento del modulo di contatto: messaggi di validazione in italiano accanto ai campi,
|
||||
* riepilogo degli errori annunciato agli screen reader, campo `ts` con l'ora di apertura della
|
||||
* pagina e blocco degli invii troppo rapidi (anti-spam senza cookie). Senza JavaScript il modulo
|
||||
* usa la validazione nativa del browser.
|
||||
*/
|
||||
|
||||
const MESSAGES = {
|
||||
required: 'Compila questo campo.',
|
||||
email: 'Inserisci un indirizzo e-mail valido (es. nome@esempio.it).',
|
||||
tel: 'Inserisci un numero di telefono valido (solo cifre, spazi e +).',
|
||||
short: 'Il testo è troppo breve.',
|
||||
consent: 'Per inviare la richiesta devi accettare l’informativa sulla privacy.',
|
||||
tooFast: 'Attendi qualche secondo prima di inviare il modulo.',
|
||||
};
|
||||
|
||||
type Field = HTMLInputElement | HTMLTextAreaElement;
|
||||
|
||||
function messageFor(field: Field): string | null {
|
||||
const v = field.validity;
|
||||
if (v.valid) return null;
|
||||
if (field instanceof HTMLInputElement && field.type === 'checkbox') return MESSAGES.consent;
|
||||
if (v.valueMissing) return MESSAGES.required;
|
||||
if (v.typeMismatch && field.type === 'email') return MESSAGES.email;
|
||||
if (field.type === 'tel' && (v.patternMismatch || v.tooShort || v.tooLong)) return MESSAGES.tel;
|
||||
if (v.tooShort) return MESSAGES.short;
|
||||
return field.validationMessage || MESSAGES.required;
|
||||
}
|
||||
|
||||
function labelText(form: HTMLFormElement, field: Field): string {
|
||||
const label = form.querySelector<HTMLLabelElement>(`label[for="${field.id}"]`);
|
||||
return (label?.textContent ?? field.name).replace('*', '').replace(/\s+/g, ' ').trim();
|
||||
}
|
||||
|
||||
function showError(field: Field, message: string | null): void {
|
||||
const error = document.getElementById(`${field.id}-err`);
|
||||
if (message) {
|
||||
field.setAttribute('aria-invalid', 'true');
|
||||
if (error) {
|
||||
error.textContent = message;
|
||||
error.hidden = false;
|
||||
}
|
||||
} else {
|
||||
field.removeAttribute('aria-invalid');
|
||||
if (error) {
|
||||
error.textContent = '';
|
||||
error.hidden = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function init(form: HTMLFormElement): void {
|
||||
const loadedAt = Date.now();
|
||||
const minMs = Number(form.dataset.minSeconds ?? '3') * 1000;
|
||||
const ts = form.querySelector<HTMLInputElement>('[data-form-ts]');
|
||||
if (ts) ts.value = String(loadedAt);
|
||||
|
||||
const summary = form.querySelector<HTMLElement>('[data-form-summary]');
|
||||
const summaryList = form.querySelector<HTMLElement>('[data-form-summary-list]');
|
||||
const status = form.querySelector<HTMLElement>('[data-form-status]');
|
||||
const fields = Array.from(
|
||||
form.querySelectorAll<Field>('input[required], textarea[required]'),
|
||||
).filter((f) => f.type !== 'hidden');
|
||||
|
||||
// Da qui in poi la validazione è gestita dallo script (messaggi in italiano).
|
||||
form.noValidate = true;
|
||||
|
||||
for (const field of fields) {
|
||||
const event = field.type === 'checkbox' ? 'change' : 'blur';
|
||||
field.addEventListener(event, () => {
|
||||
if (field.getAttribute('aria-invalid') === 'true' || field.value !== '') {
|
||||
showError(field, messageFor(field));
|
||||
}
|
||||
});
|
||||
field.addEventListener('input', () => {
|
||||
if (field.getAttribute('aria-invalid') === 'true') showError(field, messageFor(field));
|
||||
});
|
||||
}
|
||||
|
||||
form.addEventListener('submit', (event) => {
|
||||
const invalid: { field: Field; message: string }[] = [];
|
||||
for (const field of fields) {
|
||||
const message = messageFor(field);
|
||||
showError(field, message);
|
||||
if (message) invalid.push({ field, message });
|
||||
}
|
||||
|
||||
if (invalid.length > 0) {
|
||||
event.preventDefault();
|
||||
if (summary && summaryList) {
|
||||
summaryList.replaceChildren(
|
||||
...invalid.map(({ field, message }) => {
|
||||
const li = document.createElement('li');
|
||||
const a = document.createElement('a');
|
||||
a.href = `#${field.id}`;
|
||||
a.textContent = `${labelText(form, field)}: ${message}`;
|
||||
a.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
field.focus();
|
||||
});
|
||||
li.append(a);
|
||||
return li;
|
||||
}),
|
||||
);
|
||||
summary.hidden = false;
|
||||
summary.focus();
|
||||
}
|
||||
if (status) {
|
||||
status.textContent = `Il modulo contiene ${invalid.length} ${
|
||||
invalid.length === 1 ? 'errore' : 'errori'
|
||||
}.`;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (summary) summary.hidden = true;
|
||||
|
||||
if (Date.now() - loadedAt < minMs) {
|
||||
event.preventDefault();
|
||||
if (status) status.textContent = MESSAGES.tooFast;
|
||||
return;
|
||||
}
|
||||
|
||||
if (status) status.textContent = 'Invio in corso…';
|
||||
});
|
||||
}
|
||||
|
||||
for (const form of document.querySelectorAll<HTMLFormElement>('form[data-contact-form]')) {
|
||||
init(form);
|
||||
}
|
||||
|
||||
export {};
|
||||
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Continuità con il vecchio sito (brief §5.3): i link del tipo /servizi#contenzioso-tributario-3
|
||||
* atterrano già sulla card giusta (stesso `id`); con JavaScript il visitatore viene portato
|
||||
* direttamente alla pagina di dettaglio del servizio.
|
||||
*/
|
||||
|
||||
function redirectLegacyAnchor(): void {
|
||||
const hash = window.location.hash.slice(1);
|
||||
if (!hash) return;
|
||||
let id: string;
|
||||
try {
|
||||
id = decodeURIComponent(hash);
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
const target = document.getElementById(id);
|
||||
const href = target?.dataset.legacyHref;
|
||||
if (href && href.startsWith('/servizi/')) window.location.replace(href);
|
||||
}
|
||||
|
||||
redirectLegacyAnchor();
|
||||
window.addEventListener('hashchange', redirectLegacyAnchor);
|
||||
|
||||
export {};
|
||||
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* Mappe Google caricate solo dopo il consenso esplicito (clic su «Carica la mappa»).
|
||||
* Nessun cookie: la scelta è ricordata in sessionStorage (dato tecnico, nessun dato personale)
|
||||
* e vale fino alla chiusura della scheda.
|
||||
*/
|
||||
|
||||
const STORAGE_KEY = 'mappa-consentita';
|
||||
|
||||
function rememberConsent(): void {
|
||||
try {
|
||||
sessionStorage.setItem(STORAGE_KEY, '1');
|
||||
} catch {
|
||||
// sessionStorage non disponibile (es. navigazione privata restrittiva): nessun problema.
|
||||
}
|
||||
}
|
||||
|
||||
function hasConsent(): boolean {
|
||||
try {
|
||||
return sessionStorage.getItem(STORAGE_KEY) === '1';
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function loadMap(block: HTMLElement, moveFocus: boolean): void {
|
||||
if (block.dataset.mapLoaded === 'true') return;
|
||||
const src = block.dataset.mapSrc;
|
||||
const frame = block.querySelector<HTMLElement>('[data-map-frame]');
|
||||
const placeholder = block.querySelector<HTMLElement>('[data-map-placeholder]');
|
||||
if (!src || !frame || !placeholder) return;
|
||||
|
||||
const iframe = document.createElement('iframe');
|
||||
iframe.src = src;
|
||||
iframe.title = block.dataset.mapTitle ?? 'Mappa';
|
||||
iframe.loading = 'lazy';
|
||||
iframe.referrerPolicy = 'strict-origin-when-cross-origin';
|
||||
iframe.allowFullscreen = true;
|
||||
|
||||
frame.append(iframe);
|
||||
frame.hidden = false;
|
||||
placeholder.hidden = true;
|
||||
block.dataset.mapLoaded = 'true';
|
||||
if (moveFocus) iframe.focus();
|
||||
}
|
||||
|
||||
function init(): void {
|
||||
const blocks = Array.from(document.querySelectorAll<HTMLElement>('[data-map-consent]'));
|
||||
if (blocks.length === 0) return;
|
||||
|
||||
for (const block of blocks) {
|
||||
const button = block.querySelector<HTMLButtonElement>('[data-map-load]');
|
||||
button?.addEventListener('click', () => {
|
||||
rememberConsent();
|
||||
loadMap(block, true);
|
||||
});
|
||||
}
|
||||
|
||||
if (hasConsent()) for (const block of blocks) loadMap(block, false);
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
export {};
|
||||
@@ -0,0 +1,87 @@
|
||||
/**
|
||||
* Menu mobile e sottomenu (miglioramento progressivo: senza JavaScript la navigazione
|
||||
* funziona comunque, vedi BaseLayout e MobileMenu).
|
||||
*
|
||||
* - Menu mobile: <dialog> modale aperto con `showModal()`; Esc e il pulsante «Chiudi» lo
|
||||
* chiudono; il focus passa al pulsante di chiusura e, alla chiusura, torna al pulsante menu.
|
||||
* - Sottomenu: pulsanti con `aria-expanded`; Esc chiude il sottomenu aperto e riporta il focus
|
||||
* sul pulsante; un clic all'esterno o l'uscita del focus chiudono il sottomenu desktop.
|
||||
*/
|
||||
|
||||
function setExpanded(toggle: HTMLElement, open: boolean): void {
|
||||
toggle.setAttribute('aria-expanded', String(open));
|
||||
}
|
||||
|
||||
function initMobileMenu(): void {
|
||||
const dialog = document.querySelector<HTMLDialogElement>('dialog[data-menu]');
|
||||
const openButton = document.querySelector<HTMLButtonElement>('[data-menu-open]');
|
||||
if (!dialog || !openButton || typeof dialog.showModal !== 'function') return;
|
||||
const closeButton = dialog.querySelector<HTMLButtonElement>('[data-menu-close]');
|
||||
|
||||
openButton.addEventListener('click', () => {
|
||||
if (dialog.open) return;
|
||||
dialog.showModal();
|
||||
setExpanded(openButton, true);
|
||||
closeButton?.focus();
|
||||
});
|
||||
|
||||
closeButton?.addEventListener('click', () => dialog.close());
|
||||
|
||||
dialog.addEventListener('close', () => {
|
||||
setExpanded(openButton, false);
|
||||
openButton.focus();
|
||||
});
|
||||
|
||||
// Se la finestra diventa larga (rotazione, ridimensionamento) il menu mobile si chiude.
|
||||
const desktop = window.matchMedia('(min-width: 960.02px)');
|
||||
desktop.addEventListener('change', (event) => {
|
||||
if (event.matches && dialog.open) dialog.close();
|
||||
});
|
||||
}
|
||||
|
||||
function initSubmenus(): void {
|
||||
const toggles = Array.from(document.querySelectorAll<HTMLButtonElement>('[data-submenu-toggle]'));
|
||||
if (toggles.length === 0) return;
|
||||
|
||||
const closeAll = (except?: HTMLButtonElement) => {
|
||||
for (const t of toggles) if (t !== except) setExpanded(t, false);
|
||||
};
|
||||
|
||||
for (const toggle of toggles) {
|
||||
toggle.addEventListener('click', () => {
|
||||
const open = toggle.getAttribute('aria-expanded') !== 'true';
|
||||
closeAll(toggle);
|
||||
setExpanded(toggle, open);
|
||||
});
|
||||
|
||||
// Sottomenu desktop: si chiude quando il focus esce dalla voce.
|
||||
const item = toggle.closest<HTMLElement>('[data-submenu]');
|
||||
item?.addEventListener('focusout', (event) => {
|
||||
const next = event.relatedTarget as Node | null;
|
||||
if (!next || !item.contains(next)) setExpanded(toggle, false);
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener('keydown', (event) => {
|
||||
if (event.key !== 'Escape') return;
|
||||
const open = toggles.find(
|
||||
(t) => t.getAttribute('aria-expanded') === 'true' && !t.closest('dialog'),
|
||||
);
|
||||
if (!open) return;
|
||||
setExpanded(open, false);
|
||||
open.focus();
|
||||
});
|
||||
|
||||
document.addEventListener('click', (event) => {
|
||||
const target = event.target as Node;
|
||||
for (const t of toggles) {
|
||||
const item = t.closest('[data-submenu]');
|
||||
if (item && !item.contains(target)) setExpanded(t, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
initMobileMenu();
|
||||
initSubmenus();
|
||||
|
||||
export {};
|
||||
Reference in new issue
Block a user