forked from Harshal-Jadhav/Dot-and-Key-Clone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
serumdetail.js
112 lines (81 loc) · 2.97 KB
/
serumdetail.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// localStorage.setItem("detailpage",JSON.stringify("productdetail"))
let productdetailpage = JSON.parse(localStorage.getItem("detailpage"))
console.log(productdetailpage)
display(productdetailpage)
function display(productdetailpage) {
productdetailpage.forEach(function (elem) {
let productphoto = document.createElement("img")
productphoto.setAttribute("src", elem.img)
let producttext = document.createElement("h2")
producttext.innerText = elem.des
// let price1 = document.createElement("span")
let price1 = document.createElement("span")
price1.innerText = elem.price1 + " "
price1.setAttribute("class", "price1")
let price2 = document.createElement("span")
price2.innerText = "Rs: " + elem.price
price2.setAttribute("class", "price2")
document.querySelector("#pricelebel").append(price1, price2)
document.querySelector("#productImage").append(productphoto)
document.querySelector("#productdescription").append(producttext)
})
}
document.querySelector('#centerLogo').addEventListener('click', home);
document.querySelector('#cart').addEventListener('click', cart);
document.querySelector('#profile').addEventListener('click', profile);
// function for home page redirection
function home() {
window.location.href = 'index.html'
}
// functin for cart page redirection
let cartDataLS = JSON.parse(localStorage.getItem('cartData')) || []
function cart() {
if (cartDataLS.length === 0) {
window.location.href = 'emptyCart.html'
} else {
window.location.href = 'cart.html'
}
}
// functin for profile page redirection
loginLS = JSON.parse(localStorage.getItem('login')) || 0;
function profile() {
if (loginLS == 0) {
window.location.href = 'signin.html'
} else {
window.location.href = 'profile.html'
}
}
// New Update
loginLS = JSON.parse(localStorage.getItem('login')) || 0
let personBtn = document.querySelector('#profile')
if (loginLS == 1) {
personBtn.innerText = localStorage.getItem('userInitial')
personBtn.setAttribute('class', 'initials')
} else {
personBtn.innerText = 'person';
personBtn.setAttribute('class', 'material-symbols-outlined')
}
cartDataLS = JSON.parse(localStorage.getItem('cartData')) || []
let mark = document.querySelector('#mark')
if (cartDataLS.length > 0) {
mark.setAttribute('class', 'dotVisible')
} else {
mark.setAttribute('class', "dotHidden")
}
// New Update V2.0
document.querySelector('#menuButton').addEventListener('click', toggle)
function toggle() {
let x = document.querySelector('#menu')
if (x.style.display == 'grid') {
x.style.display = 'none'
} else {
x.style.display = 'grid'
}
}
let x = document.querySelector('#addTocart')
x.addEventListener('click', addtoCart)
function addtoCart() {
cartDataLS.push(productdetailpage[0]);
localStorage.setItem('cartData', JSON.stringify(cartDataLS))
window.location.reload()
}