Branchwell

Clothworks / website · clothworks.ai / careers / careers.js

1(function(){var f=document.getElementById('cr-form');if(!f)return;var m=document.getElementById('cr-msg');
2var E=f.elements,k=E['kind'],box=document.getElementById('cr-tech');
3function sync(){var on=k&&k.value==='tech';if(box)box.hidden=!on;if(E['github'])E['github'].required=on;if(E['homepage'])E['homepage'].required=on;}
4if(k){k.addEventListener('change',sync);sync();}
5function url(v){v=(v||'').trim();if(v&&!/^https?:\/\//i.test(v))v='https://'+v;return v;}
6f.addEventListener('submit',function(e){e.preventDefault();
7var n=(E['name'].value||'').trim(),em=(E['email'].value||'').trim(),t=E['request'].value.trim(),kind=k?k.value:'',gh='',hp='';
8if(!n){m.textContent='Please add your name.';return;}
9if(!/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(em)){m.textContent='Please add a valid email.';return;}
10if(k&&!kind){m.textContent='Please choose what kind of work.';return;}
11if(kind==='tech'){gh=url(E['github'].value);hp=url(E['homepage'].value);
12if(!/^https:\/\/(www\.)?(github\.com|branchwell\.ai)\/[A-Za-z0-9_.-]+/i.test(gh.replace(/^http:/i,'https:'))){m.textContent='Tech roles need your Branchwell profile link.';return;}
13if(!/^https?:\/\/[^\s\/]+\.[^\s\/]{2,}/i.test(hp)||/^https?:\/\/(www\.)?(github\.com|branchwell\.ai)(\/|$)/i.test(hp)){m.textContent='Tech roles need a link to your own website too.';return;}}
14if(!t){m.textContent='Please write a short message.';return;}
15var head='Name: '+n+'\nEmail: '+em+(kind?'\nKind of work: '+(kind==='tech'?'Tech':'Everything else'):'')+(gh?'\nBranchwell: '+gh:'')+(hp?'\nWebsite: '+hp:'');
16var b=f.querySelector('button');b.disabled=true;m.textContent='Sending…';
17fetch('/api/request',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify({request:head+'\n\n'+t,name:n,email:em,message:t,kind:kind,github:gh,homepage:hp,site:location.hostname,website:E['website'].value})})
18.then(function(r){if(!r.ok)throw 0;f.reset();sync();m.textContent='Thanks. We got your note and will be in touch about joining our team.';})
19.catch(function(){m.textContent='That didn’t go through. Please try again in a minute.';})
20.then(function(){b.disabled=false;});});})();