|
5 | 5 | */
|
6 | 6 |
|
7 | 7 | class DocumentableList extends Component {
|
8 |
| - constructor(props) { |
9 |
| - super(props); |
10 |
| - |
11 |
| - this.refs = { |
12 |
| - tabs: findRefs(".names .tab[data-togglable]", findRef(".membersList")).concat( |
13 |
| - findRefs(".contents h2[data-togglable]", findRef(".membersList")) |
14 |
| - ), |
15 |
| - sections: findRefs(".contents .tab[data-togglable]", findRef(".membersList")), |
16 |
| - }; |
17 |
| - |
18 |
| - this.state = { |
19 |
| - list: new List(this.refs.tabs, this.refs.sections), |
20 |
| - }; |
21 |
| - |
22 |
| - this.render(this.props); |
23 |
| - } |
24 |
| - |
25 |
| - toggleElementDatasetVisibility(isVisible, ref) { |
26 |
| - ref.dataset.visibility = isVisible |
27 |
| - } |
28 |
| - |
29 |
| - toggleDisplayStyles(condition, ref) { |
30 |
| - ref.style.display = condition ? null : 'none' |
31 |
| - } |
32 |
| - |
33 |
| - render({ filter }) { |
34 |
| - this.state.list.sectionsRefs.map(sectionRef => { |
35 |
| - const isTabVisible = this.state.list |
36 |
| - .getSectionListRefs(sectionRef) |
37 |
| - .filter((listRef) => { |
38 |
| - const isListVisible = this.state.list |
39 |
| - .getSectionListElementsRefs(listRef) |
40 |
| - .map(elementRef => this.state.list.toListElement(elementRef)) |
41 |
| - .filter(elementData => { |
42 |
| - const isElementVisible = this.state.list.isElementVisible(elementData, filter); |
43 |
| - |
44 |
| - this.toggleDisplayStyles(isElementVisible, elementData.ref); |
45 |
| - this.toggleElementDatasetVisibility(isElementVisible, elementData.ref); |
46 |
| - |
47 |
| - return isElementVisible; |
48 |
| - }).length; |
49 |
| - |
50 |
| - findRefs("span.groupHeader", listRef).forEach(h => { |
51 |
| - const headerSiblings = this.state.list.getSectionListElementsRefs(h.parentNode).map(ref => this.state.list.toListElement(ref)) |
52 |
| - const isHeaderVisible = headerSiblings.filter(s => this.state.list.isElementVisible(s, filter)) != 0 |
53 |
| - |
54 |
| - this.toggleDisplayStyles(isHeaderVisible, h) |
55 |
| - }) |
56 |
| - |
57 |
| - this.toggleDisplayStyles(isListVisible, listRef); |
58 |
| - |
59 |
| - return isListVisible; |
60 |
| - }).length; |
61 |
| - |
62 |
| - const outerThis = this |
63 |
| - this.state.list.getTabRefFromSectionRef(sectionRef).forEach(function(tabRef){ |
64 |
| - outerThis.toggleDisplayStyles(isTabVisible, tabRef); |
65 |
| - }) |
66 |
| - }); |
67 |
| - } |
68 |
| -} |
| 8 | + constructor(props) { |
| 9 | + super(props); |
| 10 | + |
| 11 | + this.refs = { |
| 12 | + tabs: findRefs( |
| 13 | + ".names .tab[data-togglable]", |
| 14 | + findRef(".membersList"), |
| 15 | + ).concat( |
| 16 | + findRefs(".contents h2[data-togglable]", findRef(".membersList")), |
| 17 | + ), |
| 18 | + sections: findRefs( |
| 19 | + ".contents .tab[data-togglable]", |
| 20 | + findRef(".membersList"), |
| 21 | + ), |
| 22 | + }; |
| 23 | + |
| 24 | + this.state = { |
| 25 | + list: new List(this.refs.tabs, this.refs.sections), |
| 26 | + }; |
| 27 | + |
| 28 | + this.render(this.props); |
| 29 | + } |
| 30 | + |
| 31 | + toggleElementDatasetVisibility(isVisible, ref) { |
| 32 | + ref.dataset.visibility = isVisible; |
| 33 | + } |
| 34 | + |
| 35 | + toggleDisplayStyles(condition, ref) { |
| 36 | + ref.style.display = condition ? null : "none"; |
| 37 | + } |
| 38 | + |
| 39 | + render({ filter }) { |
| 40 | + this.state.list.sectionsRefs.map((sectionRef) => { |
| 41 | + const isTabVisible = this.state.list |
| 42 | + .getSectionListRefs(sectionRef) |
| 43 | + .filter((listRef) => { |
| 44 | + const isListVisible = this.state.list |
| 45 | + .getSectionListElementsRefs(listRef) |
| 46 | + .map((elementRef) => this.state.list.toListElement(elementRef)) |
| 47 | + .filter((elementData) => { |
| 48 | + const isElementVisible = this.state.list.isElementVisible( |
| 49 | + elementData, |
| 50 | + filter, |
| 51 | + ); |
| 52 | + |
| 53 | + this.toggleDisplayStyles(isElementVisible, elementData.ref); |
| 54 | + this.toggleElementDatasetVisibility( |
| 55 | + isElementVisible, |
| 56 | + elementData.ref, |
| 57 | + ); |
| 58 | + |
| 59 | + return isElementVisible; |
| 60 | + }).length; |
| 61 | + |
| 62 | + findRefs("span.groupHeader", listRef).forEach((h) => { |
| 63 | + const headerSiblings = this.state.list |
| 64 | + .getSectionListElementsRefs(h.parentNode) |
| 65 | + .map((ref) => this.state.list.toListElement(ref)); |
| 66 | + const isHeaderVisible = |
| 67 | + headerSiblings.filter((s) => |
| 68 | + this.state.list.isElementVisible(s, filter), |
| 69 | + ) != 0; |
| 70 | + |
| 71 | + this.toggleDisplayStyles(isHeaderVisible, h); |
| 72 | + }); |
| 73 | + |
| 74 | + this.toggleDisplayStyles(isListVisible, listRef); |
| 75 | + return isListVisible; |
| 76 | + }).length; |
| 77 | + |
| 78 | + const outerThis = this; |
| 79 | + this.state.list |
| 80 | + .getTabRefFromSectionRef(sectionRef) |
| 81 | + .forEach(function (tabRef) { |
| 82 | + outerThis.toggleDisplayStyles(isTabVisible, tabRef); |
| 83 | + }); |
| 84 | + }); |
| 85 | + } |
| 86 | + } |
69 | 87 |
|
70 | 88 | class List {
|
71 | 89 | /**
|
|
0 commit comments