We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
1 | // For use with {ship,weapon}_list.php |
||
2 | |||
3 | var filter = []; |
||
4 | |||
5 | //reset all check boxes |
||
6 | function resetBoxes() { |
||
7 | var toggle = document.getElementById("raceform"); |
||
8 | for (var i = 0; i < toggle.races.length; i++) { |
||
9 | toggle.races[i].checked = true; |
||
10 | } |
||
11 | } |
||
12 | |||
13 | function filterSelect(element) { |
||
14 | var selected = element.options[element.selectedIndex].value; |
||
15 | var columnId = element.parentElement.cellIndex; |
||
16 | |||
17 | filter[columnId] = [selected]; |
||
18 | applyFilter('data-list'); |
||
19 | } |
||
20 | |||
21 | function raceToggle() { |
||
22 | var toggle = document.getElementById("raceform"); |
||
23 | // 1 is the index of the "Race" column |
||
24 | filter[1] = []; |
||
25 | for (var i = 0; i < toggle.races.length; i++) { |
||
26 | if (toggle.races[i].checked) { |
||
27 | filter[1].push(toggle.races[i].value); |
||
28 | } |
||
29 | } |
||
30 | applyFilter('data-list'); |
||
31 | } |
||
32 | |||
33 | function applyFilter(tableId) { |
||
34 | var table = document.getElementById(tableId); |
||
35 | for (var i=1; i < table.rows.length; i++) { |
||
36 | // Loop over columns with active filters, and hide row if any column |
||
37 | // fails its respective filter. |
||
38 | var show = true; |
||
39 | for (var j=0; j < table.rows[i].cells.length; j++) { |
||
40 | // No filtering for null, undefined, and "All". |
||
41 | // But we do filter on the empty string (for the "None" option). |
||
42 | if (filter[j] == null || filter[j][0] === "All") { |
||
0 ignored issues
–
show
Best Practice
introduced
by
![]() |
|||
43 | continue; |
||
44 | } |
||
45 | |||
46 | // Prepare the list of values in this cell for filtering. |
||
47 | // If there are no divs, then entire cell is the only value. |
||
48 | var cell = table.rows[i].cells[j]; |
||
49 | var values = cell.getElementsByTagName('div'); |
||
50 | if (values.length === 0) { |
||
51 | values = [cell]; |
||
52 | } |
||
53 | |||
54 | // The filters match against raw values, so extract them here. |
||
55 | var rawValues = []; |
||
56 | for (var k=0; k < values.length; k++) { |
||
57 | rawValues.push(values[k].textContent); |
||
58 | } |
||
59 | |||
60 | // One of the values must match at least one of the filters |
||
61 | if (rawValues.filter(function(value) { return filter[j].indexOf(value) !== -1; }).length === 0) { |
||
0 ignored issues
–
show
|
|||
62 | show = false; |
||
63 | break; |
||
64 | } |
||
65 | } |
||
66 | if (show) { |
||
67 | table.rows[i].style.display=""; |
||
68 | } else { |
||
69 | table.rows[i].style.display="none"; |
||
70 | } |
||
71 | } |
||
72 | } |
||
73 |