« get me outta code hell

content, test: linkThing: tooltip -> tooltipStyle - 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:11:28 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-01-13 21:19:10 -0400
commita3dca62ee1cd0c1da0a8952bbbf62fb55ce7319f (patch)
treed8377c4ae82027146548b06a06ab18a5ca6bb8f0
parenteb8670ee11fd0a68c02ef96227b4475f08157ace (diff)
content, test: linkThing: tooltip -> tooltipStyle
-rw-r--r--src/content/dependencies/generateChronologyLinks.js4
-rw-r--r--src/content/dependencies/generatePreviousNextLinks.js4
-rw-r--r--src/content/dependencies/linkThing.js29
-rw-r--r--tap-snapshots/test/snapshot/generateAlbumSecondaryNav.js.test.cjs4
-rw-r--r--tap-snapshots/test/snapshot/generatePreviousNextLinks.js.test.cjs12
-rw-r--r--tap-snapshots/test/snapshot/linkThing.js.test.cjs5
-rw-r--r--test/snapshot/linkThing.js7
7 files changed, 32 insertions, 33 deletions
diff --git a/src/content/dependencies/generateChronologyLinks.js b/src/content/dependencies/generateChronologyLinks.js
index 16e4f999..8ec6ee0a 100644
--- a/src/content/dependencies/generateChronologyLinks.js
+++ b/src/content/dependencies/generateChronologyLinks.js
@@ -61,13 +61,13 @@ export default {
               html.tag('span', {class: 'buttons'},
                 language.formatUnitList([
                   previousLink?.slots({
-                    tooltip: true,
+                    tooltipStyle: 'browser',
                     color: false,
                     content: language.$('misc.nav.previous'),
                   }),
 
                   nextLink?.slots({
-                    tooltip: true,
+                    tooltipStyle: 'browser',
                     color: false,
                     content: language.$('misc.nav.next'),
                   }),
diff --git a/src/content/dependencies/generatePreviousNextLinks.js b/src/content/dependencies/generatePreviousNextLinks.js
index d3e529bf..9771de39 100644
--- a/src/content/dependencies/generatePreviousNextLinks.js
+++ b/src/content/dependencies/generatePreviousNextLinks.js
@@ -28,7 +28,7 @@ export default {
     if (!html.isBlank(slots.previousLink)) {
       previousNext.push(
         slots.previousLink.slots({
-          tooltip: true,
+          tooltipStyle: 'browser',
           color: false,
           attributes: {id: slots.id && 'previous-button'},
           content: language.$('misc.nav.previous'),
@@ -38,7 +38,7 @@ export default {
     if (!html.isBlank(slots.nextLink)) {
       previousNext.push(
         slots.nextLink.slots({
-          tooltip: true,
+          tooltipStyle: 'browser',
           color: false,
           attributes: {id: slots.id && 'next-button'},
           content: language.$('misc.nav.next'),
diff --git a/src/content/dependencies/linkThing.js b/src/content/dependencies/linkThing.js
index 2c3b0369..4c38c51d 100644
--- a/src/content/dependencies/linkThing.js
+++ b/src/content/dependencies/linkThing.js
@@ -36,9 +36,9 @@ export default {
       default: false,
     },
 
-    tooltip: {
-      validate: v => v.anyOf(v.isBoolean, v.isHTML),
-      default: false,
+    tooltipStyle: {
+      validate: v => v.is('none', 'browser'),
+      default: 'none',
     },
 
     color: {
@@ -69,10 +69,19 @@ export default {
     const path =
       slots.path ?? data.path;
 
-    const name =
+    const showShortName =
       (slots.preferShortName
-        ? data.nameShort ?? data.name ?? null
-        : data.name ?? null);
+        ? data.nameShort && data.nameShort !== data.name
+        : false);
+
+    const name =
+      (showShortName
+        ? data.nameShort
+        : data.name);
+
+    if (slots.tooltipStyle === 'browser') {
+      attributes.add('title', data.name);
+    }
 
     const content =
       (html.isBlank(slots.content)
@@ -91,19 +100,11 @@ export default {
       attributes.add(colorStyle);
     }
 
-    let tooltip = null;
-    if (slots.tooltip === true) {
-      tooltip = name;
-    } else if (typeof slots.tooltip === 'string') {
-      tooltip = slots.tooltip;
-    }
-
     return relations.linkTemplate
       .slots({
         path: slots.anchor ? [] : path,
         href: slots.anchor ? '' : null,
         content,
-        tooltip,
         attributes,
         hash: slots.hash,
         linkless: slots.linkless,
diff --git a/tap-snapshots/test/snapshot/generateAlbumSecondaryNav.js.test.cjs b/tap-snapshots/test/snapshot/generateAlbumSecondaryNav.js.test.cjs
index 6ffdfaa4..f2b51cb5 100644
--- a/tap-snapshots/test/snapshot/generateAlbumSecondaryNav.js.test.cjs
+++ b/tap-snapshots/test/snapshot/generateAlbumSecondaryNav.js.test.cjs
@@ -9,11 +9,11 @@ exports[`test/snapshot/generateAlbumSecondaryNav.js > TAP > generateAlbumSeconda
 <nav id="secondary-nav" class="nav-links-groups">
     <span style="--primary-color: #abcdef">
         <a href="group/vcg/">VCG</a>
-        (<a href="album/first/" title="First">Previous</a>, <a href="album/last/" title="Last">Next</a>)
+        (<a title="First" href="album/first/">Previous</a>, <a title="Last" href="album/last/">Next</a>)
     </span>
     <span style="--primary-color: #123456">
         <a href="group/bepis/">Bepis</a>
-        (<a href="album/second/" title="Second">Next</a>)
+        (<a title="Second" href="album/second/">Next</a>)
     </span>
 </nav>
 `
diff --git a/tap-snapshots/test/snapshot/generatePreviousNextLinks.js.test.cjs b/tap-snapshots/test/snapshot/generatePreviousNextLinks.js.test.cjs
index ed7b882a..b2c4c647 100644
--- a/tap-snapshots/test/snapshot/generatePreviousNextLinks.js.test.cjs
+++ b/tap-snapshots/test/snapshot/generatePreviousNextLinks.js.test.cjs
@@ -6,13 +6,13 @@
  */
 'use strict'
 exports[`test/snapshot/generatePreviousNextLinks.js > TAP > generatePreviousNextLinks (snapshot) > basic behavior 1`] = `
-previous: { tooltip: true, color: false, attributes: { id: 'previous-button' }, content: Tag (no name, 1 items) }
-next: { tooltip: true, color: false, attributes: { id: 'next-button' }, content: Tag (no name, 1 items) }
+previous: { tooltipStyle: 'browser', color: false, attributes: { id: 'previous-button' }, content: Tag (no name, 1 items) }
+next: { tooltipStyle: 'browser', color: false, attributes: { id: 'next-button' }, content: Tag (no name, 1 items) }
 `
 
 exports[`test/snapshot/generatePreviousNextLinks.js > TAP > generatePreviousNextLinks (snapshot) > disable id 1`] = `
-previous: { tooltip: true, color: false, attributes: { id: false }, content: Tag (no name, 1 items) }
-next: { tooltip: true, color: false, attributes: { id: false }, content: Tag (no name, 1 items) }
+previous: { tooltipStyle: 'browser', color: false, attributes: { id: false }, content: Tag (no name, 1 items) }
+next: { tooltipStyle: 'browser', color: false, attributes: { id: false }, content: Tag (no name, 1 items) }
 `
 
 exports[`test/snapshot/generatePreviousNextLinks.js > TAP > generatePreviousNextLinks (snapshot) > neither link present 1`] = `
@@ -20,9 +20,9 @@ exports[`test/snapshot/generatePreviousNextLinks.js > TAP > generatePreviousNext
 `
 
 exports[`test/snapshot/generatePreviousNextLinks.js > TAP > generatePreviousNextLinks (snapshot) > next missing 1`] = `
-previous: { tooltip: true, color: false, attributes: { id: 'previous-button' }, content: Tag (no name, 1 items) }
+previous: { tooltipStyle: 'browser', color: false, attributes: { id: 'previous-button' }, content: Tag (no name, 1 items) }
 `
 
 exports[`test/snapshot/generatePreviousNextLinks.js > TAP > generatePreviousNextLinks (snapshot) > previous missing 1`] = `
-next: { tooltip: true, color: false, attributes: { id: 'next-button' }, content: Tag (no name, 1 items) }
+next: { tooltipStyle: 'browser', color: false, attributes: { id: 'next-button' }, content: Tag (no name, 1 items) }
 `
diff --git a/tap-snapshots/test/snapshot/linkThing.js.test.cjs b/tap-snapshots/test/snapshot/linkThing.js.test.cjs
index 414bad16..114116ee 100644
--- a/tap-snapshots/test/snapshot/linkThing.js.test.cjs
+++ b/tap-snapshots/test/snapshot/linkThing.js.test.cjs
@@ -32,8 +32,7 @@ exports[`test/snapshot/linkThing.js > TAP > linkThing (snapshot) > tags in name
 
 exports[`test/snapshot/linkThing.js > TAP > linkThing (snapshot) > tooltip & content 1`] = `
 <a href="album/beyond-canon/">Beyond Canon</a>
-<a href="album/beyond-canon/" title="Beyond Canon">Beyond Canon</a>
-<a href="album/beyond-canon/" title="Beyond Canon">Next</a>
-<a href="album/beyond-canon/" title="Apple">Banana</a>
+<a title="Beyond Canon" href="album/beyond-canon/">Beyond Canon</a>
+<a title="Beyond Canon" href="album/beyond-canon/">Next</a>
 <a href="album/beyond-canon/">Banana</a>
 `
diff --git a/test/snapshot/linkThing.js b/test/snapshot/linkThing.js
index 195d8c0e..5aaf99ca 100644
--- a/test/snapshot/linkThing.js
+++ b/test/snapshot/linkThing.js
@@ -34,10 +34,9 @@ testContentFunctions(t, 'linkThing (snapshot)', async (t, evaluate) => {
       name: 'Beyond Canon',
     }],
     multiple: [
-      {slots: {tooltip: false}},
-      {slots: {tooltip: true}},
-      {slots: {tooltip: true, content: 'Next'}},
-      {slots: {tooltip: 'Apple', content: 'Banana'}},
+      {slots: {tooltipStyle: 'none'}},
+      {slots: {tooltipStyle: 'browser'}},
+      {slots: {tooltipStyle: 'browser', content: 'Next'}},
       {slots: {content: 'Banana'}},
     ],
   });