-
Notifications
You must be signed in to change notification settings - Fork 0
/
bags1.js
374 lines (372 loc) · 10.6 KB
/
bags1.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
let bagsData = [
{
img: "https://img.mytheresa.com/1000/1000/95/jpeg/catalog/product/a7/P00566568_b1.jpg",
brand: "Floral silk minidress",
name: "STELLA MCCARTNEY",
price: 95,
cat: "sandals",
qty: 1
},
{
img: "https://img.mytheresa.com/1000/1000/95/jpeg/catalog/product/44/P00640733_b1.jpg",
name: "LOEWE",
brand: "Sculptural leather mules",
price: 825,
cat: "sandals",
qty: 1
},
{
img: "https://img.mytheresa.com/1000/1000/95/jpeg/catalog/product/5b/P00267859_b1.jpg",
name: "THE ROW",
brand: "Emy leather shoulder bag",
price: 1059,
cat: "sandals",
qty: 1
},
{
img: "https://img.mytheresa.com/1000/1000/95/jpeg/catalog/product/64/P00591281_b1.jpg",
name: "STELLA MCCARTNEY",
brand: "Ribbed-knit midi dress",
price: 715,
cat: "sandals",
qty: 1
},
{
img: "https://img.mytheresa.com/1000/1000/95/jpeg/catalog/product/c5/P00591274_b1.jpg",
name: "FRANKIE SHOP",
brand: "Bourse nylon shoulder bag",
price: 135,
cat: "sandals",
qty: 1
},
{
img: "https://img.mytheresa.com/1000/1000/95/jpeg/catalog/product/b8/P00665723_b1.jpg",
name: "THE ROW",
brand: "Emy leather shoulder bag",
price: 775,
cat: "sandals",
qty: 1
},
{
img: "https://img.mytheresa.com/1000/1000/95/jpeg/catalog/product/ee/P00498437_b1.jpg",
name: "LOEWE",
brand: "Printed canvas mules",
price: 585,
cat: "sandals",
qty: 1
},
{
img: "https://img.mytheresa.com/1000/1000/95/jpeg/catalog/product/6c/P00653606_b1.jpg",
name: "FRANKIE SHOP",
brand: "Lui cotton shorts",
price: 79,
cat: "sandals",
qty: 1
},
{
img: "https://img.mytheresa.com/1000/1000/95/jpeg/catalog/product/49/P00525738_b1.jpg",
name: "STELLA MCCARTNEY",
brand: "Floral silk maxi dress",
price: 1005,
cat: "sandals",
qty: 1
},
{
img: "https://img.mytheresa.com/560/560/33/jpeg/catalog/product/2f/P00660703_b1.jpg",
name: "LOEWE",
brand: "Caged platform sandals",
price: 329,
cat: "sandals",
qty: 1
},
{
img: "https://img.mytheresa.com/560/560/33/jpeg/catalog/product/da/P00657414_b1.jpg",
name: "THE ROW",
brand: "Park Large nylon tote bag",
price: 725,
cat: "sandals",
qty: 1
},
{
img: "https://img.mytheresa.com/560/560/33/jpeg/catalog/product/4c/P00651976_b1.jpg",
name: "ETRO",
brand: "Floral midi dress",
price: 1015,
cat: "sandals",
qty: 1
},
{
img: "https://img.mytheresa.com/560/560/33/jpeg/catalog/product/88/P00451085_b1.jpg",
name: "ETRO",
brand: "Floral silk crêpe de chine minidres",
price: 1425,
cat: "sandals",
qty: 1
},
{
img: "https://img.mytheresa.com/560/560/33/jpeg/catalog/product/5a/P00634463_b1.jpg",
name: "AQUAZZURA",
brand: "Moondust embellished leather slides",
price: 585,
cat: "sandals",
qty: 1
},
{
img: "https://img.mytheresa.com/560/560/33/jpeg/catalog/product/3b/P00651966_b1.jpg",
name: "LOEWE",
brand: "Caged platform sandals",
price: 329,
cat: "sandals",
qty: 1
},
{
img: "https://img.mytheresa.com/560/560/33/jpeg/catalog/product/5a/P00634487_b1.jpg",
name: "PETAR PETROV",
brand: "Finley cashmere and silk",
price: 749,
cat: "sandals",
qty: 1
},
{
img: "https://img.mytheresa.com/560/560/33/jpeg/catalog/product/22/P00633293_b1.jpg",
name: "STELLA MCCARTNEY",
brand: "Ribbed-knit sweater",
price: 585,
cat: "sandals",
qty: 1
},
{
img: "https://img.mytheresa.com/560/560/33/jpeg/catalog/product/c2/P00633292_b1.jpg",
name: "ETRO",
brand: "Paisley jacquard shopper",
price: 429,
cat: "sandals",
qty: 1
},
{
img: "https://img.mytheresa.com/560/560/33/jpeg/catalog/product/b6/P00633291_b1.jpg",
name: "STELLA MCCARTNEY",
brand: "Falabella faux leather mules",
price: 505,
cat: "sandals",
qty: 1
},
{
img: "https://img.mytheresa.com/560/560/33/jpeg/catalog/product/59/P00634466_b1.jpg",
name: "STELLA MCCARTNEY",
brand: "Ribbed-knit midi skirt",
price: 635,
cat: "sandals",
qty: 1
},
{
img: "https://img.mytheresa.com/560/560/33/jpeg/catalog/product/8e/P00636803_b1.jpg",
name: "PETAR PETROV",
brand: "Flavia cashmere and silk midi dress",
price: 755,
cat: "sandals",
qty: 1
},
{
img: "https://img.mytheresa.com/560/560/33/jpeg/catalog/product/8e/P00644402_b1.jpg",
name: "THE ROW",
brand: "Park Large nylon tote bag",
price: 725,
cat: "sandals",
qty: 1
},
{
img: "https://img.mytheresa.com/560/560/33/jpeg/catalog/product/0e/P00636784_b1.jpg",
name: "MALONE SOULIERS",
brand: "Perla metallic leather mules",
price: 379,
cat: "sandals",
qty: 1
},
{
img: "https://img.mytheresa.com/560/560/33/jpeg/catalog/product/3b/P00626616_b1.jpg",
brand: "Sequined minidress",
name: "STELLA MCCARTNEY",
price: 925,
cat: "sandals",
qty: 1
}]
// for (let i=0; i<bagsData.length; i++){
// console.log(bagsData[i])
// }
let jwlrdata=JSON.parse(localStorage.getItem("kids-NewArr"))||[]
document.querySelector("#sort").addEventListener("change",function(){
sortMe(bagsData)
})
function sortMe(bagsData)
{
let req = document.querySelector("#sort").value;
if(req=="asc")
{
let asc= bagsData.sort(function(a,b){
if(a.price>b.price) return 1
if(a.price<b.price) return -1
return 0
})
displayProducts(asc)
}
else if(req=="desc")
{
let desc= bagsData.sort(function(a,b){
if(a.price>b.price) return -1
if(a.price<b.price) return 1
return 0
})
displayProducts(desc)
}
}
displayProducts(bagsData)
function displayProducts(bagsData)
{
document.querySelector("#display").innerHTML=""
bagsData.forEach(function(el){
let child_div=document.createElement("div")
let holder=document.createElement("div")
holder.setAttribute("class","holder")
let wish = document.createElement("button")
let heart = document.createElement("i")
heart.setAttribute("class","fas fa-heart")
wish.append(heart)
wish.style.color="grey"
wish.setAttribute("class","btn1")
wish.addEventListener("click",function(){
if(toggle(el,wish)==true)
{
alert("Item already extists in wishlist")
}
else
{
if(wish.style.color=="grey")
{
wish.style.color="red"
}
else
{
wish.style.color="grey"
}
jwlrdata.push(el)
alert("added")
localStorage.setItem("kids-NewArr",JSON.stringify(jwlrdata))
}
})
holder.append(wish)
let img = document.createElement("img")
img.setAttribute("src",el.img)
let brand = document.createElement("p")
brand.innerText=el.brand;
let name=document.createElement("p")
name.innerText=el.name;
let price=document.createElement("p")
price.innerText="€"+" "+el.price;
child_div.append(holder,img,brand,name,price)
document.querySelector("#display").append(child_div)
});
}
function toggle(el,wish)
{
let filtered= jwlrdata.filter(function(elem){
return el.name==elem.name
})
if(filtered.length>0)
{
return true
}
else
{
return false
}
}
let sorting = document.querySelectorAll("#colour>input")
for(let i=0;i<sorting.length;i++)
{
let c = sorting[i].value
sorting[i].addEventListener("click",function(){
colourSort(c)
})
}
function colourSort(c)
{
console.log("hi")
if(c==="All")
{
displayProducts(bagsData)
}
else
{
let filtered=bagsData.filter(function(el){
return el.color==c
})
if(filtered.length==0)
{
alert("No products found")
}
else
{
displayProducts(filtered)
}
}
}
let sortingBrand = document.querySelectorAll("#designer>input")
for(let i=0;i<sortingBrand.length;i++)
{
let b = sortingBrand[i].value
console.log(b)
sortingBrand[i].addEventListener("click",function(){
brandSort(b)
})
}
function brandSort(b)
{
if(b==="All")
{
displayProducts(jewelData)
}
else
{
let brandFilter=bagsData.filter(function(el){
return el.brand==b
})
if(brandFilter.length==0)
{
alert("No products found")
}
else
{
displayProducts(brandFilter)
}
}
}
let sortingCat = document.querySelectorAll("#category>input")
for(let i=0;i<sortingCat.length;i++)
{
let s = sortingCat[i].value
sortingCat[i].addEventListener("click",function(){
catSort(s)
})
}
function catSort(s)
{
if(s==="All")
{
displayProducts(bagsData)
}
else
{
let catFilter=bagsData.filter(function(el){
return el.cat==s
})
if(catFilter.length==0)
{
alert("No products found")
}
else
{
displayProducts(catFilter)
}
}
}