mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-05 04:53:01 +00:00
feat: check if text is ellipsised before attaching tooltip
This commit is contained in:
committed by
Mungai Njoroge
parent
eb8c4e5628
commit
1c3998aa25
+45
-30
@@ -46,41 +46,56 @@ function hideTooltip() {
|
|||||||
tooltip.style.visibility = "hidden";
|
tooltip.style.visibility = "hidden";
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
function getFullWidth(el: HTMLElement) {
|
||||||
mounted(el: HTMLElement, binding) {
|
// display el as inline-block to get the correct width
|
||||||
if (!tooltip) {
|
el.style.display = "inline-block";
|
||||||
tooltip = getTooltip();
|
el.style.visibility = "hidden";
|
||||||
}
|
document.getElementsByTagName("body")[0].appendChild(el);
|
||||||
|
const width = el.offsetWidth;
|
||||||
|
el.remove();
|
||||||
|
|
||||||
if (!popperInstance) {
|
return width;
|
||||||
popperInstance = getInstance() as Instance;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let isHovered = false;
|
export default (el: HTMLElement) => {
|
||||||
|
const fullWidth = getFullWidth(el.cloneNode(true) as HTMLElement);
|
||||||
|
if (fullWidth <= el.offsetWidth) return;
|
||||||
|
|
||||||
el.addEventListener("mouseover", () => {
|
if (!tooltip) {
|
||||||
isHovered = true;
|
tooltip = getTooltip();
|
||||||
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
if (!popperInstance) {
|
||||||
if (!isHovered) return;
|
popperInstance = getInstance() as Instance;
|
||||||
tooltip.innerText = el.innerText;
|
}
|
||||||
|
|
||||||
virtualEl.getBoundingClientRect = () => el.getBoundingClientRect();
|
let isHovered = false;
|
||||||
popperInstance.update().then(showTooltip);
|
|
||||||
}, 1500);
|
el.addEventListener("mouseover", () => {
|
||||||
|
isHovered = true;
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
if (!isHovered) return;
|
||||||
|
tooltip.innerText = el.innerText;
|
||||||
|
|
||||||
|
virtualEl.getBoundingClientRect = () => el.getBoundingClientRect();
|
||||||
|
popperInstance.update().then(showTooltip);
|
||||||
|
}, 1500);
|
||||||
|
});
|
||||||
|
|
||||||
|
["mouseout", "click"].forEach((event) => {
|
||||||
|
document.addEventListener(event, () => {
|
||||||
|
isHovered = false;
|
||||||
|
hideTooltip();
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
["mouseout", "click"].forEach((event) => {
|
// } as Directive;
|
||||||
document.addEventListener(event, () => {
|
|
||||||
isHovered = false;
|
|
||||||
hideTooltip();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
beforeUnmount(el: HTMLElement) {
|
|
||||||
hideTooltip();
|
|
||||||
|
|
||||||
el.removeEventListener("mouseover", () => {});
|
// beforeUnmount(el: HTMLElement) {
|
||||||
el.removeEventListener("mouseout", () => {});
|
// // hideTooltip();
|
||||||
},
|
|
||||||
} as Directive;
|
// el.removeEventListener("mouseover", () => {});
|
||||||
|
// el.removeEventListener("mouseout", () => {});
|
||||||
|
// },
|
||||||
|
|||||||
Reference in New Issue
Block a user