-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmen-product.js
92 lines (63 loc) · 2.67 KB
/
men-product.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// -------------------------------------------------------------------------
// redirecting code to single product page
// --------------------------------------------------------------------------
let product = document.querySelectorAll('.product-cont');
for (let i = 0; i < product.length; i++) {
product[i].addEventListener('click', () => {
window.location.href = "men-product.html?productIndex=" + i;
});
}
// -------------------------------------------------------------------------------------------------------
//single product page receiving the selected product number and show the product
// -------------------------------------------------------------------------------------------------------
const urlParams = new URLSearchParams(window.location.search);
const productIndex = parseInt(urlParams.get('productIndex'));
// Select and display the single product element
let singleProduct = document.querySelectorAll('.single-product');
singleProduct[productIndex].style.display = "block";
// -------------------------------------------------------------------------------
// product image to zoom in
// ----------------------------------------------------------------------------
// Get the modal
function onClick(element) {
document.getElementById("img01").src = element.src;
document.getElementById("modal01").style.display = "block";
}
// -------------------------------------------------------------------------
// wishlist button operation
// --------------------------------------------------------------------------
let wishlistBtn = document.querySelectorAll(".wishlist");
let icon = document.querySelectorAll(".wishlist-fill")
let count = document.querySelector(".count");
changecolorOn = ()=>{
icon[productIndex].name="heart";
icon[productIndex].classList.add('fill-color');
}
changecolorOff = ()=>{
icon[productIndex].name="heart-outline";
icon[productIndex].classList.remove('fill-color');
}
wishlistBtn[productIndex].addEventListener('click', ()=>{
if(icon[productIndex].classList.contains('fill-color')){
wishlistRemove();
changecolorOff();
}
else{
wishlistAdd();
changecolorOn();
}
})
let wishlistAdd = ()=>{
let itemsNumber = parseInt(localStorage.getItem("wishlist"));
if(itemsNumber){
localStorage.setItem('wishlist',itemsNumber = 1);
count.innerHTML = itemsNumber
}else{
localStorage.setItem('wishlist', 1);
count.innerHTML = 1
}
}
let wishlistRemove = ()=>{
localStorage.removeItem('wishlist')
count.innerHTML=0
}