Huurbaken website — Marstark 24-Hour Build Challenge (bilingual NL/EN)
This commit is contained in:
@@ -0,0 +1,484 @@
|
||||
/* ============================================================
|
||||
Huurbaken — script.js
|
||||
Language switcher (NL/EN), mobile menu, FAQ accordion,
|
||||
lead-form validation with success state.
|
||||
No backend: the form is a demo and stores nothing.
|
||||
============================================================ */
|
||||
|
||||
"use strict";
|
||||
|
||||
/* ---------------- i18n dictionaries ---------------- */
|
||||
const I18N = {
|
||||
nl: {
|
||||
"meta.title": "Huurbaken — Verkoop uw verhuurde pand direct",
|
||||
"meta.description": "Huurbaken koopt verhuurde woningen en gebouwen rechtstreeks van eigenaren. Binnen 48 uur een vrijblijvend bod, zonder makelaarskosten.",
|
||||
"a11y.skip": "Direct naar het aanvraagformulier",
|
||||
"nav.how": "Hoe het werkt",
|
||||
"nav.why": "Waarom Huurbaken",
|
||||
"nav.types": "Wat wij kopen",
|
||||
"nav.faq": "Veelgestelde vragen",
|
||||
"nav.contact": "Contact",
|
||||
"nav.cta": "Ontvang een bod",
|
||||
"hero.badge": "Directe aankoop van verhuurd vastgoed",
|
||||
"hero.title": "Verkoop uw verhuurde pand direct — zonder bezichtigingen, zonder wachten.",
|
||||
"hero.sub": "Huurbaken koopt verhuurde woningen en gebouwen rechtstreeks van eigenaren. Binnen 48 uur een eerlijk, vrijblijvend bod. Geen makelaarskosten — en uw huurders blijven gewoon wonen.",
|
||||
"hero.cta1": "Ontvang een gratis bod",
|
||||
"hero.cta2": "Zo werkt het",
|
||||
"hero.trust1": "Bod binnen 48 uur",
|
||||
"hero.trust2": "Geen makelaarskosten",
|
||||
"hero.trust3": "Huurders blijven wonen",
|
||||
"hero.imgAlt": "Moderne woning",
|
||||
"hero.cardLabel": "Eerste bod binnen",
|
||||
"hero.cardUnit": "uur",
|
||||
"hero.cardNote": "Vrijblijvend & gratis",
|
||||
"how.eyebrow": "Het proces",
|
||||
"how.title": "Zo werkt het",
|
||||
"how.sub": "Van eerste contact tot uitbetaling in vier duidelijke stappen.",
|
||||
"how.s1t": "Laat uw gegevens achter",
|
||||
"how.s1d": "Vul het formulier in — binnen twee minuten gedaan. Wij nemen binnen één werkdag contact met u op.",
|
||||
"how.s2t": "Ontvang een vrijblijvend bod",
|
||||
"how.s2d": "Binnen 48 uur ontvangt u een eerlijk bod op basis van huurinkomsten, locatie en staat van het pand.",
|
||||
"how.s3t": "Wij regelen alles",
|
||||
"how.s3d": "Taxatie, huurders, administratie en papierwerk: wij nemen het u volledig uit handen.",
|
||||
"how.s4t": "Notaris en uitbetaling",
|
||||
"how.s4d": "Na uw akkoord regelen wij de notaris. Het bedrag staat snel op uw rekening.",
|
||||
"why.eyebrow": "Waarom Huurbaken",
|
||||
"why.title": "Waarom verkopen aan Huurbaken?",
|
||||
"why.sub": "Verkopen zonder gedoe — met zekerheid en een eerlijke prijs.",
|
||||
"why.imgAlt": "Interieur van een woning",
|
||||
"why.c1t": "Geen bezichtigingen",
|
||||
"why.c1d": "Geen vreemden over de vloer en geen open huizen. Uw huurders worden niet gestoord.",
|
||||
"why.c2t": "Geen makelaarskosten",
|
||||
"why.c2d": "U betaalt geen courtage en geen verkoopkosten. Het bod is het bedrag dat u ontvangt.",
|
||||
"why.c3t": "Huurders blijven wonen",
|
||||
"why.c3d": "Wij nemen de huurovereenkomsten over zoals ze zijn. Niemand hoeft te verhuizen.",
|
||||
"why.c4t": "Snel zekerheid",
|
||||
"why.c4d": "Binnen 48 uur weet u waar u aan toe bent — geen maanden wachten op een koper.",
|
||||
"why.c5t": "Wij kopen zoals het is",
|
||||
"why.c5d": "Renoveren hoeft niet. Ook panden met achterstallig onderhoud nemen wij over.",
|
||||
"why.c6t": "Discreet en persoonlijk",
|
||||
"why.c6d": "Eén vast aanspreekpunt, geen veiling en geen openbare verkoop.",
|
||||
"types.eyebrow": "Ons aanbod",
|
||||
"types.title": "Wat wij kopen",
|
||||
"types.sub": "Verhuurde panden in heel Duitsland — van één appartement tot een compleet complex.",
|
||||
"types.t1img": "Appartementencomplex",
|
||||
"types.t1t": "Verhuurde appartementen",
|
||||
"types.t1d": "Eén of meerdere appartementen, bewoond of leegstaand.",
|
||||
"types.t2img": "Verhuurde woning",
|
||||
"types.t2t": "Verhuurde woningen",
|
||||
"types.t2d": "Eengezinswoningen en herenhuizen met lopende huur.",
|
||||
"types.t3img": "Appartementencomplex",
|
||||
"types.t3t": "Appartementencomplexen",
|
||||
"types.t3d": "Complete complexen met meerdere eenheden en huurders.",
|
||||
"types.t4img": "Gemengd gebouw",
|
||||
"types.t4t": "Gemengd gebruik",
|
||||
"types.t4d": "Combinaties van wonen en werken, winkels of kantoren.",
|
||||
"value.eyebrow": "Eerste indicatie",
|
||||
"value.title": "Wat zou uw pand waard kunnen zijn?",
|
||||
"value.sub": "Een eerste indicatie op basis van huurinkomsten. De cijfers hieronder zijn fictieve voorbeelden (testdata).",
|
||||
"value.note": "Elk pand is anders. Uw definitieve bod volgt na een korte beoordeling — altijd vrijblijvend.",
|
||||
"value.col1": "Type pand",
|
||||
"value.col2": "Huur per maand",
|
||||
"value.col3": "Indicatie",
|
||||
"value.r1c1": "Verhuurd appartement",
|
||||
"value.r2c1": "Verhuurde woning",
|
||||
"value.r3c1": "Appartementencomplex (8 eenheden)",
|
||||
"value.testdata": "Fictieve voorbeeldcijfers — testdata",
|
||||
"testi.eyebrow": "Ervaringen",
|
||||
"testi.title": "Wat eigenaren zeggen",
|
||||
"testi.sub": "Fictieve citaten — testdata.",
|
||||
"testi.q1": "“Binnen drie dagen hadden we een bod op tafel. Geen bezichtigingen, geen gedoe — en onze huurders konden gewoon blijven.”",
|
||||
"testi.a1n": "Marleen V.",
|
||||
"testi.a1r": "Eigenaar van twee verhuurde appartementen",
|
||||
"testi.q2": "“Na het overlijden van mijn vader wilde ik het verhuurde huis snel en netjes verkopen. Huurbaken regelde alles, inclusief de huurder.”",
|
||||
"testi.a2n": "Johan D.",
|
||||
"testi.a2r": "Erfgenaam van een verhuurde woning",
|
||||
"testi.q3": "“Eindelijk een koper die begrijpt dat huurders mensen zijn. De afhandeling was snel, helder en discreet.”",
|
||||
"testi.a3n": "Samira E.",
|
||||
"testi.a3r": "Eigenaar van een appartementencomplex",
|
||||
"faq.eyebrow": "Vragen & antwoorden",
|
||||
"faq.title": "Veelgestelde vragen",
|
||||
"faq.q1": "Moet ik mijn huurders uitzetten?",
|
||||
"faq.a1": "Nee. Wij nemen de bestaande huurovereenkomsten over zoals ze zijn. Uw huurders blijven gewoon wonen en merken weinig van de verkoop.",
|
||||
"faq.q2": "Hoe snel ontvang ik een bod?",
|
||||
"faq.a2": "Binnen 48 uur na uw aanvraag ontvangt u een eerste, vrijblijvend bod — op werkdagen vaak nog sneller.",
|
||||
"faq.q3": "Zijn er kosten aan verbonden?",
|
||||
"faq.a3": "Nee. U betaalt geen makelaarskosten en geen verkoopcommissie. Ook de taxatie- en notariskosten nemen wij voor onze rekening.",
|
||||
"faq.q4": "Welke documenten heb ik nodig?",
|
||||
"faq.a4": "In eerste instantie alleen de basis: huurinkomsten, adres en type pand. Later vragen wij om de huurovereenkomst en, indien beschikbaar, het WOZ- of taxatierapport.",
|
||||
"faq.q5": "Welke panden kopen jullie?",
|
||||
"faq.a5": "Verhuurde appartementen, woningen, appartementencomplexen en gemengd gebruik — in heel Duitsland, in elke staat van onderhoud.",
|
||||
"faq.q6": "Is het bod bindend?",
|
||||
"faq.a6": "Nee. Ons bod is altijd vrijblijvend. U beslist in alle rust of u wilt verkopen — zonder druk en zonder verplichtingen.",
|
||||
"form.eyebrow": "Gratis & vrijblijvend",
|
||||
"form.title": "Ontvang uw gratis, vrijblijvende bod",
|
||||
"form.sub": "Vul het formulier in — wij nemen binnen één werkdag contact met u op.",
|
||||
"form.p1": "Bod binnen 48 uur",
|
||||
"form.p2": "Geen makelaarskosten",
|
||||
"form.p3": "Huurders blijven wonen",
|
||||
"form.demoNote": "Demoformulier: er worden geen gegevens verzonden of opgeslagen.",
|
||||
"form.f_name": "Naam *",
|
||||
"form.ph_name": "Bijv. Anna Jansen",
|
||||
"form.f_email": "E-mailadres *",
|
||||
"form.ph_email": "naam@voorbeeld.nl",
|
||||
"form.f_phone": "Telefoonnummer *",
|
||||
"form.ph_phone": "+31 6 12345678",
|
||||
"form.f_type": "Type pand *",
|
||||
"form.type_ph": "Kies een type",
|
||||
"form.type1": "Verhuurd appartement",
|
||||
"form.type2": "Verhuurde woning",
|
||||
"form.type3": "Appartementencomplex",
|
||||
"form.type4": "Gemengd gebruik",
|
||||
"form.type5": "Anders",
|
||||
"form.f_city": "Plaats en adres *",
|
||||
"form.ph_city": "Plaats, straat + huisnummer",
|
||||
"form.f_rent": "Maandelijkse huur (optioneel)",
|
||||
"form.ph_rent": "Bijv. 1.250",
|
||||
"form.f_msg": "Bericht",
|
||||
"form.ph_msg": "Vertel kort iets over uw pand…",
|
||||
"form.submit": "Vraag een bod aan",
|
||||
"form.privacy": "Uw gegevens gebruiken wij alleen om contact met u op te nemen.",
|
||||
"form.success_title": "Bedankt voor uw aanvraag!",
|
||||
"form.success_text": "Wij nemen binnen één werkdag contact met u op met een eerste indicatie.",
|
||||
"form.demoNote2": "Demoformulier: er worden geen gegevens verzonden of opgeslagen.",
|
||||
"form.again": "Nieuwe aanvraag doen",
|
||||
"footer.tagline": "Huurbaken koopt verhuurde woningen en gebouwen rechtstreeks van eigenaren — snel, eerlijk en discreet.",
|
||||
"footer.navTitle": "Navigatie",
|
||||
"footer.contactTitle": "Contact",
|
||||
"footer.langNote": "Deze website is beschikbaar in het Nederlands en Engels.",
|
||||
"footer.demo": "Huurbaken is een fictief bedrijf. Deze website is een demo met testdata, gemaakt voor de Marstark Build Challenge.",
|
||||
"footer.rights": "© 2026 Huurbaken — fictieve demo-website",
|
||||
"err.required": "Dit veld is verplicht.",
|
||||
"err.email": "Vul een geldig e-mailadres in.",
|
||||
"err.phone": "Vul een geldig telefoonnummer in.",
|
||||
"menu.open": "Menu openen",
|
||||
"menu.close": "Menu sluiten"
|
||||
},
|
||||
en: {
|
||||
"meta.title": "Huurbaken — Sell your rented property directly",
|
||||
"meta.description": "Huurbaken buys rented homes and buildings directly from owners. A non-binding offer within 48 hours, no estate-agent fees.",
|
||||
"a11y.skip": "Skip to the request form",
|
||||
"nav.how": "How it works",
|
||||
"nav.why": "Why Huurbaken",
|
||||
"nav.types": "What we buy",
|
||||
"nav.faq": "FAQ",
|
||||
"nav.contact": "Contact",
|
||||
"nav.cta": "Get an offer",
|
||||
"hero.badge": "Direct purchase of rented property",
|
||||
"hero.title": "Sell your rented property directly — no viewings, no waiting.",
|
||||
"hero.sub": "Huurbaken buys rented homes and buildings directly from owners. A fair, non-binding offer within 48 hours. No estate-agent fees — and your tenants simply stay.",
|
||||
"hero.cta1": "Get a free offer",
|
||||
"hero.cta2": "How it works",
|
||||
"hero.trust1": "Offer within 48 hours",
|
||||
"hero.trust2": "No estate-agent fees",
|
||||
"hero.trust3": "Tenants stay put",
|
||||
"hero.imgAlt": "Modern house",
|
||||
"hero.cardLabel": "First offer within",
|
||||
"hero.cardUnit": "hours",
|
||||
"hero.cardNote": "Non-binding & free",
|
||||
"how.eyebrow": "The process",
|
||||
"how.title": "How it works",
|
||||
"how.sub": "From first contact to payment in four clear steps.",
|
||||
"how.s1t": "Leave your details",
|
||||
"how.s1d": "Fill in the form — done in two minutes. We will contact you within one working day.",
|
||||
"how.s2t": "Receive a non-binding offer",
|
||||
"how.s2d": "Within 48 hours you receive a fair offer based on rental income, location and the condition of the property.",
|
||||
"how.s3t": "We handle everything",
|
||||
"how.s3d": "Valuation, tenants, administration and paperwork: we take it all off your hands.",
|
||||
"how.s4t": "Notary and payment",
|
||||
"how.s4d": "Once you agree, we arrange the notary. The money is in your account quickly.",
|
||||
"why.eyebrow": "Why Huurbaken",
|
||||
"why.title": "Why sell to Huurbaken?",
|
||||
"why.sub": "Sell without the hassle — with certainty and a fair price.",
|
||||
"why.imgAlt": "Interior of a home",
|
||||
"why.c1t": "No viewings",
|
||||
"why.c1d": "No strangers through the house and no open-house days. Your tenants are not disturbed.",
|
||||
"why.c2t": "No agent fees",
|
||||
"why.c2d": "You pay no commission and no selling costs. The offer is the amount you receive.",
|
||||
"why.c3t": "Tenants stay put",
|
||||
"why.c3d": "We take over the tenancy agreements as they are. Nobody has to move.",
|
||||
"why.c4t": "Fast certainty",
|
||||
"why.c4d": "Within 48 hours you know where you stand — no months of waiting for a buyer.",
|
||||
"why.c5t": "We buy as-is",
|
||||
"why.c5d": "No renovation needed. We also take on properties with a maintenance backlog.",
|
||||
"why.c6t": "Discreet and personal",
|
||||
"why.c6d": "One dedicated contact, no auction and no public sale.",
|
||||
"types.eyebrow": "What we buy",
|
||||
"types.title": "What we buy",
|
||||
"types.sub": "Rented properties across Germany — from a single apartment to a full complex.",
|
||||
"types.t1img": "Apartment building",
|
||||
"types.t1t": "Rented apartments",
|
||||
"types.t1d": "One or more apartments, occupied or vacant.",
|
||||
"types.t2img": "Rented house",
|
||||
"types.t2t": "Rented houses",
|
||||
"types.t2d": "Family homes and townhouses with ongoing tenancies.",
|
||||
"types.t3img": "Apartment building",
|
||||
"types.t3t": "Apartment buildings",
|
||||
"types.t3d": "Entire complexes with multiple units and tenants.",
|
||||
"types.t4img": "Mixed-use building",
|
||||
"types.t4t": "Mixed-use buildings",
|
||||
"types.t4d": "Combinations of living and working, shops or offices.",
|
||||
"value.eyebrow": "First indication",
|
||||
"value.title": "What could your property be worth?",
|
||||
"value.sub": "A first indication based on rental income. The figures below are fictional examples (test data).",
|
||||
"value.note": "Every property is different. Your final offer follows a short assessment — always non-binding.",
|
||||
"value.col1": "Property type",
|
||||
"value.col2": "Rent per month",
|
||||
"value.col3": "Indication",
|
||||
"value.r1c1": "Rented apartment",
|
||||
"value.r2c1": "Rented house",
|
||||
"value.r3c1": "Apartment building (8 units)",
|
||||
"value.testdata": "Fictional example figures — test data",
|
||||
"testi.eyebrow": "Experiences",
|
||||
"testi.title": "What owners say",
|
||||
"testi.sub": "Fictional quotes — test data.",
|
||||
"testi.q1": "“Within three days we had an offer on the table. No viewings, no hassle — and our tenants could simply stay.”",
|
||||
"testi.a1n": "Marleen V.",
|
||||
"testi.a1r": "Owner of two rented apartments",
|
||||
"testi.q2": "“After my father passed away, I wanted to sell the rented house quickly and properly. Huurbaken arranged everything, including the tenant.”",
|
||||
"testi.a2n": "Johan D.",
|
||||
"testi.a2r": "Heir to a rented house",
|
||||
"testi.q3": "“Finally a buyer who understands that tenants are people. The process was fast, clear and discreet.”",
|
||||
"testi.a3n": "Samira E.",
|
||||
"testi.a3r": "Owner of an apartment building",
|
||||
"faq.eyebrow": "Questions & answers",
|
||||
"faq.title": "Frequently asked questions",
|
||||
"faq.q1": "Do I need to evict my tenants?",
|
||||
"faq.a1": "No. We take over the existing tenancy agreements as they are. Your tenants simply stay and barely notice the sale.",
|
||||
"faq.q2": "How fast do I get an offer?",
|
||||
"faq.a2": "Within 48 hours of your request you receive a first, non-binding offer — on working days often even faster.",
|
||||
"faq.q3": "Are there any fees?",
|
||||
"faq.a3": "No. You pay no estate-agent fees and no sales commission. We also cover the valuation and notary costs.",
|
||||
"faq.q4": "What documents do I need?",
|
||||
"faq.a4": "At first only the basics: rental income, address and property type. Later we ask for the tenancy agreement and, if available, the WOZ or valuation report.",
|
||||
"faq.q5": "Which properties do you buy?",
|
||||
"faq.a5": "Rented apartments, houses, apartment buildings and mixed-use properties — across Germany, in any state of repair.",
|
||||
"faq.q6": "Is the offer binding?",
|
||||
"faq.a6": "No. Our offer is always non-binding. You decide in your own time whether to sell — no pressure, no obligations.",
|
||||
"form.eyebrow": "Free & non-binding",
|
||||
"form.title": "Get your free, non-binding offer",
|
||||
"form.sub": "Fill in the form — we will contact you within one working day.",
|
||||
"form.p1": "Offer within 48 hours",
|
||||
"form.p2": "No estate-agent fees",
|
||||
"form.p3": "Tenants stay put",
|
||||
"form.demoNote": "Demo form: no data is sent or stored.",
|
||||
"form.f_name": "Name *",
|
||||
"form.ph_name": "E.g. Anna Jansen",
|
||||
"form.f_email": "Email address *",
|
||||
"form.ph_email": "name@example.com",
|
||||
"form.f_phone": "Phone number *",
|
||||
"form.ph_phone": "+31 6 12345678",
|
||||
"form.f_type": "Property type *",
|
||||
"form.type_ph": "Choose a type",
|
||||
"form.type1": "Rented apartment",
|
||||
"form.type2": "Rented house",
|
||||
"form.type3": "Apartment building",
|
||||
"form.type4": "Mixed-use building",
|
||||
"form.type5": "Other",
|
||||
"form.f_city": "City and address *",
|
||||
"form.ph_city": "City, street + number",
|
||||
"form.f_rent": "Monthly rent (optional)",
|
||||
"form.ph_rent": "E.g. 1,250",
|
||||
"form.f_msg": "Message",
|
||||
"form.ph_msg": "Tell us briefly about your property…",
|
||||
"form.submit": "Request an offer",
|
||||
"form.privacy": "We use your details only to contact you.",
|
||||
"form.success_title": "Thank you for your request!",
|
||||
"form.success_text": "We will contact you within one working day with a first indication.",
|
||||
"form.demoNote2": "Demo form: no data is sent or stored.",
|
||||
"form.again": "Make a new request",
|
||||
"footer.tagline": "Huurbaken buys rented homes and buildings directly from owners — fast, fair and discreet.",
|
||||
"footer.navTitle": "Navigation",
|
||||
"footer.contactTitle": "Contact",
|
||||
"footer.langNote": "This website is available in Dutch and English.",
|
||||
"footer.demo": "Huurbaken is a fictional company. This website is a demo with test data, created for the Marstark Build Challenge.",
|
||||
"footer.rights": "© 2026 Huurbaken — fictional demo website",
|
||||
"err.required": "This field is required.",
|
||||
"err.email": "Please enter a valid email address.",
|
||||
"err.phone": "Please enter a valid phone number.",
|
||||
"menu.open": "Open menu",
|
||||
"menu.close": "Close menu"
|
||||
}
|
||||
};
|
||||
|
||||
const DEFAULT_LANG = "nl";
|
||||
const STORAGE_KEY = "huurbaken-lang";
|
||||
let currentLang = DEFAULT_LANG;
|
||||
|
||||
function getStoredLang() {
|
||||
try {
|
||||
const saved = window.localStorage.getItem(STORAGE_KEY);
|
||||
if (saved === "nl" || saved === "en") return saved;
|
||||
} catch (e) { /* storage unavailable — use default */ }
|
||||
return DEFAULT_LANG;
|
||||
}
|
||||
|
||||
function applyLanguage(lang) {
|
||||
if (!I18N[lang]) lang = DEFAULT_LANG;
|
||||
currentLang = lang;
|
||||
const dict = I18N[lang];
|
||||
|
||||
document.documentElement.lang = lang;
|
||||
document.title = dict["meta.title"] || document.title;
|
||||
|
||||
document.querySelectorAll("[data-i18n]").forEach((el) => {
|
||||
const key = el.getAttribute("data-i18n");
|
||||
if (dict[key] !== undefined) el.textContent = dict[key];
|
||||
});
|
||||
document.querySelectorAll("[data-i18n-ph]").forEach((el) => {
|
||||
const key = el.getAttribute("data-i18n-ph");
|
||||
if (dict[key] !== undefined) el.setAttribute("placeholder", dict[key]);
|
||||
});
|
||||
document.querySelectorAll("[data-i18n-alt]").forEach((el) => {
|
||||
const key = el.getAttribute("data-i18n-alt");
|
||||
if (dict[key] !== undefined) el.setAttribute("alt", dict[key]);
|
||||
});
|
||||
const metaDesc = document.querySelector('meta[name="description"]');
|
||||
if (metaDesc && dict["meta.description"]) {
|
||||
metaDesc.setAttribute("content", dict["meta.description"]);
|
||||
}
|
||||
|
||||
document.querySelectorAll(".lang-btn").forEach((btn) => {
|
||||
const active = btn.getAttribute("data-lang") === lang;
|
||||
btn.classList.toggle("is-active", active);
|
||||
btn.setAttribute("aria-pressed", active ? "true" : "false");
|
||||
});
|
||||
|
||||
try { window.localStorage.setItem(STORAGE_KEY, lang); } catch (e) { /* ignore */ }
|
||||
}
|
||||
|
||||
/* ---------------- Mobile menu ---------------- */
|
||||
function initMenu() {
|
||||
const toggle = document.getElementById("menuToggle");
|
||||
const nav = document.getElementById("mainNav");
|
||||
if (!toggle || !nav) return;
|
||||
|
||||
toggle.addEventListener("click", () => {
|
||||
const open = nav.classList.toggle("open");
|
||||
toggle.setAttribute("aria-expanded", open ? "true" : "false");
|
||||
toggle.setAttribute("aria-label", I18N[currentLang][open ? "menu.close" : "menu.open"]);
|
||||
});
|
||||
nav.querySelectorAll("a").forEach((link) => {
|
||||
link.addEventListener("click", () => {
|
||||
nav.classList.remove("open");
|
||||
toggle.setAttribute("aria-expanded", "false");
|
||||
toggle.setAttribute("aria-label", I18N[currentLang]["menu.open"]);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/* ---------------- FAQ accordion ---------------- */
|
||||
function initFaq() {
|
||||
document.querySelectorAll(".faq-item").forEach((item) => {
|
||||
const btn = item.querySelector(".faq-q");
|
||||
const answer = item.querySelector(".faq-a");
|
||||
if (!btn || !answer) return;
|
||||
btn.addEventListener("click", () => {
|
||||
const isOpen = item.classList.contains("open");
|
||||
document.querySelectorAll(".faq-item.open").forEach((other) => {
|
||||
other.classList.remove("open");
|
||||
other.querySelector(".faq-a").style.maxHeight = null;
|
||||
other.querySelector(".faq-q").setAttribute("aria-expanded", "false");
|
||||
});
|
||||
if (!isOpen) {
|
||||
item.classList.add("open");
|
||||
answer.style.maxHeight = answer.scrollHeight + "px";
|
||||
btn.setAttribute("aria-expanded", "true");
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/* ---------------- Lead form ---------------- */
|
||||
function showError(input, errorEl, message) {
|
||||
if (input) input.classList.add("invalid");
|
||||
if (errorEl) {
|
||||
errorEl.textContent = message;
|
||||
errorEl.hidden = false;
|
||||
}
|
||||
}
|
||||
function clearError(input, errorEl) {
|
||||
if (input) input.classList.remove("invalid");
|
||||
if (errorEl) errorEl.hidden = true;
|
||||
}
|
||||
|
||||
function initForm() {
|
||||
const form = document.getElementById("leadForm");
|
||||
const success = document.getElementById("formSuccess");
|
||||
const resetBtn = document.getElementById("formReset");
|
||||
if (!form || !success) return;
|
||||
|
||||
const fields = [
|
||||
{ input: document.getElementById("fName"), error: document.getElementById("errName"), kind: "required" },
|
||||
{ input: document.getElementById("fEmail"), error: document.getElementById("errEmail"), kind: "email" },
|
||||
{ input: document.getElementById("fPhone"), error: document.getElementById("errPhone"), kind: "phone" },
|
||||
{ input: document.getElementById("fType"), error: document.getElementById("errType"), kind: "required" },
|
||||
{ input: document.getElementById("fCity"), error: document.getElementById("errCity"), kind: "required" }
|
||||
];
|
||||
|
||||
fields.forEach(({ input, error }) => {
|
||||
if (!input) return;
|
||||
input.addEventListener("input", () => clearError(input, error));
|
||||
input.addEventListener("change", () => clearError(input, error));
|
||||
});
|
||||
|
||||
form.addEventListener("submit", (event) => {
|
||||
event.preventDefault();
|
||||
const dict = I18N[currentLang];
|
||||
let valid = true;
|
||||
let firstInvalid = null;
|
||||
|
||||
fields.forEach(({ input, error, kind }) => {
|
||||
if (!input) return;
|
||||
const value = input.value.trim();
|
||||
if (kind === "required" && !value) {
|
||||
showError(input, error, dict["err.required"]);
|
||||
valid = false;
|
||||
if (!firstInvalid) firstInvalid = input;
|
||||
} else if (kind === "email" && value && !/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(value)) {
|
||||
showError(input, error, dict["err.email"]);
|
||||
valid = false;
|
||||
if (!firstInvalid) firstInvalid = input;
|
||||
} else if (kind === "phone" && value && !/^\+?[0-9\s\-().]{7,20}$/.test(value)) {
|
||||
showError(input, error, dict["err.phone"]);
|
||||
valid = false;
|
||||
if (!firstInvalid) firstInvalid = input;
|
||||
}
|
||||
});
|
||||
|
||||
if (!valid) {
|
||||
if (firstInvalid) firstInvalid.focus();
|
||||
return;
|
||||
}
|
||||
|
||||
// Demo form: no data is sent or stored.
|
||||
form.hidden = true;
|
||||
success.hidden = false;
|
||||
success.scrollIntoView({ behavior: "smooth", block: "center" });
|
||||
});
|
||||
|
||||
if (resetBtn) {
|
||||
resetBtn.addEventListener("click", () => {
|
||||
form.reset();
|
||||
fields.forEach(({ input, error }) => clearError(input, error));
|
||||
success.hidden = true;
|
||||
form.hidden = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------- Language buttons ---------------- */
|
||||
function initLangSwitch() {
|
||||
document.querySelectorAll(".lang-btn").forEach((btn) => {
|
||||
btn.addEventListener("click", () => applyLanguage(btn.getAttribute("data-lang")));
|
||||
});
|
||||
}
|
||||
|
||||
/* ---------------- Init ---------------- */
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
applyLanguage(getStoredLang());
|
||||
initLangSwitch();
|
||||
initMenu();
|
||||
initFaq();
|
||||
initForm();
|
||||
});
|
||||
Reference in New Issue
Block a user