|
1 | 1 | /*
|
2 | 2 | * Filter feature matrix
|
3 | 3 | */
|
4 |
| -$(document).ready(function(){ |
5 |
| - // Show/hide column based on whether supplied checkbox is checked. |
6 |
| - function filter_version(checkbox) |
7 |
| - { |
8 |
| - var total_checked = $('form#featurematrix_version_filter .featurematrix_version:checked').length; |
9 |
| - var column=$("table tr:first th").index($("table tr:first th:contains('" + checkbox.val() + "')")) + 1; |
10 |
| - if (total_checked) { |
11 |
| - $('.feature-version-col').css('width', (70 / total_checked) + '%'); |
| 4 | + |
| 5 | +function hide_unchanged(toggled) { |
| 6 | + /* Unfortunately, can't figure out how to do this part in pure CSS */ |
| 7 | + |
| 8 | + if (!document.getElementById('hide_unchanged').checked) { |
| 9 | + /* Unchanged filter is unchecked. If we just made it unchecked we have to display everything, otherwise we have nothing to do here. */ |
| 10 | + if (toggled) { |
| 11 | + document.querySelectorAll('table.matrix tbody tr').forEach((tr) => { |
| 12 | + tr.style.display = 'table-row'; |
| 13 | + }); |
12 | 14 | }
|
13 |
| - $("table th:nth-child(" + column + "), table td:nth-child(" + column + ")").toggle(checkbox.is(":checked")).toggleClass('hidden'); |
14 |
| - hide_unchanged(); |
15 |
| - // Lastly, if at this point an entire row is obsolete, then hide |
16 |
| - $('tbody tr').each(function(i, el) { |
17 |
| - var $tr = $(el), |
18 |
| - visible_count = $tr.find('td:not(.hidden)').length, |
19 |
| - obsolete_count = $tr.find('td.fm_obs:not(.hidden)').length; |
20 |
| - // if visible count matches obsolete count, then hide this row |
21 |
| - $tr.toggle(visible_count !== obsolete_count); |
22 |
| - }); |
| 15 | + return; |
23 | 16 | }
|
24 | 17 |
|
25 |
| - // Show/hide rows if all values are the same in displayed cells |
26 |
| - function hide_unchanged() |
27 |
| - { |
28 |
| - var hide_unchanged=$('form#featurematrix_version_filter input#hide_unchanged').is(':checked'); |
29 |
| - $('table tr').has('td').each(function(){ |
30 |
| - var row_values=$(this).children('td').not('.colFirst, .hidden'); |
31 |
| - var yes_count=row_values.filter(":contains('Yes')").length; |
32 |
| - var no_count=row_values.filter(":contains('No')").length; |
33 |
| - var obsolete_count=row_values.filter(":contains('Obsolete')").length; |
34 |
| - $(this).toggle(hide_unchanged == false || (yes_count != row_values.length && no_count != row_values.length && obsolete_count != row_values.length)); |
35 |
| - }); |
36 |
| - } |
| 18 | + /* Get indexes of checked version checkboxes */ |
| 19 | + const vercols = [...document.querySelectorAll('#featurematrix_version_filter input.featurematrix_version')].map((cb, i) => cb.checked ? i : null).filter((i) => i != null); |
37 | 20 |
|
38 |
| - // Upon loading the page, apply the filter based on EOL versions that are |
39 |
| - // unchecked. |
40 |
| - $('form#featurematrix_version_filter input.featurematrix_version').not(':checked').each(function(){ |
41 |
| - filter_version($(this)); |
| 21 | + document.querySelectorAll('table.matrix tbody tr').forEach((tr) => { |
| 22 | + /* Get classes of all relevant td's (based on vercols), and see if there is more than one unique class. Assumes each td only has one explicit class. */ |
| 23 | + const changed = new Set([...tr.querySelectorAll('td')].filter((td, i) => vercols.indexOf(i) > -1).map((td) => td.classList[0])).size > 1; |
| 24 | + tr.style.display = changed ? "table-row" : "none"; |
42 | 25 | });
|
| 26 | +} |
43 | 27 |
|
44 |
| - // Apply filter based on change in check status of clicked version filter. |
45 |
| - $('form#featurematrix_version_filter input.featurematrix_version').on("change", function(){ |
46 |
| - filter_version($(this)); |
| 28 | +document.addEventListener('DOMContentLoaded', () => { |
| 29 | + document.getElementById('hide_unchanged').addEventListener('change', (e) => { |
| 30 | + hide_unchanged(true); |
47 | 31 | });
|
48 |
| - |
49 |
| - // Show/hide unchanged feature rows when checkbox clicked. |
50 |
| - $('form#featurematrix_version_filter input#hide_unchanged').on("change", function(){ |
51 |
| - hide_unchanged(); |
| 32 | + document.querySelectorAll('input.featurematrix_version').forEach((c) => { |
| 33 | + c.addEventListener('change', (e) => { |
| 34 | + hide_unchanged(false); |
| 35 | + }); |
52 | 36 | });
|
53 | 37 | });
|
0 commit comments