-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
59 lines (55 loc) · 2.44 KB
/
scripts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
window.addEventListener("DOMContentLoaded", () => {
const inputsColor = document.querySelectorAll('input[name=product_color]');
const formColorLabel = document.getElementById('productColorValue');
const formPriceLabel = document.getElementById('productPriceValue');
inputsColor.forEach((input) => {
input.addEventListener('change', (e) => {
formColorLabel.innerText = e.target.dataset.nameDisplay;
formPriceLabel.innerText = `EUR ${e.target.dataset.price}`;
});
});
const inputsQuantity = document.querySelectorAll('.input-quantity');
inputsQuantity.forEach((input) => {
const inputField = input.querySelector('.input-quantity__field');
const inputBtnIncrease = input.querySelector('.input-quantity__btn[data-action=increase]');
const inputBtnDecrease = input.querySelector('.input-quantity__btn[data-action=decrease]');
inputBtnIncrease.addEventListener('click', () => {
const initialValue = inputField.value * 1;
inputField.value = initialValue + 1;
});
inputBtnDecrease.addEventListener('click', () => {
const initialValue = inputField.value * 1;
if (initialValue > 1) inputField.value = initialValue - 1;
});
});
const accordions = document.querySelectorAll('.accordion__item');
accordions.forEach((accordion) => {
const accordionTitle = accordion.querySelector('.accordion__item-title');
accordionTitle.addEventListener('click', () => {
accordion.classList.toggle('accordion__item_active');
const title = accordion.querySelector('.accordion__item-title');
const body = accordion.querySelector('.accordion__item-body');
if (accordion.classList.contains('accordion__item_active')) {
title.setAttribute('aria-expanded', 'true');
body.removeAttribute('aria-hidden');
} else {
title.setAttribute('aria-expanded', 'false');
body.setAttribute('aria-hidden', 'true');
}
});
});
const modalTarget = document.querySelectorAll('.modal-target');
modalTarget.forEach((modalTarget)=> {
modalTarget.addEventListener('click', ()=>{
const modalWindow = document.querySelector('.modal');
modalWindow.showModal();
});
});
const modalCloseButton = document.querySelectorAll('.modal-close-button');
modalCloseButton.forEach((modalCloseButton)=> {
modalCloseButton.addEventListener('click', (e) => {
const modalWindow = e.target.closest('.modal');
modalWindow.close();
});
});
})