« get me outta code hell

summary-nested-link.js « client « js « static « src - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/static/js/client/summary-nested-link.js
blob: 23857fa5da4e88ec7b66c06e32a55d0d196ead94 (plain)
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
/* eslint-env browser */

import {
  empty,
  filterMultipleArrays,
  stitchArrays,
} from '../../shared-util/sugar.js';

export const info = {
  id: 'summaryNestedLinkInfo',

  summaries: null,
  links: null,
};

export function getPageReferences() {
  info.summaries =
    Array.from(document.getElementsByTagName('summary'));

  info.links =
    info.summaries
      .map(summary =>
        Array.from(summary.getElementsByTagName('a')));

  filterMultipleArrays(
    info.summaries,
    info.links,
    (_summary, links) => !empty(links));
}

export function addPageListeners() {
  for (const {summary, links} of stitchArrays({
    summary: info.summaries,
    links: info.links,
  })) {
    for (const link of links) {
      link.addEventListener('mouseover', () => {
        link.classList.add('nested-hover');
        summary.classList.add('has-nested-hover');
      });

      link.addEventListener('mouseout', () => {
        link.classList.remove('nested-hover');
        summary.classList.remove('has-nested-hover');
      });
    }
  }
}