forked from tedbow/drupal-gitlab-chrome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rowFilterer.js
38 lines (37 loc) · 1.01 KB
/
rowFilterer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* A filter table rows.
*/
class rowFilterer {
addHideCondition(element) {
const parentRow = element.closest("tr");
if (!parentRow.hasOwnProperty("hideConditions")) {
parentRow.hideConditions = new Set();
}
parentRow.hideConditions.add(this.getElementColumnIndex(element));
this.setHideStatus(parentRow);
}
removeHideCondition(element) {
const parentRow = element.closest("tr");
if (!parentRow.hasOwnProperty("hideConditions")) {
return;
}
parentRow.hideConditions.delete(this.getElementColumnIndex(element));
this.setHideStatus(parentRow);
}
setHideStatus(element) {
if (
element.hasOwnProperty("hideConditions") &&
element.hideConditions.size > 0
) {
element.style.display = "none";
} else {
element.style.display = "table-row";
}
}
getElementColumnIndex(element) {
const td = element.closest("td");
const tds = Array.from(td.closest("tr").children);
return tds.indexOf(td);
}
}
export { rowFilterer };