« get me outta code hell

client: client modules - 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
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-06-19 19:50:55 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-06-20 10:01:05 -0300
commitdf5f6048e6a177b5ce3920d10a1249129c669a1f (patch)
treef94c984a6f21069c02e33a8b9184580916606041 /src/static/js/client/text-with-tooltip.js
parente254ad385d33739d3e6b4a04d79325e2bca840b8 (diff)
client: client modules
Diffstat (limited to 'src/static/js/client/text-with-tooltip.js')
-rw-r--r--src/static/js/client/text-with-tooltip.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/static/js/client/text-with-tooltip.js b/src/static/js/client/text-with-tooltip.js
new file mode 100644
index 00000000..dd207e04
--- /dev/null
+++ b/src/static/js/client/text-with-tooltip.js
@@ -0,0 +1,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);
+  }
+}