(() => { const filters = document.querySelector('.career-filters'); if (!filters) return; const field = document.querySelector('#career-query'); const family = document.querySelector('#career-family'); const clear = document.querySelector('#career-clear'); const cards = document.querySelector('.career-families'); const results = document.querySelector('.career-results'); const list = document.querySelector('#career-results'); const status = document.querySelector('#career-status'); const more = document.querySelector('#career-more'); const browse = [...cards.querySelectorAll('[data-career-browse]')]; const pageSize = 24; const normalize = s => s.toLowerCase().normalize('NFKD').replace(/\p{M}/gu, '').replace(/[^a-z0-9]+/g, ' ').trim(); const communities = { software: 'Software', 'ai-data': 'AI and Data', community: 'Community', 'leadership-operations': 'Leadership and Operations', 'design-media': 'Design and Media', 'film-tv-production': 'Film and TV Production', 'data-centers-trades': 'Data Centers and Trades', 'health-veterinary': 'Health and Veterinary', 'kitchens-food': 'Kitchens and Food', 'farming': 'Farming', 'delivery-driving': 'Delivery and Driving', 'motors': 'Motors', 'robotics-space': 'Robotics and Space', 'chips-manufacturing': 'Chips and Manufacturing', }; const communityLink = () => 'mailto:hello@jobley.ai?subject=Volunteer'; let rows, set, shown; function search() { const typed = normalize(field.value); const words = typed.split(' ').filter(Boolean); const group = family.value; cards.hidden = Boolean(typed || group); results.hidden = !cards.hidden; list.replaceChildren(); shown = 0; if (results.hidden) { status.textContent = ''; return; } set = rows.filter(row => (!group || row.group === group) && words.every(word => row.key.includes(word))); if (typed) set.sort((a, b) => Number(b.primary.startsWith(typed)) - Number(a.primary.startsWith(typed))); if (!set.length) { status.textContent = 'No careers found. Try another term or clear the filters.'; more.hidden = true; } else renderNext(false); } function renderNext(moveFocus) { let first; for (const row of set.slice(shown, shown + pageSize)) { const item = document.createElement('li'); const head = document.createElement('h3'); const guide = document.createElement('a'); guide.href = '/careers/' + row.code + '/'; guide.textContent = row.title; guide.setAttribute('aria-label', 'Read the starter curriculum for ' + row.title); head.append(guide); const detail = document.createElement('p'); detail.textContent = row.family; const link = document.createElement('a'); link.href = communityLink(row.trade); link.textContent = 'Volunteer in ' + communities[row.trade]; link.setAttribute('aria-label', link.textContent + ' for ' + row.title); const art = document.createElement('img'); art.className = 'role-art role-art-thumb'; art.src = '/assets/role-art/career/' + row.code + '.svg'; art.alt = ''; art.width = 224; art.height = 112; art.loading = 'lazy'; art.decoding = 'async'; const heading = document.createElement('div'); heading.className = 'role-card-heading'; heading.append(art, head); item.append(heading, detail, link); list.append(item); first ||= guide; } shown = Math.min(shown + pageSize, set.length); more.hidden = shown >= set.length; status.textContent = 'Showing ' + shown + ' of ' + set.length + (set.length === 1 ? ' career' : ' careers') + '.'; if (moveFocus) first?.focus(); } fetch('/assets/career-directory.json') .then(response => { if (!response.ok) throw new Error('Directory unavailable'); return response.json(); }) .then(data => { const families = new Map(data.families.map(([code, name, trade]) => [code, {name, trade}])); rows = data.careers.map(([code, title, override, aliases]) => { const group = code.slice(0, 2); const {name, trade} = families.get(group); return {code, title, family: name, group, trade: override || trade, primary: normalize(title), key: normalize(title + ' ' + aliases + ' ' + code)}; }); filters.hidden = false; for (const button of browse) { button.hidden = false; button.addEventListener('click', () => { family.value = button.dataset.careerBrowse; search(); family.focus(); }); } field.addEventListener('input', search); family.addEventListener('change', search); clear.addEventListener('click', () => { field.value = ''; family.value = ''; search(); field.focus(); }); more.addEventListener('click', () => renderNext(true)); search(); }) .catch(() => { document.querySelector('.career-fallback').hidden = false; }); })();