Initial commit of the project
This commit is contained in:
commit
a1c679b60a
5 files changed
+553
No files matched your search
@@ -0,0 +1,72 @@
|
||||
/* ===== Contact form settings =====
|
||||
1. Create a free key at https://web3forms.com with nelson.thomas.contact@pm.me
|
||||
2. Paste it below. Messages then arrive straight in your Proton inbox.
|
||||
Without a key (or if the service is unreachable), the form opens the
|
||||
visitor's mail app with the message already written. */
|
||||
var WEB3FORMS_KEY = "YOUR_ACCESS_KEY";
|
||||
var CONTACT_EMAIL = "nelson.thomas.contact@pm.me";
|
||||
|
||||
(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';
|
||||
try{localStorage.setItem('theme',root.dataset.theme)}catch(e){}
|
||||
});
|
||||
|
||||
// Scroll-spy: highlight the section on screen
|
||||
var links=[].slice.call(document.querySelectorAll('nav a'));
|
||||
var nav=document.querySelector('nav');
|
||||
function setActive(id){
|
||||
links.forEach(function(a){
|
||||
var on=a.getAttribute('href')==='#'+id;
|
||||
a.classList.toggle('active',on);
|
||||
if(on){a.setAttribute('aria-current','true');
|
||||
var l=a.offsetLeft-nav.offsetLeft, r=l+a.offsetWidth;
|
||||
if(l<nav.scrollLeft||r>nav.scrollLeft+nav.clientWidth) nav.scrollTo({left:l-16,behavior:'smooth'});
|
||||
} else a.removeAttribute('aria-current');
|
||||
});
|
||||
}
|
||||
var sections=[].slice.call(document.querySelectorAll('main>section'));
|
||||
if('IntersectionObserver' in window){
|
||||
var io=new IntersectionObserver(function(entries){
|
||||
entries.forEach(function(e){if(e.isIntersecting)setActive(e.target.id)});
|
||||
},{rootMargin:'-45% 0px -50% 0px'});
|
||||
sections.forEach(function(s){io.observe(s)});
|
||||
}
|
||||
// Reading progress line under the header
|
||||
var header=document.querySelector('header');
|
||||
function progress(){
|
||||
var h=document.documentElement, max=h.scrollHeight-h.clientHeight;
|
||||
header.style.setProperty('--progress',(max>0?h.scrollTop/max*100:0)+'%');
|
||||
if(h.scrollTop+h.clientHeight>=h.scrollHeight-4) setActive('contact');
|
||||
}
|
||||
window.addEventListener('scroll',progress,{passive:true}); progress();
|
||||
|
||||
// Contact form
|
||||
var form=document.getElementById('contact-form'), btn=document.getElementById('f-send'), st=document.getElementById('f-status');
|
||||
function say(msg,cls){st.textContent=msg;st.className='status '+(cls||'')}
|
||||
function mailtoFallback(d){
|
||||
var body=d.message+'\n\n'+d.name+(d.company?' ('+d.company+')':'')+'\n'+d.email;
|
||||
window.location.href='mailto:'+CONTACT_EMAIL+'?subject='+encodeURIComponent(d.subject)+'&body='+encodeURIComponent(body);
|
||||
say('Your mail app should open with the message ready. If nothing happens, write to '+CONTACT_EMAIL+'.','ok');
|
||||
}
|
||||
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.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()};
|
||||
if(!WEB3FORMS_KEY||WEB3FORMS_KEY==='YOUR_ACCESS_KEY'){mailtoFallback(d);return}
|
||||
btn.disabled=true;btn.textContent='Sending...';say('');
|
||||
fetch('https://api.web3forms.com/submit',{method:'POST',headers:{'Content-Type':'application/json',Accept:'application/json'},
|
||||
body:JSON.stringify({access_key:WEB3FORMS_KEY,from_name:'Portfolio: '+d.name,replyto:d.email,subject:'[Portfolio] '+d.subject,name:d.name,email:d.email,company:d.company,message:d.message})})
|
||||
.then(function(r){return r.json()})
|
||||
.then(function(r){
|
||||
if(r.success){form.reset();say('Message sent. Thanks, I\'ll get back to you soon.','ok')}
|
||||
else throw new Error(r.message);
|
||||
})
|
||||
.catch(function(){mailtoFallback(d)})
|
||||
.finally(function(){btn.disabled=false;btn.textContent='Send message'});
|
||||
});
|
||||
})();
|
||||
Reference in new issue
Block a user