From f69962bc2d144b3b26642eebf4e797e1715a4ffe Mon Sep 17 00:00:00 2001 From: ketah Date: Fri, 1 Jul 2022 11:35:45 +0300 Subject: [PATCH] commit tree 7749e539d5ff69d2c366d200335f5970db4d266b --- main.js | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/main.js b/main.js index 96ed93fe..ecf3a802 100644 --- a/main.js +++ b/main.js @@ -34,34 +34,33 @@ const EMPTY_HEART = '♡' const FULL_HEART = '♥' - const articleHearts = document.querySelectorAll(".like-glyph"); - - function likeCallback(e) { - const heart = e.target; - mimicServerCall() - .then(function(){ - if ( liker.innerText === EMPTY_HEART) { - liker.innerText = FULL_HEART; - liker.className = "activated-heart"; - } else { - liker.innerText = EMPTY_HEART; - liker.className = ""; - } - }) - .catch((error)=> { - let modal = document.getElementById("modal"); + // + const heartResponce = document.querySelectorAll(".like-glyph"); + +function likefunc(event) { + const likeHeart = event.target; + mimicServerCall() + .then(() => { + if ( likeHeart.innerText === EMPTY_HEART) { + likeHeart.innerText = FULL_HEART; + likeHeart.className = "activated-heart"; + } else { + likeHeart.innerText = EMPTY_HEART; + likeHeart.className = ""; + } + }) + .catch((error) => { + const modal = document.getElementById("modal"); modal.className = ""; modal.innerText = error; setTimeout(() => modal.className = "hidden", 3000); }); - - } - - for (const glyph of articleHearts) { - glyph.addEventListener("click", likeCallback); - } - - +} + +for (const glyphlike of heartResponce) { + glyphlike.addEventListener("click", likefunc); +} + //------------------------------------------------------------------------------