communication fix
This commit is contained in:
@ -1,14 +1,22 @@
|
||||
import { createElement } from "../functions";
|
||||
// import { global } from "../utility";
|
||||
|
||||
function setTooltip(container, content, flag = false) {
|
||||
const tip = container.querySelector('.tooltip-wrapper');
|
||||
if (tip != null) {
|
||||
tip.remove();
|
||||
function setTooltip(container, content, flag = false, parent = null) {
|
||||
const isParent = parent instanceof HTMLElement;
|
||||
if (isParent) {
|
||||
const tipid = container.dataset.tipId;
|
||||
const tip = parent.querySelector(`.tooltip-wrapper[data-tip-id="${tipid}"]`);
|
||||
tip?.remove();
|
||||
} else {
|
||||
const tip = container.querySelector('.tooltip-wrapper');
|
||||
tip?.remove();
|
||||
}
|
||||
const wrapper = createElement('div', wrapper => {
|
||||
wrapper.className = 'tooltip-wrapper tooltip-color';
|
||||
wrapper.style.visibility = 'hidden';
|
||||
wrapper.style.opacity = 0;
|
||||
wrapper.style.top = '0';
|
||||
wrapper.style.left = '0';
|
||||
},
|
||||
createElement('div', 'tooltip-pointer tooltip-color'),
|
||||
createElement('div', 'tooltip-curtain tooltip-color'),
|
||||
@ -22,7 +30,14 @@ function setTooltip(container, content, flag = false) {
|
||||
})
|
||||
);
|
||||
// container.insertAdjacentElement('afterend', wrapper);
|
||||
container.appendChild(wrapper);
|
||||
if (isParent) {
|
||||
const tipId = String(Math.random()).substring(2);
|
||||
container.dataset.tipId = tipId;
|
||||
wrapper.dataset.tipId = tipId;
|
||||
parent.appendChild(wrapper);
|
||||
} else {
|
||||
container.appendChild(wrapper);
|
||||
}
|
||||
|
||||
let tid;
|
||||
container.addEventListener('mouseenter', () => {
|
||||
@ -36,19 +51,27 @@ function setTooltip(container, content, flag = false) {
|
||||
}
|
||||
if (!flag || c.scrollWidth > c.offsetWidth) {
|
||||
tid = setTimeout(() => {
|
||||
let parent = c;
|
||||
let left = c.offsetLeft;
|
||||
let top = c.offsetTop;
|
||||
while ((parent = parent.offsetParent) != null) {
|
||||
left += parent.offsetLeft;
|
||||
top += parent.offsetTop;
|
||||
let p;
|
||||
let left;
|
||||
let top;
|
||||
left = c.offsetLeft;
|
||||
top = c.offsetTop;
|
||||
if (isParent) {
|
||||
p = c.offsetParent;
|
||||
while (p != null && p !== parent) {
|
||||
left += p.offsetLeft;
|
||||
top += p.offsetTop;
|
||||
p = p.offsetParent;
|
||||
}
|
||||
}
|
||||
parent = c;
|
||||
while ((parent = parent.parentElement) != null) {
|
||||
left -= parent.scrollLeft;
|
||||
top -= parent.scrollTop;
|
||||
p = c.parentElement;
|
||||
const offsetParent = c.offsetParent;
|
||||
while (p != null && p !== (isParent ? parent : offsetParent)) {
|
||||
left -= p.scrollLeft;
|
||||
top -= p.scrollTop;
|
||||
p = p.parentElement;
|
||||
}
|
||||
left -= wrapper.offsetWidth / 2 - c.offsetWidth / 2;
|
||||
left += (c.offsetWidth - wrapper.offsetWidth) / 2;
|
||||
top -= wrapper.offsetHeight + 14;
|
||||
wrapper.style.left = `${left}px`;
|
||||
wrapper.style.top = `${top}px`;
|
||||
|
Reference in New Issue
Block a user