mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-04-27 14:57:35 +00:00

* Positioning terminology tooltip to be always fully visible #resolves https://github.com/home-assistant/home-assistant.io/issues/31341 * terminology_tooltip: removed debugs resolves7a0183402f (r1485840114)
* terminology_tooltip: removed $–convention from var names resolves7a0183402f (r1485839944)
* terminology_tooltip: let -> const --------- Co-authored-by: Joakim Sørensen <joasoe@gmail.com>
39 lines
1.3 KiB
JavaScript
39 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
[...document.getElementsByClassName('terminology')].forEach(terminology => {
|
|
const horizontalMargin = 20;
|
|
|
|
const topMargin = document
|
|
.getElementsByClassName('site-header')[0]
|
|
.clientHeight;
|
|
|
|
const tooltip = terminology.querySelector('.terminology-tooltip');
|
|
|
|
terminology.addEventListener('mouseenter', () => {
|
|
const tooltipRect = tooltip.getBoundingClientRect();
|
|
|
|
if (tooltipRect.top < topMargin) {
|
|
// doesn't fit on top -> moving to bottom
|
|
tooltip.classList.add('below');
|
|
}
|
|
|
|
let horizontalMove = 0;
|
|
|
|
if (tooltipRect.left < horizontalMargin) {
|
|
// doesn't fit on the left edge -> moving right
|
|
horizontalMove = Math.abs(tooltipRect.left) + horizontalMargin;
|
|
} else if (tooltipRect.right + horizontalMargin > window.innerWidth) {
|
|
// doesn't fit on the right edge -> moving left
|
|
horizontalMove = window.innerWidth - tooltipRect.right - horizontalMargin;
|
|
}
|
|
|
|
tooltip.style.setProperty('--horizontal-move', `${horizontalMove}px`);
|
|
});
|
|
|
|
terminology.addEventListener('mouseleave', () => {
|
|
// reset
|
|
tooltip.style.setProperty('--horizontal-move', '0px');
|
|
tooltip.classList.remove('below');
|
|
});
|
|
});
|