« get me outta code hell

text-with-tooltip.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/text-with-tooltip.js
blob: dd207e04177be45afcd77c97dd4b8b9065145411 (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
/* eslint-env browser */

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

import {registerTooltipElement, registerTooltipHoverableElement}
  from './hoverable-tooltip.js';

export const info = {
  id: 'textWithTooltipInfo',

  hoverables: null,
  tooltips: null,
};

export function getPageReferences() {
  const spans =
    Array.from(document.querySelectorAll('.text-with-tooltip'));

  info.hoverables =
    spans.map(span => span.children[0]);

  info.tooltips =
    spans.map(span => span.children[1]);
}

export function addPageListeners() {
  for (const {hoverable, tooltip} of stitchArrays({
    hoverable: info.hoverables,
    tooltip: info.tooltips,
  })) {
    registerTooltipElement(tooltip);
    registerTooltipHoverableElement(hoverable, tooltip);
  }
}