Skip to content

Commit

Permalink
Merge pull request #55 from sgvictorino/separately-toggle-dupe-annota…
Browse files Browse the repository at this point in the history
…tions

fix: don't collapse annotations for clicked lyrics elsewhere on page
  • Loading branch information
rramiachraf authored Apr 11, 2024
2 parents aac426d + 816f4cd commit e54ea8a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions static/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}
}
Expand Down

0 comments on commit e54ea8a

Please sign in to comment.