-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathitems_detail.js
158 lines (140 loc) · 5.33 KB
/
items_detail.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import navbar from "./cmmponents/navbar.js"
const navbar_div = document.getElementById("navbar")
navbar_div.innerHTML = navbar()
import footer from "./cmmponents/footer.js"
const footer_div = document.getElementById("footer")
footer_div.innerHTML = footer()
let addedItems=JSON.parse(localStorage.getItem("cartitems")) || [];
// cart length
let total_cart_products = document.getElementById("cartitems")
total_cart_products.innerText = addedItems.length;
let data = JSON.parse(localStorage.getItem('swiped_data'))
console.log(data)
let left = document.getElementById("left")
let div1 = document.getElementById("div1")
// let cartArr = JSON.parse(localStorage.getItem("addcart")) || []
const append = ((data) => {
let div = document.createElement("div");
div.setAttribute("class","items_detail_div")
let image = document.createElement("img");
image.src = data.image;
let name = document.createElement("h1")
name.setAttribute("class","style1")
name.innerText = data.name;
let price = document.createElement("p")
price.id = "items_price"
price.innerText = `Price: ${data.price}`;
price.setAttribute("class","style1")
let div_star = document.createElement("div")
div_star.setAttribute("class","style1")
for (let i = 0; i < data.star; i++) {
let star = document.createElement("i")
star.setAttribute("class", "fa-solid fa-star")
div_star.append(star)
}
let ship = document.createElement("p");
ship.setAttribute("class","style1")
let btn = document.createElement("button")
btn.id = "add_to_cart_btn"
btn.innerText = "Add To Cart"
btn.setAttribute("class", "style1")
btn.onclick = () => {
btn.innerText = "Added"
btn.disabled = true;
addedItems.push(data)
total_cart_products.innerText = addedItems.length;
localStorage.setItem("cartitems",JSON.stringify(addedItems))
}
left.append(image)
div.append(name, price, div_star, ship, btn);
div1.append(div);
})
append(data)
let likeCount=0;
let like=document.getElementById("like")
like.onclick=()=>{
likeCount++
like.innerText=null
// like.style.backgroundColor="skyblue"
like.style.width = "150px"
like.style.paddingBottom = "2px"
like.style.paddingTop = "2px"
let div=document.createElement("div")
let p=document.createElement("p")
p.innerText=`You and ${likeCount} other Like this`
div.append(p)
like.append(div)
}
// category js
let mens_cat = document.getElementsByClassName("mens")
let womens_cat = document.getElementsByClassName("womens")
let beauty_cat = document.getElementsByClassName("beauty")
let electronics_cat = document.getElementsByClassName("electronics")
let jewellery_cat = document.getElementsByClassName("jewellery")
let kids_cat = document.getElementsByClassName("kids")
let videogame_cat = document.getElementsByClassName("videogame")
for(let i=0;i<mens_cat.length;i++){
mens_cat[i].addEventListener("click",function(){
console.log("nikhil");
localStorage.setItem("category_call","mens")
window.location.href = "category.html"
})
}
for(let i=0;i<womens_cat.length;i++){
womens_cat[i].addEventListener("click",function(){
console.log("nikhil");
localStorage.setItem("category_call","womens")
window.location.href = "category.html"
})
}
for(let i=0;i<beauty_cat.length;i++){
beauty_cat[i].addEventListener("click",function(){
console.log("nikhil");
localStorage.setItem("category_call","beauty")
window.location.href = "category.html"
})
}
for(let i=0;i<electronics_cat.length;i++){
electronics_cat[i].addEventListener("click",function(){
console.log("nikhil");
localStorage.setItem("category_call","electronics")
window.location.href = "category.html"
})
}
for(let i=0;i<jewellery_cat.length;i++){
jewellery_cat[i].addEventListener("click",function(){
console.log("nikhil");
localStorage.setItem("category_call","jewellery")
window.location.href = "category.html"
})
}
for(let i=0;i<kids_cat.length;i++){
kids_cat[i].addEventListener("click",function(){
console.log("nikhil");
localStorage.setItem("category_call","kids")
window.location.href = "category.html"
})
}
for(let i=0;i<videogame_cat.length;i++){
videogame_cat[i].addEventListener("click",function(){
console.log("nikhil");
localStorage.setItem("category_call","videogame")
window.location.href = "category.html"
})
}
// login logout status
let homePage_username_logout_div = document.getElementById("username_logout_homePage_div")
let Username_onHomePage = document.getElementById("Username_onHomePage")
let homePage_logout_btn = document.getElementById("homePage_logout_btn")
let signup_login_homePage_div = document.getElementById("signup_login_homePage_div")
let login_logout_status = JSON.parse(localStorage.getItem("login_logout_status"))
if(login_logout_status.login_status=="loggedin"){
signup_login_homePage_div.style.display = "none";
Username_onHomePage.innerText = login_logout_status.username;
homePage_username_logout_div.style.display = "flex";
}
homePage_logout_btn.onclick = ()=>{
localStorage.removeItem("login_logout_status")
signup_login_homePage_div.style.display = "block";
homePage_username_logout_div.style.display = "none";
}