// Jobley board: filter teams and roles by words and place. Works without it: every role shows. (function () { var box = document.querySelector('.board-filters'); if (!box) return; box.hidden = false; var q = document.getElementById('q'), where = document.getElementById('where'); var orgs = Array.prototype.slice.call(document.querySelectorAll('.org')); var status = document.getElementById('board-status'), empty = document.getElementById('board-empty'); function run() { var words = q.value.toLowerCase().trim().split(/\s+/).filter(Boolean), place = where.value, teams = 0, roles = 0; orgs.forEach(function (o) { var okPlace = !place || o.dataset.where === place; var name = o.querySelector('h3').textContent.toLowerCase() + ' ' + o.querySelector('.org-what').textContent.toLowerCase(); var orgHit = words.length && words.every(function (w) { return name.indexOf(w) > -1; }); var shown = 0; Array.prototype.forEach.call(o.querySelectorAll('.roles li'), function (li) { var t = li.textContent.toLowerCase(); var hit = !words.length || orgHit || words.every(function (w) { return t.indexOf(w) > -1; }); li.hidden = !hit; if (hit) shown++; }); var show = okPlace && shown > 0; o.hidden = !show; if (show) { teams++; roles += shown; } }); empty.hidden = teams > 0; status.textContent = (words.length || place) ? roles + (roles === 1 ? ' role' : ' roles') + ' on ' + teams + (teams === 1 ? ' team' : ' teams') : ''; } q.addEventListener('input', run); where.addEventListener('change', run); })();