-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
47 lines (44 loc) · 1.19 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const style = `
.tooltip { width: 16px;
height: 16px;
border-radius: 10px;
border: 2px solid #000;
background: rgba(0, 0, 0, .5);
display: inline;
margin: -8px;
}
`
const appendStyle = (text) => {
let styleEl = document.createElement('style')
styleEl.type = 'text/css'
styleEl.appendChild(document.createTextNode(text))
document.body.append(styleEl)
}
const overlay = (data, css) => {
document.addEventListener('DOMContentLoaded', () => {
appendStyle(style)
if (typeof css !== undefined) {
fetch(css)
.then(response => response.text())
.then(text => appendStyle(text))
}
//data is mandatory, so no checking for undefined
fetch(data)
.then((response) => response.text())
.then((text) =>
{
const doc = jsyaml.load(text)
console.log(doc)
for (let tip of doc) {
let el = document.querySelector(tip.sel)
let div = document.createElement('div')
div.appendChild(document.createTextNode(tip.txt))
div.classList.add("tooltip")
el.parentNode.insertBefore(div, el.nextSibling)
}
})
})
}
//get file
//when complete, eval file
//append style