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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
/* eslint-env browser */
import {stitchArrays} from '../../shared-util/sugar.js';
export const info = {
id: 'quickDescriptionInfo',
quickDescriptionContainers: null,
quickDescriptionsAreExpandable: null,
expandDescriptionLinks: null,
collapseDescriptionLinks: null,
};
export function getPageReferences() {
info.quickDescriptionContainers =
Array.from(document.querySelectorAll('#content .quick-description'));
info.quickDescriptionsAreExpandable =
info.quickDescriptionContainers
.map(container =>
container.querySelector('.quick-description-actions.when-expanded'));
info.expandDescriptionLinks =
info.quickDescriptionContainers
.map(container =>
container.querySelector('.quick-description-actions .expand-link'));
info.collapseDescriptionLinks =
info.quickDescriptionContainers
.map(container =>
container.querySelector('.quick-description-actions .collapse-link'));
}
export function addPageListeners() {
for (const {
isExpandable,
container,
expandLink,
collapseLink,
} of stitchArrays({
isExpandable: info.quickDescriptionsAreExpandable,
container: info.quickDescriptionContainers,
expandLink: info.expandDescriptionLinks,
collapseLink: info.collapseDescriptionLinks,
})) {
if (!isExpandable) continue;
expandLink.addEventListener('click', event => {
event.preventDefault();
container.classList.add('expanded');
container.classList.remove('collapsed');
});
collapseLink.addEventListener('click', event => {
event.preventDefault();
container.classList.add('collapsed');
container.classList.remove('expanded');
});
}
}
|