-
Notifications
You must be signed in to change notification settings - Fork 0
/
sale.js
403 lines (351 loc) · 15.4 KB
/
sale.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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
let navtop1data = [
{
name1: "lifetime",
name2: "EXTRA 40% OFF ON ALL SALE ITEMS",
name3: "shop's summery hottest style",
name4: "all sales final see details",
name5: "teal",
},
{
name1: "new styles added!",
name2: "25% OFF SELECT BEDDING, PILLOWS, RUGS & MORE",
name3: "shop",
name4: "online executive-see details",
name5: "orange"
},
{
name1: "look polished.",
name2: "dress sharp",
name3: "JUST IN: SUIT & TIE",
name4: "start shopping",
name5: "cornflowerblue"
}
]
let left = document.querySelector("#left")
let right = document.querySelector("#right")
let currentvalue = 0;
right.addEventListener("click", (e) => {
currentvalue++;
if (currentvalue == navtop1data.length) {
currentvalue = 0;
}
document.querySelector("#navtop1>div:nth-child(1)").innerText = navtop1data[currentvalue].name1
document.querySelector("#navtop1>div:nth-child(2)").innerText = navtop1data[currentvalue].name2
document.querySelector("#navtop1>div:nth-child(3)").innerText = navtop1data[currentvalue].name3
document.querySelector("#navtop1>div:nth-child(4)").innerText = navtop1data[currentvalue].name4
document.querySelector("#navtop1").style.background = navtop1data[currentvalue].name5
})
left.addEventListener("click", (e) => {
currentvalue--;
if (currentvalue < 0) {
currentvalue = navtop1data.length - 1;
}
document.querySelector("#navtop1>div:nth-child(1)").innerText = navtop1data[currentvalue].name1
document.querySelector("#navtop1>div:nth-child(2)").innerText = navtop1data[currentvalue].name2
document.querySelector("#navtop1>div:nth-child(3)").innerText = navtop1data[currentvalue].name3
document.querySelector("#navtop1>div:nth-child(4)").innerText = navtop1data[currentvalue].name4
document.querySelector("#navtop1").style.background = navtop1data[currentvalue].name5
})
let saledata = [
{
img:"https://images.urbndata.com/is/image/Anthropologie/45407863AA_011_b2?$an-category$&fit=constrain&fmt=webp&hei=523&qlt=80&wid=349" ,
productname:"Bronte Duvet Cover" ,
price:"98" ,
producttype: "sheets" ,
color:"white" ,
}, {
img:"https://images.urbndata.com/is/image/Anthropologie/45457843AA_031_b?$an-category$&fit=constrain&fmt=webp&hei=523&qlt=80&wid=349" ,
productname:"Woven Bronte Pillow" ,
price:"66" ,
producttype: "throwpillows" ,
color:"pink" ,
}, {
img:"https://images.urbndata.com/is/image/Anthropologie/65336273_004_b3?$an-category$&fit=constrain&fmt=webp&hei=523&qlt=80&wid=349" ,
productname:"Moroccan Wool Blanket" ,
price:"228" ,
producttype: "throws" ,
color:"grey" ,
}, {
img:"https://images.urbndata.com/is/image/Anthropologie/45407866AD_045_b2?$an-category$&fit=constrain&fmt=webp&hei=523&qlt=80&wid=349" ,
productname:"Print Fresh Sheet" ,
price:"208" ,
producttype: "sheets" ,
color:"blue" ,
}, {
img:"https://images.urbndata.com/is/image/Anthropologie/45409388AA_067_b?$an-category$&fit=constrain&fmt=webp&hei=523&qlt=80&wid=349" ,
productname:"Joaquin Quilt" ,
price:"228" ,
producttype: "pillowshamps" ,
color:"pink" ,
}, {
img:"https://images.urbndata.com/is/image/Anthropologie/45457823AA_011_b?$an-category$&fit=constrain&fmt=webp&hei=523&qlt=80&wid=349" ,
productname:"Pillow Cover" ,
price:"128" ,
producttype: "throwpillows" ,
color:"white" ,
}, {
img:"https://images.urbndata.com/is/image/Anthropologie/66667742_095_b?$an-category$&fit=constrain&fmt=webp&hei=523&qlt=80&wid=349" ,
productname:"Parasol Beach Blanket" ,
price:"73" ,
producttype: "towel" ,
color:"blue" ,
}, {
img:"https://images.urbndata.com/is/image/Anthropologie/45407437AD_066_b?$an-category$&fit=constrain&fmt=webp&hei=523&qlt=80&wid=349" ,
productname:"Organic Sateen Sheet" ,
price:"43" ,
producttype: "sheets" ,
color:"pink" ,
}, {
img:"https://images.urbndata.com/is/image/Anthropologie/45457831AA_066_b?$an-category$&fit=constrain&fmt=webp&hei=523&qlt=80&wid=349" ,
productname:"Suillivan Pillow" ,
price:"98" ,
producttype: "pillowshamps" ,
color:"red" ,
}, {
img:"https://images.urbndata.com/is/image/Anthropologie/56258999_012_b2?$an-category$&fit=constrain&fmt=webp&hei=523&qlt=80&wid=349" ,
productname:"Rifle Paper Pillow" ,
price:"90" ,
producttype: "throwpillows" ,
color:"white" ,
}, {
img:"https://images.urbndata.com/is/image/Anthropologie/45407835AD_040_b2?$an-category$&fit=constrain&fmt=webp&hei=523&qlt=80&wid=349" ,
productname:"Percale Sheet Set" ,
price:"58" ,
producttype: "sheets" ,
color:"black" ,
}, {
img:"https://images.urbndata.com/is/image/Anthropologie/45407869AG_080_b?$an-category$&fit=constrain&fmt=webp&hei=523&qlt=80&wid=349" ,
productname:"Organic Euro Shamp" ,
price:"66" ,
producttype: "pillowshamps" ,
color:"green" ,
}, {
img:"https://images.urbndata.com/is/image/Anthropologie/45457853AA_066_b?$an-category$&fit=constrain&fmt=webp&hei=523&qlt=80&wid=349" ,
productname:"Woven Silk Pillow" ,
price:"66" ,
producttype: "throwpillows" ,
color:"red" ,
}, {
img:"https://images.urbndata.com/is/image/Anthropologie/66937251_095_b?$an-category$&fit=constrain&fmt=webp&hei=523&qlt=80&wid=349" ,
productname:"Birdie Shamps" ,
price:"66" ,
producttype: "pillowshamps" ,
color:"red" ,
}, {
img:"https://images.urbndata.com/is/image/Anthropologie/69511277_010_b2?$an-category$&fit=constrain&fmt=webp&hei=523&qlt=80&wid=349" ,
productname:"Alternative Pillow" ,
price:"80" ,
producttype: "sheets" ,
color:"white" ,
}, {
img:"https://images.urbndata.com/is/image/Anthropologie/4545Z073AA_099_b?$an-category$&fit=constrain&fmt=webp&hei=523&qlt=80&wid=349" ,
productname:"Andersen Wool Pillow" ,
price:"78" ,
producttype: "throwpillows" ,
color:"blue" ,
}, {
img:"https://images.urbndata.com/is/image/Anthropologie/68892447_018_b2?$an-category$&fit=constrain&fmt=webp&hei=523&qlt=80&wid=349" ,
productname:"Novella Throw Blanket" ,
price:"128" ,
producttype: "throws" ,
color:"black" ,
},
{
img:"https://images.urbndata.com/is/image/Anthropologie/62985262_001_b2?$an-category$&fit=constrain&fmt=webp&hei=523&qlt=80&wid=349" ,
productname:"Henderson Bookshelf" ,
price:"1,499" ,
producttype: "amber lewis" ,
color:"black" ,
},
{
img:"https://images.urbndata.com/is/image/Anthropologie/65070898_220_b2?$an-category$&fit=constrain&fmt=webp&hei=523&qlt=80&wid=349" ,
productname:"Rattan Lidded Ceramic Candle" ,
price:"19" ,
producttype: "amber lewis" ,
color:"brown" ,
}, {
img:"https://images.urbndata.com/is/image/Anthropologie/65535429_040_b11?$an-category$&fit=constrain&fmt=webp&hei=523&qlt=80&wid=349" ,
productname:"Sunrar Reed Diffuser" ,
price:"20" ,
producttype: "anthropologie" ,
color:"blue" ,
}, {
img:"https://images.urbndata.com/is/image/Anthropologie/67118760_001_b2?$an-category$&fit=constrain&fmt=webp&hei=523&qlt=80&wid=349" ,
productname:"Raffia Basket" ,
price:"189" ,
producttype: "across africa" ,
color:"black" ,
}, {
img:"https://images.urbndata.com/is/image/Anthropologie/67957084_046_b10?$an-category$&fit=constrain&fmt=webp&hei=523&qlt=80&wid=349" ,
productname:"Teal Gourad Bird House" ,
price:"39" ,
producttype: "across africa" ,
color:"yellow" ,
}, {
img:"https://images.urbndata.com/is/image/Anthropologie/66295684_010_b10?$an-category$&fit=constrain&fmt=webp&hei=523&qlt=80&wid=349" ,
productname:"Floral Bouqet Diffuser" ,
price:"19" ,
producttype: "anthropologie" ,
color:"white" ,
}, {
img:"https://images.urbndata.com/is/image/Anthropologie/45407841AA_011_b?$an-category$&fit=constrain&fmt=webp&hei=523&qlt=80&wid=349" ,
productname:"Hill View Duvet Cover" ,
price:"269" ,
producttype: "amber lewis" ,
color:"white" ,
}, {
img:"https://images.urbndata.com/is/image/Anthropologie/62883913_014_b2?$an-category$&fit=constrain&fmt=webp&hei=523&qlt=80&wid=349" ,
productname:"Hanging Basket" ,
price:"40" ,
producttype: "across africa" ,
color:"yellow" ,
}, {
img:"https://images.urbndata.com/is/image/Anthropologie/62130752_001_b2?$an-category$&fit=constrain&fmt=webp&hei=523&qlt=80&wid=349" ,
productname:"" ,
price:"1,399" ,
producttype: "amber lewis" ,
color:"black" ,
},
{
img:"https://images.urbndata.com/is/image/Anthropologie/65063927_066_b10?$an-category$&fit=constrain&fmt=webp&hei=523&qlt=80&wid=349" ,
productname:"Taper Duo Candle" ,
price:"29" ,
producttype: "anthropologie" ,
color:"red" ,
},
{
img:"https://images.urbndata.com/is/image/Anthropologie/45407381AG_059_b2?$an-category$&fit=constrain&fmt=webp&hei=523&qlt=80&wid=349" ,
productname:"Gwendolen Euro Shem" ,
price:"29" ,
producttype: "amber lewis" ,
color:"brown" ,
}, {
img:"https://images.urbndata.com/is/image/Anthropologie/64741796_049_b?$an-category$&fit=constrain&fmt=webp&hei=523&qlt=80&wid=349" ,
productname:"Juliette Oil" ,
price:"9" ,
producttype: "anthropologie" ,
color:"white" ,
}, {
img:"https://images.urbndata.com/is/image/Anthropologie/62922893_027_b?$an-category$&fit=constrain&fmt=webp&hei=523&qlt=80&wid=349" ,
productname:"Brass Decorative Object" ,
price:"29" ,
producttype: "amber lewis" ,
color:"brown" ,
}
]
let total = document.querySelector("#counting")
display(saledata)
// -----------------------------------FILTER BY PRODUCT TYPE
let productType = document.querySelector("#brand")
productType.addEventListener("change" ,(e)=>{
let productValue = document.querySelector("#brand").value
if(productValue == "brand"){
display(saledata)
}
else{
let productSort = saledata.filter((e)=>{
return e.producttype==productValue
})
display(productSort)
}
})
// FILTER BY PRICE ----------------------------------------------------------->
let price = document.querySelector("#Price")
price.addEventListener("change" ,(e)=>{
let priceValue = document.querySelector("#Price").value
if(priceValue == "p"){
display(saledata)
}
else{
if(priceValue == "25"){
let less = saledata.filter((e)=>{
return Number(e.price) < Number(priceValue) && (e.productname !== "")
})
display(less)
}
else if(priceValue == 50){
let less = saledata.filter((e)=>{
return Number(e.price) < Number(priceValue) && (Number(e.price) >= Number(25))
})
display(less)
}
else if(priceValue == 100){
let less = saledata.filter((e)=>{
return Number(e.price) < Number(priceValue) && (Number(e.price) >= Number(50))
})
display(less)
}
else if(priceValue == 200){
let less = saledata.filter((e)=>{
return Number(e.price) < Number(priceValue) && (Number(e.price) >= Number(100))
})
display(less)
}
else if(priceValue == 500){
let less = saledata.filter((e)=>{
return Number(e.price) < Number(priceValue) && (Number(e.price) >= Number(200))
})
display(less)
}
}
})
// filter by color ----------------------------------------->
let color = document.querySelector("#color")
color.addEventListener("change",(e)=>{
let colorValue = document.querySelector("#color").value
if(colorValue == "no"){
display(saledata)
}
else{
let colorsort = saledata.filter((e)=>{
return e.color == colorValue
})
display(colorsort)
}
})
// ---------------------------------------------------------------ascending sort ---
let ascen = document.querySelector("#sorting")
ascen.addEventListener("change" ,(e)=>{
let ascenValue = document.querySelector("#sorting").value
if(ascenValue == "ascending"){
saledata.sort(function(a,b){
if(+a.price > +b.price) return 1
if(+a.price < +b.price) return -1
})
display(saledata)
}
if(ascenValue == "descending"){
saledata.sort(function(a,b){
if(+a.price > +b.price) return -1
if(+a.price < +b.price) return 1
})
display(saledata)
}
})
function display(saledata){
document.querySelector("#productItems").innerHTML = ""
let count = 0 ;
saledata.forEach(function (elem){
count++
let div = document.createElement("div")
let img = document.createElement("img")
img.src=elem.img
let name = document.createElement("p")
name.innerText=elem.productname
name.style.fontSize="14px"
let price = document.createElement("p")
if(elem.price !== ""){
price.innerText ="$"+elem.price
price.style.color="grey"
price.style.fontSize="14px"
}
div.append(img,name,price)
document.querySelector("#productItems").append(div)
})
if(count == 0){
total.innerText="Sorry Item Is Out Of Stock"
}
else{
total.innerText = count
}
}