forked from Harshal-Jadhav/Dot-and-Key-Clone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bodynavbar.js
58 lines (51 loc) · 1.62 KB
/
bodynavbar.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
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
function cart() {
cartDataLS = JSON.parse(localStorage.getItem('cartData')) || []
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
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')
}
let 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'
}
}