Skip to content

Commit

Permalink
feat (accessibility) : add handleEvents (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
codexarama committed May 9, 2021
1 parent 7d56ed9 commit 37ead02
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 23 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<section id="contenu" tabindex="-1"></section>
</main>
<script type="text/javascript" src="js/elmt_factory.js"></script>
<script type="text/javascript" src="js/handleEvents.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript" src="js/home_page.js"></script>
</body>
Expand Down
1 change: 1 addition & 0 deletions js/gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const setGallery = (media) => {
elmtFactory('input', {
class: 'gallery__likes--count',
type: 'number',
readonly: "true",
value: `${media.likes}`,
}),
elmtFactory('i', {
Expand Down
8 changes: 8 additions & 0 deletions js/handleEvents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function handleEvent(e) {
if (
e && // mouseEvent
e.keyCode === 13 // keypress "Enter"
) {
console.log('click');
}
}
49 changes: 27 additions & 22 deletions js/likes_counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,32 @@ const likesCount = () => {

for (let i = 0; i < likes.length; i++) {
let like = likes[i];
like.addEventListener('click', function () {
like.classList.toggle('selected');
let input = like.parentElement.children[0];
console.log(input); // au click sur "like", l'input "counter" prend le focus
if (like.classList.contains('selected')) {
location.hash = "j'aime";
likesCounter = parseInt(input.value) + 1;
console.log(likesCounter);
input.value = likesCounter;
input.style.color = '#db8876';
// incremente de 1 le compteur global de likes
totalCounter.value++;
} else {
location.hash = "je n'aime plus";
likesCounter = parseInt(input.value) - 1;
console.log(likesCounter);
input.value = likesCounter;
input.style.color = '#901c1c';
// decremente de 1 le compteur global de likes
totalCounter.value--;
}
});
// handleEvent = keypress "Enter" + "click"
like.addEventListener(
'click',
(handleEvent = () => {
// like.addEventListener('click', () => {
like.classList.toggle('selected');
let input = like.parentElement.children[0];
console.log(input); // au click sur "like", l'input "counter" prend le focus
if (like.classList.contains('selected')) {
location.hash = "j'aime";
likesCounter = parseInt(input.value) + 1;
console.log(likesCounter);
input.value = likesCounter;
input.style.color = '#db8876';
// incremente de 1 le compteur global de likes
totalCounter.value++;
} else {
location.hash = "je n'aime plus";
likesCounter = parseInt(input.value) - 1;
console.log(likesCounter);
input.value = likesCounter;
input.style.color = '#901c1c';
// decremente de 1 le compteur global de likes
totalCounter.value--;
}
})
);
}
};
3 changes: 2 additions & 1 deletion propage.html
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ <h2 class="form__body--name"></h2>
<!-- footer element -->
<footer class="footer">
<div class="footer__content">
<input id="total-likes" type="number"></input>
<input id="total-likes" readonly type="number"></input>
<i class="fas fa-heart"></i>
</div>
<div class="footer__content">
Expand All @@ -168,6 +168,7 @@ <h2 class="form__body--name"></h2>

<!-- appel des scripts js -->
<script type="text/javascript" src="js/elmt_factory.js"></script>
<script type="text/javascript" src="js/handleEvents.js"></script>
<script type="text/javascript" src="js/gallery.js"></script>
<script type="text/javascript" src="js/profile.js"></script>
<script type="text/javascript" src="js/sort.js"></script>
Expand Down

0 comments on commit 37ead02

Please sign in to comment.