add jsdoc comments
This commit is contained in:
1 parent
6de354ad47
commit
8c1205bc13
24 files changed
+1228
-425
No files matched your search
+32
-11
@@ -4,7 +4,16 @@ import { global } from '../utility';
|
||||
|
||||
const pointerHeight = 12;
|
||||
|
||||
export function setTooltip(container, content, flag = false, parent = null, maxLeft = null) {
|
||||
/**
|
||||
*
|
||||
* @param {HTMLElement} container
|
||||
* @param {string | HTMLElement} content
|
||||
* @param {boolean} [flag]
|
||||
* @param {HTMLElement} [parent]
|
||||
* @param {(left: number) => number} [maxLeft]
|
||||
* @returns
|
||||
*/
|
||||
export function setTooltip(container, content, flag = false, parent, maxLeft) {
|
||||
const isParent = parent instanceof HTMLElement;
|
||||
if (isParent) {
|
||||
const tipid = container.dataset.tipId;
|
||||
@@ -43,11 +52,13 @@ export function setTooltip(container, content, flag = false, parent = null, maxL
|
||||
container.appendChild(wrapper);
|
||||
}
|
||||
|
||||
/** @type {number} */
|
||||
let tid;
|
||||
container.addEventListener('mouseenter', () => {
|
||||
tid && clearTimeout(tid);
|
||||
/** @type {HTMLElement | null} */
|
||||
let c = container;
|
||||
while (c?.offsetWidth == null) {
|
||||
while (c != null && c.offsetWidth == null) {
|
||||
c = c.parentElement;
|
||||
}
|
||||
if (c == null) {
|
||||
@@ -56,17 +67,16 @@ export function setTooltip(container, content, flag = false, parent = null, maxL
|
||||
if (!flag || c.scrollWidth > c.offsetWidth) {
|
||||
wrapper.style.cssText += 'left: -9999px; top: -9999px; display: block';
|
||||
tid = setTimeout(() => {
|
||||
/** @type {HTMLElement | null} */
|
||||
let p;
|
||||
let left;
|
||||
let top;
|
||||
left = c.offsetLeft;
|
||||
top = c.offsetTop;
|
||||
let left = c.offsetLeft;
|
||||
let top = c.offsetTop;
|
||||
if (isParent) {
|
||||
p = c.offsetParent;
|
||||
p = /** @type {HTMLElement} */ (c.offsetParent);
|
||||
while (p != null && p !== parent) {
|
||||
left += p.offsetLeft;
|
||||
top += p.offsetTop;
|
||||
p = p.offsetParent;
|
||||
p = /** @type {HTMLElement} */ (p.offsetParent);
|
||||
}
|
||||
}
|
||||
p = c.parentElement;
|
||||
@@ -92,7 +102,7 @@ export function setTooltip(container, content, flag = false, parent = null, maxL
|
||||
// check overflow
|
||||
let t = c.offsetTop;
|
||||
let l = c.offsetLeft;
|
||||
p = c.offsetParent;
|
||||
p = /** @type {HTMLElement} */ (c.offsetParent);
|
||||
if (p == null) {
|
||||
return;
|
||||
}
|
||||
@@ -105,7 +115,7 @@ export function setTooltip(container, content, flag = false, parent = null, maxL
|
||||
}
|
||||
t += p.offsetTop;
|
||||
l += p.offsetLeft;
|
||||
const parent = p.offsetParent;
|
||||
const parent = /** @type {HTMLElement} */ (p.offsetParent);
|
||||
while (p != null) {
|
||||
const w = p.clientWidth;
|
||||
if (w < lastWidth) {
|
||||
@@ -171,16 +181,27 @@ export function setTooltip(container, content, flag = false, parent = null, maxL
|
||||
tid && clearTimeout(tid);
|
||||
tid = setTimeout(() => {
|
||||
wrapper.style.visibility = 'hidden';
|
||||
wrapper.style.opacity = 0;
|
||||
wrapper.style.opacity = '0';
|
||||
tid = setTimeout(() => wrapper.style.display = 'none', 120);
|
||||
}, 300);
|
||||
});
|
||||
return container;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {HTMLElement} [container]
|
||||
* @returns {HTMLElement}
|
||||
* @example
|
||||
* ```
|
||||
* <span title="tooltip text"></span>
|
||||
* ```
|
||||
*/
|
||||
export function resolveTooltip(container = document.body) {
|
||||
const tips = container.querySelectorAll('[title]');
|
||||
for (let tip of tips) {
|
||||
if (!(tip instanceof HTMLElement)) {
|
||||
continue;
|
||||
}
|
||||
const title = tip.getAttribute('title');
|
||||
if (title != null) {
|
||||
tip.removeAttribute('title');
|
||||
|
||||
Reference in new issue
Block a user