Files
overleaf-cep/services/web/frontend/js/features/tooltip/index.ts
Rebeka Dekany c9a1ecd060 Remove Bootstrap version 3 (#27420)
* Remove bootstrap-3 entrypoint

* Rename bootstrap-5 entrypoint to bootstrap

* Restore entrypoints

* Remove `bootstrap-5` and `bootstrap-3` entrypoints and a single `bootstrap.ts` file is now the default entrypoint

* Update `bootstrap-5` component imports to `bootstrap`

* Update `bootstrap-5` CSS imports to `bootstrap`

* Remove the `isBootstrap5` utility

* Remove `bootstrapVersion`

* Remove `ol-bootstrapVersion`

* Remove getCssThemeModifier

* Update path and rename

* Source format

* Remove Bootstrap v3 and Bootstrap v5 alias npm packages

* Remove bootstrap argument

* Remove unused files

* Update with the latest split tests

* Remove remaining bootstrap5PageStatus

* Update path

GitOrigin-RevId: 7acda2f80114d2de8699e1f06729a2a29218e284
2025-08-08 08:06:00 +00:00

46 lines
1.6 KiB
TypeScript

import { Tooltip } from 'bootstrap'
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
}
const footerLanguageElement = document.querySelector(
'[data-ol-lang-selector-tooltip]'
) as Element
if (footerLanguageElement) {
// eslint-disable-next-line no-new
new Tooltip(footerLanguageElement)
}
const allTooltips = document.querySelectorAll('[data-bs-toggle="tooltip"]')
allTooltips.forEach(element => {
// eslint-disable-next-line no-new
new Tooltip(element)
})
const possibleBadgeTooltips = document.querySelectorAll('[data-badge-tooltip]')
possibleBadgeTooltips.forEach(element => {
// Put data-badge-tooltip on .badge-content
// 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-new
new Tooltip(element)
} else {
element.parentElement.style.maxWidth = 'none'
}
}
})