-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
35 lines (29 loc) · 1.44 KB
/
script.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
if (localStorage.getItem('cart')) {
const cart = JSON.parse(localStorage.getItem('cart'));
let shopCart = new Cart(cart);
console.log(shopCart);
document.querySelector('.cart-out').innerHTML = '';
document.querySelector('.cart-out').append(shopCart.render());
document.querySelector('.cart-out').addEventListener('click', event => {
let target = event.target;
if (target.classList.contains('delete')) {
shopCart.goodsDelete(target.dataset['articul']);
document.querySelector('.cart-out').innerHTML = '';
document.querySelector('.cart-out').append(shopCart.render());
localStorage.setItem('cart', JSON.stringify(shopCart.items));
return true;
} else if (target.classList.contains('plus')) {
shopCart.goodsPlus(target.dataset['articul']);
document.querySelector('.cart-out').innerHTML = '';
document.querySelector('.cart-out').append(shopCart.render());
localStorage.setItem('cart', JSON.stringify(shopCart.items));
return true;
} else if (target.classList.contains('minus')) {
shopCart.goodsMinus(target.dataset['articul']);
document.querySelector('.cart-out').innerHTML = '';
document.querySelector('.cart-out').append(shopCart.render());
localStorage.setItem('cart', JSON.stringify(shopCart.items));
return true;
}
})
}