From 816f4cd8facff9fe0742a361d397a678eba4c648 Mon Sep 17 00:00:00 2001 From: Solomon Victorino Date: Wed, 10 Apr 2024 13:30:45 -0600 Subject: [PATCH] fix: don't collapse annotations for clicked lyrics elsewhere on page --- static/script.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/static/script.js b/static/script.js index 686b6a8..a9018a7 100644 --- a/static/script.js +++ b/static/script.js @@ -24,8 +24,9 @@ window.addEventListener("load", () => { function getAnnotation(e) { e.preventDefault() //document.querySelector('.annotation')?.remove() - const uri = e.target.parentElement.getAttribute("href") - const presentAnnotation = document.getElementById(uri) + const link = e.target.parentElement + const uri = link.getAttribute("href") + const presentAnnotation = link.nextElementSibling.matches(".annotation") && link.nextElementSibling if (presentAnnotation) { presentAnnotation.remove() return @@ -41,8 +42,8 @@ function getAnnotation(e) { annotationDiv.innerHTML = parsedReponse.html annotationDiv.id = uri annotationDiv.className = "annotation" - if (!document.getElementById(uri)) { - e.target.parentElement.insertAdjacentElement('afterend', annotationDiv) + if (!link.nextElementSibling.matches(".annotation")) { + link.insertAdjacentElement('afterend', annotationDiv) } } }