Skip to content

Commit 6c8171e

Browse files
committed
feat(docs): switch glossary to hover/click/tap popover tooltips
1 parent a31d6fd commit 6c8171e

5 files changed

Lines changed: 25 additions & 23 deletions

File tree

‎docs/.vitepress/theme/custom.css‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@
4141
--vp-button-brand-active-text: #111111;
4242
}
4343

44-
/* Tooltips from markdown-it-glossary render as plain <abbr title>. Make them discoverable. */
45-
abbr[title] {
44+
/* Glossary terms render as plain <abbr title>. Underline them so they are discoverable;
45+
the pointer cursor comes from enableGlossaryTooltips(). Selecting on `abbr` alone, not
46+
`abbr[title]`, keeps the underline while a popover is open (the title is lifted then). */
47+
abbr {
4648
text-decoration: underline dotted;
4749
text-underline-offset: 3px;
48-
cursor: help;
4950
}
5051

5152
.vp-doc img {

‎docs/.vitepress/theme/index.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import DefaultTheme from 'vitepress/theme';
22
import type { Theme } from 'vitepress';
33
import { registerMarkdownTags } from '@binarynoir/vitepress-markdown-tags/theme';
44
import '@binarynoir/vitepress-markdown-tags/style.css';
5-
import { enableGlossaryTouch } from 'markdown-it-glossary/client';
5+
import { enableGlossaryTooltips } from 'markdown-it-glossary/client';
66
import './custom.css';
77

88
export default {
99
extends: DefaultTheme,
1010
enhanceApp({ app }) {
1111
// Registers the <MarkdownTag> component that ((tag|...)) compiles to.
1212
registerMarkdownTags(app);
13-
// Tap a glossary term to see its definition on touch screens, where hover doesn't exist.
14-
enableGlossaryTouch();
13+
// Glossary definitions in a popover on hover, click and tap (title tooltips never show on touch screens).
14+
enableGlossaryTooltips();
1515
},
1616
} satisfies Theme;

‎docs/plugins/glossary.md‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,32 +38,33 @@ export default defineConfig({
3838

3939
Or wrap the config with `withGlossary` from `markdown-it-glossary/vitepress`. It plays nicely with other `withX()` wrappers.
4040

41-
### Touch devices
41+
### Hover, click and tap
4242

43-
`<abbr title>` tooltips only appear on hover, so they never show on a phone or tablet. Call `enableGlossaryTouch()` once in the browser and tapping a term shows its definition in a small popover instead. Tapping elsewhere, scrolling, or pressing Escape dismisses it. It only activates on devices that can't hover, so desktop keeps the native tooltip.
43+
`<abbr title>` tooltips need a mouse hover, so they never show on a phone or tablet. Call `enableGlossaryTooltips()` once in the browser and every term gets a small popover that works with any input: hover a term with a mouse (click to pin it open), or tap it on a touch screen. Tap the term again, tap elsewhere, scroll, or press Escape to dismiss it. While the popover is open the term's `title` is lifted so the browser's own tooltip doesn't show on top of it, then restored.
4444

4545
In VitePress, call it from your theme's `enhanceApp`:
4646

4747
```ts
4848
// .vitepress/theme/index.ts
4949
import DefaultTheme from 'vitepress/theme';
50-
import { enableGlossaryTouch } from 'markdown-it-glossary/client';
50+
import { enableGlossaryTooltips } from 'markdown-it-glossary/client';
5151

5252
export default {
5353
extends: DefaultTheme,
5454
enhanceApp() {
55-
enableGlossaryTouch();
55+
enableGlossaryTooltips();
5656
},
5757
};
5858
```
5959

6060
| Option | Default | Description |
6161
| -------------- | --------------- | ------------------------------------------------------------------------------ |
6262
| `selector` | `'abbr[title]'` | Which elements carry a definition in their `title`. |
63-
| `touchOnly` | `true` | Only activate on devices that can't hover. `false` also enables it on desktop. |
63+
| `hover` | `true` | Show on mouse hover too. `false` for click and tap only. |
64+
| `touchOnly` | `false` | Respond to touch input only, leaving mouse users the native tooltip. |
6465
| `injectStyles` | `true` | Inject the default popover styles. `false` lets you style `.glossary-popover`. |
6566

66-
The default look follows VitePress theme colors and can be overridden with the `--glossary-popover-bg`, `--glossary-popover-fg`, and `--glossary-popover-border` CSS variables. `enableGlossaryTouch()` returns a function that removes its listeners.
67+
The default look follows VitePress theme colors and can be overridden with the `--glossary-popover-bg`, `--glossary-popover-fg`, and `--glossary-popover-border` CSS variables. `enableGlossaryTooltips()` returns a function that removes its listeners.
6768

6869
## Writing the glossary file
6970

@@ -126,6 +127,6 @@ The same syntax works on a page that has _not_ opted out. A page-local definitio
126127
| `headingLevel` | `3` | Heading level that marks a term. |
127128
| `frontmatterKey` | `'glossary'` | Frontmatter key for the opt-out. `false` disables it. |
128129

129-
The plugin emits plain `<abbr title>` tags and injects no CSS. This site adds a dotted underline and a help cursor in its theme so the tooltips are discoverable.
130+
The plugin itself emits plain `<abbr title>` tags and injects no CSS. This site adds a dotted underline in its theme so the terms are discoverable, and `enableGlossaryTooltips()` adds the popover and a pointer cursor.
130131

131132
[Source and full README on GitHub](https://github.com/binarynoir/markdown-it-glossary)

‎package-lock.json‎

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
"@binarynoir/vitepress-auto-sidebar": "^0.4.10",
2929
"@binarynoir/vitepress-downloads": "^0.1.1",
3030
"@binarynoir/vitepress-markdown-tags": "^0.2.3",
31-
"@binarynoir/vitepress-reading-time-tag": "^0.1.4",
31+
"@binarynoir/vitepress-reading-time-tag": "^0.1.5",
3232
"@types/node": "^24.19.1",
33-
"markdown-it-glossary": "^0.3.5",
33+
"markdown-it-glossary": "^0.3.6",
3434
"prettier": "^3.9.9",
3535
"vitepress": "2.0.0-alpha.20"
3636
}

0 commit comments

Comments
 (0)