Skip to content

Commit a1a909b

Browse files
committed
Convert tooltip-body to vanilla
1 parent 5f9f097 commit a1a909b

File tree

3 files changed

+26
-25
lines changed

3 files changed

+26
-25
lines changed

assets/js/handlebars/templates/tooltip-body.handlebars

Lines changed: 0 additions & 17 deletions
This file was deleted.

assets/js/helpers.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,14 @@ export function el (tagName, attributes, children) {
220220
}
221221
return element
222222
}
223+
224+
/**
225+
* Create nodelist from HTML.
226+
*
227+
* @param {string} html
228+
*/
229+
export function nodesFromHtml (html) {
230+
const element = document.createElement('div')
231+
element.innerHTML = html
232+
return element.childNodes
233+
}

assets/js/tooltips/tooltips.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { qs, qsAll } from '../helpers'
1+
import { el, nodesFromHtml, qs, qsAll } from '../helpers'
22
import { settingsStore } from '../settings-store'
33
import { cancelHintFetchingIfAny, getHint, HINT_KIND, isValidHintHref } from './hints'
4-
import tooltipBodyTemplate from '../handlebars/templates/tooltip-body.handlebars'
54

65
const TOOLTIP_HTML = '<div class="tooltip"><div class="tooltip-body"></div></div>'
76

@@ -92,17 +91,25 @@ function handleHoverStart (event) {
9291
}
9392

9493
function renderTooltip (hint) {
95-
const tooltipBodyHtml = tooltipBodyTemplate({
96-
isPlain: hint.kind === HINT_KIND.plain,
97-
hint
98-
})
99-
10094
let tooltipBody = qs(TOOLTIP_BODY_SELECTOR)
10195
if (!tooltipBody) {
10296
qs(CONTENT_INNER_SELECTOR).insertAdjacentHTML('beforeend', TOOLTIP_HTML)
10397
tooltipBody = qs(TOOLTIP_BODY_SELECTOR)
10498
}
105-
tooltipBody.innerHTML = tooltipBodyHtml
99+
tooltipBody.replaceChildren(...(
100+
hint.kind === HINT_KIND.plain
101+
? [el('section', {class: 'docstring docstring-plain'}, [hint.description])]
102+
: [
103+
el('div', {class: 'detail-header'}, [
104+
el('h1', {class: 'signature'}, [
105+
el('span', {translate: 'no'}, [hint.title]),
106+
el('div', {class: 'version-info', translate: 'no'}, [hint.version])
107+
])
108+
]),
109+
hint.description &&
110+
el('section', {class: 'docstring'}, nodesFromHtml(hint.description))
111+
].filter(Boolean)
112+
))
106113

107114
updateTooltipPosition()
108115

0 commit comments

Comments
 (0)