« get me outta code hell

datetimestamp-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/datetimestamp-tooltip.js
blob: 46d1cd5b8cbde8d3ece76aa4f0496c98595b7c90 (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
/* eslint-env browser */

// TODO: Maybe datetimestamps can just be incorporated into text-with-tooltip?

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

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

export const info = {
  id: 'datetimestampTooltipInfo',

  hoverables: null,
  tooltips: null,
};

export function getPageReferences() {
  const spans =
    Array.from(document.querySelectorAll('span.datetimestamp.has-tooltip'));

  info.hoverables =
    spans.map(span => span.querySelector('time'));

  info.tooltips =
    spans.map(span => span.querySelector('span.datetimestamp-tooltip'));
}

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