Lazily apply tooltip calculations
This commit is contained in:
parent
d71f046f53
commit
0a83c00c78
@ -245,33 +245,42 @@ export default class AnimeNotifier {
|
|||||||
let contentRect = this.app.content.getBoundingClientRect()
|
let contentRect = this.app.content.getBoundingClientRect()
|
||||||
|
|
||||||
for(let element of elements) {
|
for(let element of elements) {
|
||||||
Diff.mutations.queue(() => {
|
element.onmouseenter = () => {
|
||||||
let rect = element.getBoundingClientRect()
|
if(element.dataset.offsetAssigned) {
|
||||||
let tipStyle = window.getComputedStyle(element, ":before")
|
element.onmouseenter = null
|
||||||
let tipWidth = parseInt(tipStyle.width) + parseInt(tipStyle.paddingLeft) * 2
|
return
|
||||||
let tipStartX = rect.left + rect.width / 2 - tipWidth / 2 - contentRect.left
|
|
||||||
let tipEndX = tipStartX + tipWidth
|
|
||||||
let leftOffset = 0
|
|
||||||
|
|
||||||
if(tipStartX < 0) {
|
|
||||||
leftOffset = -tipStartX + 5
|
|
||||||
} else if(tipEndX > contentRect.width) {
|
|
||||||
leftOffset = -(tipEndX - contentRect.width + 5)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(leftOffset !== 0) {
|
Diff.mutations.queue(() => {
|
||||||
element.classList.remove("tip")
|
let rect = element.getBoundingClientRect()
|
||||||
element.classList.add("tip-offset-root")
|
let tipStyle = window.getComputedStyle(element, ":before")
|
||||||
|
let tipWidth = parseInt(tipStyle.width) + parseInt(tipStyle.paddingLeft) * 2
|
||||||
|
let tipStartX = rect.left + rect.width / 2 - tipWidth / 2 - contentRect.left
|
||||||
|
let tipEndX = tipStartX + tipWidth
|
||||||
|
let leftOffset = 0
|
||||||
|
|
||||||
let tipChild = document.createElement("div")
|
if(tipStartX < 0) {
|
||||||
tipChild.classList.add("tip-offset-child")
|
leftOffset = -tipStartX + 5
|
||||||
tipChild.setAttribute("aria-label", element.getAttribute("aria-label"))
|
} else if(tipEndX > contentRect.width) {
|
||||||
tipChild.style.left = Math.round(leftOffset) + "px"
|
leftOffset = -(tipEndX - contentRect.width + 5)
|
||||||
tipChild.style.width = rect.width + "px"
|
}
|
||||||
tipChild.style.height = rect.height + "px"
|
|
||||||
element.appendChild(tipChild)
|
if(leftOffset !== 0) {
|
||||||
}
|
element.classList.remove("tip")
|
||||||
})
|
element.classList.add("tip-offset-root")
|
||||||
|
|
||||||
|
let tipChild = document.createElement("div")
|
||||||
|
tipChild.classList.add("tip-offset-child")
|
||||||
|
tipChild.setAttribute("aria-label", element.getAttribute("aria-label"))
|
||||||
|
tipChild.style.left = Math.round(leftOffset) + "px"
|
||||||
|
tipChild.style.width = rect.width + "px"
|
||||||
|
tipChild.style.height = rect.height + "px"
|
||||||
|
element.appendChild(tipChild)
|
||||||
|
}
|
||||||
|
|
||||||
|
element.dataset.offsetAssigned = "true"
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user