2024-11-04 07:14:52 -05:00
|
|
|
import { Tooltip } from 'bootstrap-5'
|
|
|
|
|
2024-11-08 10:07:01 -05:00
|
|
|
function getElementWidth(el: Element) {
|
|
|
|
const elComputedStyle = window.getComputedStyle(el)
|
|
|
|
const elPaddingX =
|
|
|
|
parseFloat(elComputedStyle.paddingLeft) +
|
|
|
|
parseFloat(elComputedStyle.paddingRight)
|
|
|
|
const elBorderX =
|
|
|
|
parseFloat(elComputedStyle.borderLeftWidth) +
|
|
|
|
parseFloat(elComputedStyle.borderRightWidth)
|
|
|
|
return el.scrollWidth - elPaddingX - elBorderX
|
|
|
|
}
|
|
|
|
|
2024-11-04 07:14:52 -05:00
|
|
|
const footerLanguageElement = document.querySelector(
|
|
|
|
'[data-ol-lang-selector-tooltip]'
|
|
|
|
) as Element
|
|
|
|
|
|
|
|
const allTooltips = document.querySelectorAll('[data-bs-toggle="tooltip"]')
|
|
|
|
|
2024-11-15 11:31:24 -05:00
|
|
|
const possibleBadgeTooltips = document.querySelectorAll('[data-badge-tooltip]')
|
2024-11-07 10:28:17 -05:00
|
|
|
|
2024-11-04 07:14:52 -05:00
|
|
|
// eslint-disable-next-line no-unused-vars
|
|
|
|
const footLangTooltip = new Tooltip(footerLanguageElement)
|
|
|
|
|
|
|
|
allTooltips.forEach(element => {
|
|
|
|
// eslint-disable-next-line no-unused-vars
|
|
|
|
const tooltip = new Tooltip(element)
|
|
|
|
})
|
2024-11-07 10:28:17 -05:00
|
|
|
|
2024-11-08 10:07:01 -05:00
|
|
|
possibleBadgeTooltips.forEach(element => {
|
2024-11-15 11:31:24 -05:00
|
|
|
// Put data-badge-tooltip on .badge-content
|
2024-11-08 10:07:01 -05:00
|
|
|
// then tooltip is only shown if content is clipped due to max-width on .badge
|
|
|
|
// Due to font loading, the width calculated on page load might change, so we might
|
|
|
|
// incorrectly determine a tooltip is not needed. This is why max-width will always be set to none
|
|
|
|
// if no tooltip is shown so that content is fully visible in those scenarios.
|
|
|
|
|
|
|
|
if (element.parentElement) {
|
|
|
|
const parentWidth = getElementWidth(element.parentElement)
|
|
|
|
if (element.scrollWidth > parentWidth) {
|
|
|
|
// eslint-disable-next-line no-unused-vars
|
|
|
|
const tooltip = new Tooltip(element)
|
|
|
|
} else {
|
|
|
|
element.parentElement.style.maxWidth = 'none'
|
|
|
|
}
|
2024-11-07 10:28:17 -05:00
|
|
|
}
|
|
|
|
})
|