Skip to content

Commit

Permalink
IBX-1103: Remove tooltips when unneeded (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
GrabowskiM authored Feb 1, 2022
1 parent 2b6016c commit ae5cf34
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/bundle/Resources/public/js/scripts/helpers/tooltips.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
childList: true,
subtree: true,
};
const resizeEllipsisObserver = new ResizeObserver((entries) => {
entries.forEach((entry) => {
ibexa.helpers.tooltips.parse(entry.target);
});
});
const observer = new MutationObserver((mutationsList) => {
if (lastInsertTooltipTarget) {
mutationsList.forEach((mutation) => {
Expand Down Expand Up @@ -75,6 +80,31 @@

for (tooltipNode of tooltipNodes) {
if (tooltipNode.hasAttribute('title')) {
const hasEllipsisStyle = getComputedStyle(tooltipNode).textOverflow === 'ellipsis';

if (hasEllipsisStyle) {
resizeEllipsisObserver.observe(tooltipNode);

const isEllipsized = tooltipNode.scrollWidth > tooltipNode.offsetWidth;
const tooltipInstance = bootstrap.Tooltip.getInstance(tooltipNode);

if (tooltipInstance) {
if (!isEllipsized) {
tooltipInstance.dispose();
}

continue;
}

if (isEllipsized) {
if (tooltipNode.dataset.title) {
tooltipNode.title = tooltipNode.dataset.title;
}
} else {
continue;
}
}

const delay = {
show: parseInt(tooltipNode.dataset.delayShow, 10) ?? 150,
hide: parseInt(tooltipNode.dataset.delayHide, 10) ?? 75,
Expand Down

0 comments on commit ae5cf34

Please sign in to comment.