From fb88fef6a71a23be9d4de2e0e4e9c3e5bd316a88 Mon Sep 17 00:00:00 2001 From: lelexia <1095883487@qq.com> Date: Tue, 27 Oct 2026 19:39:08 +0800 Subject: [PATCH] fix(docs): handle copy tooltip clicks --- docs/main.mjs | 17 ++++++++++------- docs/modules/playground.mjs | 10 ++++++---- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/docs/main.mjs b/docs/main.mjs index be70fa928..5c937ca2b 100644 --- a/docs/main.mjs +++ b/docs/main.mjs @@ -15,13 +15,16 @@ toggleOnClick('.docs-index', 'html', 'hamburger-active'); requestAnimationFrame(startAnimations); -document.querySelectorAll('.copy-icon').forEach(icon => { +document.querySelectorAll('.copy-icon').forEach((icon) => { icon.addEventListener('click', () => { icon.classList.add('copied'); - document.querySelector('.copied .tooltip').textContent = 'Copied!'; + + const tooltip = icon.querySelector('.tooltip'); + if (tooltip) tooltip.textContent = 'Copied!'; + setTimeout(() => { - icon.children[0].textContent = 'Copy class name to clipboard' - icon.classList.remove('copied') - }, 750) - }) -}) + icon.children[0].textContent = 'Copy class name to clipboard'; + icon.classList.remove('copied'); + }, 750); + }); +}); diff --git a/docs/modules/playground.mjs b/docs/modules/playground.mjs index 0237e7013..e759b4406 100644 --- a/docs/modules/playground.mjs +++ b/docs/modules/playground.mjs @@ -25,9 +25,9 @@ const playground = ( setEndListener(targetEl, target.replace('.', '')); containerEl.addEventListener('click', (e) => { - const el = e.target + const el = e.target; - if(el.classList.contains('animation-item--title')) { + if (el.classList.contains('animation-item--title')) { clearAll(items); const animation = `animate__${el.parentElement.getAttribute('data-animation')}`; @@ -36,8 +36,10 @@ const playground = ( document.documentElement.classList.remove('animationList-active'); } - if (el.classList.contains('copy-icon')) { - const animation = `animate__${el.parentElement.getAttribute('data-animation')}`; + const copyBtn = e.target.closest('.copy-icon'); + + if (copyBtn) { + const animation = `animate__${copyBtn.parentElement.getAttribute('data-animation')}`; navigator.clipboard.writeText(animation); } });