Jobley / website · jobley.ai / assets / board.js
| 1 | // Jobley board: filter teams and roles by words and place. Works without it: every role shows. |
| 2 | (function () { |
| 3 | var box = document.querySelector('.board-filters'); |
| 4 | if (!box) return; |
| 5 | box.hidden = false; |
| 6 | var q = document.getElementById('q'), where = document.getElementById('where'); |
| 7 | var orgs = Array.prototype.slice.call(document.querySelectorAll('.org')); |
| 8 | var status = document.getElementById('board-status'), empty = document.getElementById('board-empty'); |
| 9 | function run() { |
| 10 | var words = q.value.toLowerCase().trim().split(/\s+/).filter(Boolean), place = where.value, teams = 0, roles = 0; |
| 11 | orgs.forEach(function (o) { |
| 12 | var okPlace = !place || o.dataset.where === place; |
| 13 | var name = o.querySelector('h3').textContent.toLowerCase() + ' ' + o.querySelector('.org-what').textContent.toLowerCase(); |
| 14 | var orgHit = words.length && words.every(function (w) { return name.indexOf(w) > -1; }); |
| 15 | var shown = 0; |
| 16 | Array.prototype.forEach.call(o.querySelectorAll('.roles li'), function (li) { |
| 17 | var t = li.textContent.toLowerCase(); |
| 18 | var hit = !words.length || orgHit || words.every(function (w) { return t.indexOf(w) > -1; }); |
| 19 | li.hidden = !hit; if (hit) shown++; |
| 20 | }); |
| 21 | var show = okPlace && shown > 0; |
| 22 | o.hidden = !show; |
| 23 | if (show) { teams++; roles += shown; } |
| 24 | }); |
| 25 | empty.hidden = teams > 0; |
| 26 | status.textContent = (words.length || place) ? roles + (roles === 1 ? ' role' : ' roles') + ' on ' + teams + (teams === 1 ? ' team' : ' teams') : ''; |
| 27 | } |
| 28 | q.addEventListener('input', run); where.addEventListener('change', run); |
| 29 | })(); |