Skip to content

Commit

Permalink
feat (photographer page) : enter event on likes (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
codexarama committed May 13, 2021
1 parent 98f08fa commit 8e3e80e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions js/likes_counter.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
// COMPTE LES LIKES : INCREMENTE / DECREMENTE DE 1 AU CLIC
const likesCount = () => {
const likes = document.querySelectorAll('.gallery__likes--icon');
// likes.addEventListener('clic', handleEvent);
const likes = document.querySelectorAll('.gallery__likes--btn');
const totalCounter = document.querySelector('#total-likes');

for (let i = 0; i < likes.length; i++) {
let like = likes[i];
like.setAttribute("aria-label", "likes")
// handleEvent = () => {
like.addEventListener('click', () => {
like.addEventListener('click', (event) => {
like.classList.toggle('selected');
let likeCounter = like.parentElement.children[0]; // au click sur "like", l'input "counter" prend le focus
if (like.classList.contains('selected')) {
Expand All @@ -22,6 +20,10 @@ const likesCount = () => {
likeCounter.style.color = '#901c1c';
totalCounter.value--; // decremente de 1 le compteur global de likes
}
// ACCESSIBILITE
// navigation clavier sur btn "like" : "entree" = "click"
if (event.keycode == 13) like.click();
});
}
};

0 comments on commit 8e3e80e

Please sign in to comment.