Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quantum-kittens
GitHub Repository: quantum-kittens/platypus
Path: blob/main/frontend/ts/notations.ts
3855 views
1
import { translate } from './translations'
2
3
let notations = {}
4
5
const injectTooltip = function (eq, target) {
6
if (eq) {
7
target.classList.add('q-math-notation')
8
9
// create Tooltip structure
10
const tooltip = document.createElement('div')
11
const tooltipContent = document.createElement('div')
12
tooltip.appendChild(tooltipContent);
13
tooltip.className += 'qv-tooltip'
14
tooltipContent.className += 'qv-tooltip__content'
15
16
// add tooltip data
17
tooltipContent.innerHTML = ''
18
if (eq.say) {
19
tooltipContent.innerHTML += `
20
<h3 class="qv-tooltip__title">${translate('How to read this')}:</h3>
21
<p>${eq.say}</p>
22
`
23
}
24
if (eq.meaning) {
25
tooltipContent.innerHTML += `
26
<h3 class="qv-tooltip__title">${translate('What it means')}:</h3><p>
27
${eq.meaning}</p>
28
`
29
}
30
if (eq.type) {
31
tooltipContent.innerHTML += `
32
<h3 class="qv-tooltip__title">${translate('Type')}:</h3><p>
33
${eq.type}</p>
34
`
35
}
36
37
target.appendChild(tooltip)
38
}
39
}
40
41
const loadNotations = function () {
42
if (!Object.keys(notations).length) {
43
const elt = document.getElementById('notations')
44
if (elt && elt.textContent) {
45
notations = JSON.parse(elt.textContent)
46
}
47
}
48
49
return notations
50
}
51
52
const initNotations = function () {
53
loadNotations()
54
for (const key in notations) {
55
const target = document.getElementById(key)
56
if (target) {
57
injectTooltip(notations[key], target)
58
} else {
59
const targets = document.querySelectorAll(`mjx-container .${key}`)
60
for (let t of targets) {
61
injectTooltip(notations[key], t)
62
}
63
}
64
}
65
}
66
67
export {
68
loadNotations,
69
initNotations
70
}
71
72