Improved contact form and responsive aspect

This commit is contained in:
N0Xx committed 2026-10-22 23:21:07 +02:00
1 parent 216077cd32
commit 98d513acb7
19 files changed
+584 -733

No files matched your search

-21
View File
@@ -1,21 +0,0 @@
(function(){
// Land at the top, even when the page is shown inside a frame (scrollIntoView also scrolls the parent page)
if('scrollRestoration' in history)history.scrollRestoration='manual';
function toTop(){window.scrollTo(0,0);var m=document.body;if(m&&m.scrollIntoView)m.scrollIntoView({block:'start',behavior:'instant'})}
window.addEventListener('load',function(){if(!/^#(en|fr)-/.test(location.hash))toTop()});
var arts={en:document.getElementById('en'),fr:document.getElementById('fr')};
var links=[].slice.call(document.querySelectorAll('.lang-switch a'));
function show(lang,top){
Object.keys(arts).forEach(function(k){arts[k].hidden=k!==lang});
links.forEach(function(a){a.setAttribute('aria-current',a.getAttribute('href')==='#'+lang)});
document.documentElement.lang=lang;
document.title=lang==='fr'?'Mentions légales – Nelson Thomas':'Legal notice – Nelson Thomas';
if(top)toTop();
}
links.forEach(function(a){a.addEventListener('click',function(e){
e.preventDefault(); var l=a.getAttribute('href').slice(1);
history.replaceState(null,'','#'+l); show(l,true);
})});
var h=location.hash.slice(1,3);
show(h==='fr'||h==='en'?h:(/^fr\b/i.test(navigator.language||'')?'fr':'en'),!/^#(en|fr)-/.test(location.hash));
})();
+22 -5
View File
@@ -8,6 +8,7 @@ var LINKEDIN_URL = "https://www.linkedin.com/in/nelson-thomas-pr/";
(function(){
var root=document.documentElement;
try{var s=localStorage.getItem('theme');if(s)root.dataset.theme=s}catch(e){}
document.getElementById('theme').addEventListener('click',function(){
var dark=root.dataset.theme?root.dataset.theme==='dark':!matchMedia('(prefers-color-scheme: light)').matches;
root.dataset.theme=dark?'light':'dark';
@@ -45,6 +46,7 @@ var LINKEDIN_URL = "https://www.linkedin.com/in/nelson-thomas-pr/";
// Contact form
var form=document.getElementById('contact-form'), btn=document.getElementById('f-send'), st=document.getElementById('f-status');
var btnHTML=btn?btn.innerHTML:'';
function say(msg,cls){st.textContent=msg;st.className='status '+(cls||'')}
function sendFailed(){
st.className='status err'; st.textContent='The message could not be sent. Try again in a few minutes, or reach me on ';
@@ -53,12 +55,12 @@ var LINKEDIN_URL = "https://www.linkedin.com/in/nelson-thomas-pr/";
}
form.addEventListener('submit',function(e){
e.preventDefault();
if(!form.checkValidity()){form.reportValidity();say('Fill in your name, a valid email, a subject and a message.','err');return}
if(!form.checkValidity()){form.reportValidity();say('Fill in the required fields (*), check your email and phone number, and tick the consent box.','err');return}
if(form.botcheck.checked)return;
var d={name:form.name.value.trim(),email:form.email.value.trim(),company:form.company.value.trim(),subject:form.subject.value.trim(),message:form.message.value.trim()};
btn.disabled=true;btn.textContent='Sending...';say('');
var d={first_name:form.first_name.value.trim(),last_name:form.last_name.value.trim(),email:form.email.value.trim(),phone:form.phone.value.trim(),company:form.company.value.trim(),subject:form.subject.value.trim(),message:form.message.value.trim(),consent:form.consent.checked};
btn.disabled=true;btn.textContent='Sending…';say('');
fetch(CONTACT_ENDPOINT,{method:'POST',headers:{'Content-Type':'application/json',Accept:'application/json'},
body:JSON.stringify({name:d.name,email:d.email,company:d.company,subject:d.subject,message:d.message,botcheck:false})})
body:JSON.stringify(Object.assign({},d,{botcheck:false}))})
.then(function(r){
return r.json().catch(function(){throw new Error('network')}).then(function(j){return {status:r.status,body:j}});
})
@@ -69,7 +71,7 @@ var LINKEDIN_URL = "https://www.linkedin.com/in/nelson-thomas-pr/";
throw new Error('server');
})
.catch(sendFailed)
.finally(function(){btn.disabled=false;btn.textContent='Send message'});
.finally(function(){btn.disabled=false;btn.innerHTML=btnHTML});
});
// Certificate viewer (native <dialog>: Esc closes, focus is handled by the browser)
@@ -128,4 +130,19 @@ var LINKEDIN_URL = "https://www.linkedin.com/in/nelson-thomas-pr/";
window.addEventListener('resize',tlEdges);
tlEdges();
}
// Hamburger menu on small screens
var menuBtn=document.getElementById('menu-btn'), siteNav=document.getElementById('site-nav');
if(menuBtn&&siteNav){
var setMenu=function(open){
siteNav.classList.toggle('open',open);
menuBtn.setAttribute('aria-expanded',open);
menuBtn.setAttribute('aria-label',open?'Close the menu':'Open the menu');
};
menuBtn.addEventListener('click',function(){setMenu(menuBtn.getAttribute('aria-expanded')!=='true')});
siteNav.addEventListener('click',function(e){if(e.target.closest('a'))setMenu(false)});
document.addEventListener('keydown',function(e){if(e.key==='Escape'&&siteNav.classList.contains('open')){setMenu(false);menuBtn.focus()}});
document.addEventListener('click',function(e){if(siteNav.classList.contains('open')&&!e.target.closest('header'))setMenu(false)});
window.addEventListener('resize',function(){if(window.innerWidth>1080)setMenu(false)});
}
})();
-2
View File
@@ -1,2 +0,0 @@
/* Apply the saved light/dark choice before the page paints (no flash). */
try{var t=localStorage.getItem('theme');if(t==='light'||t==='dark')document.documentElement.dataset.theme=t}catch(e){}