summaryrefslogtreecommitdiff
path: root/assets/js/tooltip.js
diff options
context:
space:
mode:
authoreltrac <hi@eltr.ac>2026-04-07 14:53:17 +0800
committereltrac <hi@eltr.ac>2026-04-07 14:53:17 +0800
commit10431bd8f5ff71690ae4e5444e8d7894fd401ae5 (patch)
tree62b7fd1b6c1f68d2804f380eb522bcebeb2c8d9f /assets/js/tooltip.js
parent3e0edacc4a0cafa53ede57ebb6f0378c93f3123b (diff)
chore: move templates out of site repo
Diffstat (limited to 'assets/js/tooltip.js')
-rw-r--r--assets/js/tooltip.js54
1 files changed, 0 insertions, 54 deletions
diff --git a/assets/js/tooltip.js b/assets/js/tooltip.js
deleted file mode 100644
index eea5b350..00000000
--- a/assets/js/tooltip.js
+++ /dev/null
@@ -1,54 +0,0 @@
-(() => {
- const allTooltipped = document.querySelectorAll('[data-tooltip]');
-
- const createOrUpdateTooltip = (element) => {
- const tooltipText = element.getAttribute('data-tooltip') || element.getAttribute('title');
-
- if (!tooltipText) return;
-
- let tooltipElement = element.querySelector('.__generated-tooltip');
- if (!tooltipElement) {
- element.classList.add('group', 'relative', 'tooltipped');
-
- tooltipElement = document.createElement('div');
- tooltipElement.classList.add(
- '__generated-tooltip',
- ...'absolute bottom-full left-1/2 transform -translate-x-1/2 translate-y-1 bg-black/80 text-white px-2.5 py-1.5 rounded text-xs whitespace-nowrap opacity-0 invisible transition-all duration-300 pointer-events-none mb-2 z-1000 group-hover:opacity-100 group-hover:visible group-hover:translate-y-0 dark:bg-white/90 dark:text-black'.split(' ')
- );
- element.appendChild(tooltipElement);
- }
-
- tooltipElement.textContent = tooltipText;
- };
-
- const observer = new IntersectionObserver((entries, obs) => {
- entries.forEach(entry => {
- if (!entry.isIntersecting) return;
-
- const element = entry.target;
- createOrUpdateTooltip(element);
-
- // listen to tooltip text changes
- const mutationObserver = new MutationObserver(mutations => {
- for (const mutation of mutations) {
- if (mutation.type === 'attributes' &&
- (mutation.attributeName === 'title' || mutation.attributeName === 'data-tooltip')) {
- createOrUpdateTooltip(element);
- }
- }
- });
-
- mutationObserver.observe(element, {
- attributes: true,
- attributeFilter: ['title', 'data-tooltip'],
- });
-
- obs.unobserve(element); // 不再需要 Intersection 监听
- });
- }, {
- rootMargin: '100px',
- threshold: 0.1,
- });
-
- allTooltipped.forEach(el => observer.observe(el));
-})();