« get me outta code hell

content, test: linkThing: apply color to text-with-tooltip wrapper - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-01-13 19:55:51 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-01-13 21:19:10 -0400
commit7cf04ff2deb4401ac9ab8d0b305658e6ac740c7e (patch)
treea20471d159026998a6405024007447bb69b827d1
parente8f8306cf85288c1f424a4d31cfc50c2aac2ccab (diff)
content, test: linkThing: apply color to text-with-tooltip wrapper
-rw-r--r--src/content/dependencies/linkThing.js19
-rw-r--r--tap-snapshots/test/snapshot/linkThing.js.test.cjs1
-rw-r--r--test/snapshot/linkThing.js1
3 files changed, 15 insertions, 6 deletions
diff --git a/src/content/dependencies/linkThing.js b/src/content/dependencies/linkThing.js
index d1f6a097..b4cfda03 100644
--- a/src/content/dependencies/linkThing.js
+++ b/src/content/dependencies/linkThing.js
@@ -76,11 +76,12 @@ export default {
   },
 
   generate(data, relations, slots, {html, language}) {
-    const {attributes} = slots;
-
     const path =
       slots.path ?? data.path;
 
+    const linkAttributes = slots.attributes;
+    const wrapperAttributes = html.attributes();
+
     const showShortName =
       (slots.preferShortName
         ? data.nameShort && data.nameShort !== data.name
@@ -104,7 +105,7 @@ export default {
         });
 
     if (slots.tooltipStyle === 'browser') {
-      attributes.add('title', data.name);
+      linkAttributes.add('title', data.name);
     }
 
     const content =
@@ -121,18 +122,24 @@ export default {
         colorStyle.setSlot('color', slots.color);
       }
 
-      attributes.add(colorStyle);
+      if (showWikiTooltip) {
+        wrapperAttributes.add(colorStyle);
+      } else {
+        linkAttributes.add(colorStyle);
+      }
     }
 
     return relations.textWithTooltip.slots({
+      attributes: wrapperAttributes,
+
       text:
         relations.linkTemplate.slots({
           path: slots.anchor ? [] : path,
           href: slots.anchor ? '' : null,
-          content,
-          attributes,
+          attributes: linkAttributes,
           hash: slots.hash,
           linkless: slots.linkless,
+          content,
         }),
 
       tooltip:
diff --git a/tap-snapshots/test/snapshot/linkThing.js.test.cjs b/tap-snapshots/test/snapshot/linkThing.js.test.cjs
index ae46443e..9a9d453b 100644
--- a/tap-snapshots/test/snapshot/linkThing.js.test.cjs
+++ b/tap-snapshots/test/snapshot/linkThing.js.test.cjs
@@ -13,6 +13,7 @@ exports[`test/snapshot/linkThing.js > TAP > linkThing (snapshot) > color 1`] = `
 <a href="track/showtime-piano-refrain/">Showtime (Piano Refrain)</a>
 <a style="--primary-color: #38f43d" href="track/showtime-piano-refrain/">Showtime (Piano Refrain)</a>
 <a style="--primary-color: #aaccff" href="track/showtime-piano-refrain/">Showtime (Piano Refrain)</a>
+<span style="--primary-color: #aaccff" class="text-with-tooltip"><a href="track/showtime-piano-refrain/">Showtime (Piano Refrain)</a><span class="tooltip thing-name-tooltip"><span class="tooltip-content">Showtime (Piano Refrain)</span></span></span>
 `
 
 exports[`test/snapshot/linkThing.js > TAP > linkThing (snapshot) > nested links in content stripped 1`] = `
diff --git a/test/snapshot/linkThing.js b/test/snapshot/linkThing.js
index d7d28a55..502db6d7 100644
--- a/test/snapshot/linkThing.js
+++ b/test/snapshot/linkThing.js
@@ -58,6 +58,7 @@ testContentFunctions(t, 'linkThing (snapshot)', async (t, evaluate) => {
       {slots: {color: false}},
       {slots: {color: true}},
       {slots: {color: '#aaccff'}},
+      {slots: {color: '#aaccff', tooltipStyle: 'wiki'}},
     ],
   });