From 2075caf0d0b4e950eb7ba46a7c2f4100f7337163 Mon Sep 17 00:00:00 2001 From: John Bowdre Date: Mon, 24 Jun 2024 21:58:22 -0500 Subject: [PATCH] clean up kudos.js --- assets/js/kudos.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/assets/js/kudos.js b/assets/js/kudos.js index 7bf55c7..3c62466 100644 --- a/assets/js/kudos.js +++ b/assets/js/kudos.js @@ -1,24 +1,25 @@ -// disables kudos button after click +// manipulates the post upvote "kudos" button behavior -document.addEventListener('DOMContentLoaded', () => { - const kudosButton = document.querySelector('.kudos-button'); - const kudosText = document.querySelector('.kudos-text'); - const emojiSpan = kudosButton.querySelector('.emoji'); +window.onload = function() { + // get the button and text elements + var kudosButton = document.querySelector('.kudos-button'); + var kudosText = document.querySelector('.kudos-text'); + var emojiSpan = kudosButton.querySelector('.emoji'); - kudosButton.addEventListener('click', () => { + kudosButton.addEventListener('click', function(event) { + // send the event to Cabin cabin.event('kudos') + // disable the button kudosButton.disabled = true; kudosButton.classList.add('clicked'); - + // change the displayed text kudosText.textContent = 'Thanks!'; kudosText.classList.add('thanks'); - - // Rotate the emoji + // spin the emoji emojiSpan.style.transform = 'rotate(360deg)'; - - // Change the emoji after rotation - setTimeout(() => { + // change the emoji to celebrate + setTimeout(function() { emojiSpan.textContent = '🎉'; - }, 150); // Half of the transition time for a smooth mid-rotation change + }, 150); // half of the css transition time for a smooth mid-rotation change }); -}); \ No newline at end of file +}