-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
239 lines (220 loc) · 6.34 KB
/
index.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
let products = {
cakes: [
{
name: "Chocolava Cake",
imgURL:
"https://www.bakingo.com/blog/wp-content/uploads/2020/06/chocolava-cake-300x185.jpg",
price: "$10",
},
{
name: "Banana Cake",
imgURL:
"https://www.bakingo.com/blog/wp-content/uploads/2020/06/banana-cake-300x185.jpg",
price: "$10",
},
{
name: "Black Forest Cake",
imgURL:
"https://www.bakingo.com/blog/wp-content/uploads/2020/06/black-forest-cake-300x185.jpg",
price: "$10",
},
{
name: "Brownie Cake",
imgURL:
"https://www.bakingo.com/blog/wp-content/uploads/2020/06/brownie-cake-300x185.jpg",
price: "$10",
},
{
name: "Bundt Cake",
imgURL:
"https://www.bakingo.com/blog/wp-content/uploads/2020/06/bundt-cake-300x185.jpg",
price: "$10",
},
],
cupcakes: [
{
name: "Panda Cupcakes",
imgURL:
"https://www.berries.com/blog/wp-content/uploads/2016/01/2-pandas.jpg",
price: "$10",
},
{
name: "Apple Pie Cupcakes",
imgURL:
"https://www.berries.com/blog/wp-content/uploads/2016/01/3-spoonful.jpg",
price: "$10",
},
{
name: "Butterbeer Cupcakes",
imgURL:
"https://www.berries.com/blog/wp-content/uploads/2016/01/7-butterbeer.jpg",
price: "$10",
},
{
name: "Lemon Cupcakes",
imgURL:
"https://www.berries.com/blog/wp-content/uploads/2016/01/8-pioneer-lemon.jpg",
price: "$10",
},
{
name: "Black Forest Cupcakes",
imgURL:
"https://www.berries.com/blog/wp-content/uploads/2016/01/10-sugar-soul.jpg",
price: "$10",
},
],
sweets: [
{
name: "Gulab Jamun",
imgURL:
"https://i.ndtvimg.com/i/2016-10/gulab-jamun_620x350_81477049812.jpg",
price: "$10",
},
{
name: "Gajar Ka Halwa",
imgURL:
"https://i.ndtvimg.com/i/2017-10/gajar-ka-halwa-recipe_620x330_51507896671.jpg",
price: "$10",
},
{
name: "Modak",
imgURL:
"https://c.ndtvimg.com/2018-09/hfq32sf8_modak-650_625x300_12_September_18.jpg",
price: "$10",
},
{
name: "Payasam",
imgURL:
"https://i.ndtvimg.com/i/2016-03/payasam-625_625x350_41459346459.jpg",
price: "$10",
},
{
name: "Kaju ki Barfi",
imgURL:
"https://i.ndtvimg.com/i/2016-03/kaju-barfi-625_625x350_81459346355.jpg",
price: "$10",
},
],
doughnuts: [
{
name: "Glazed Donuts",
imgURL:
"https://v1.nitrocdn.com/SMAjQjQrSfukicyrZHRearuvaVtcHpQg/assets/static/source/rev-d98cf76/wp-content/uploads/2020/05/4-21-2-min.jpg",
price: "$10",
},
{
name: "Sprinkled Donuts",
imgURL:
"https://v1.nitrocdn.com/SMAjQjQrSfukicyrZHRearuvaVtcHpQg/assets/static/source/rev-d98cf76/wp-content/uploads/2020/05/5-21-2-min.jpg",
price: "$10",
},
{
name: "Jelly Donuts",
imgURL:
"https://v1.nitrocdn.com/SMAjQjQrSfukicyrZHRearuvaVtcHpQg/assets/static/source/rev-d98cf76/wp-content/uploads/2020/05/6-21-2-min.jpg",
price: "$10",
},
{
name: "Cronuts",
imgURL:
"https://v1.nitrocdn.com/SMAjQjQrSfukicyrZHRearuvaVtcHpQg/assets/static/source/rev-d98cf76/wp-content/uploads/2020/05/11-21-2-min.jpg",
price: "$10",
},
{
name: "Boston Cream Donut",
imgURL:
"https://v1.nitrocdn.com/SMAjQjQrSfukicyrZHRearuvaVtcHpQg/assets/static/source/rev-d98cf76/wp-content/uploads/2020/05/8-21-2-min.jpg",
price: "$10",
},
],
};
var loadCard = (productList) => {
const outerdiv = document.getElementById("outerdiv");
outerdiv.removeChild(outerdiv.firstElementChild);
if (productList.length)
{
const cardBox = document.createElement("div");
cardBox.id = "products";
cardBox.style.paddingBottom = "50px";
for (let item of productList) {
const cardDetails = document.createElement("div");
cardDetails.className = "card";
cardDetails.style.width = "18rem";
cardDetails.style.boxShadow = "35px";
const image = document.createElement("img");
image.className = "card-img-top";
image.src = item.imgURL;
image.style.width = "286px";
image.style.height = "180px";
image.alt = item.name;
const innerdiv = document.createElement("div");
innerdiv.className =
"card-body d-flex justify-content-between align-items-center";
const name = document.createElement("p");
name.className = "card-text";
name.innerHTML = item.name;
const pricedetail = document.createElement("p");
pricedetail.className = "card-text";
pricedetail.innerHTML = item.price;
pricedetail.style.fontSize = "1.5em";
innerdiv.appendChild(name);
innerdiv.appendChild(pricedetail);
cardDetails.appendChild(image);
cardDetails.appendChild(innerdiv);
cardBox.appendChild(cardDetails);
}
outerdiv.appendChild(cardBox);
}
else {
const errorCard = document.createElement("div");
errorCard.className = "jumbotron jumbotron-fluid alert-danger";
const innerdiv = document.createElement("div");
innerdiv.className = "container text-center";
const innerh1 = document.createElement("h1");
innerh1.className = "display-4";
innerh1.innerHTML = "Not Found !!!";
innerdiv.appendChild(innerh1);
errorCard.appendChild(innerdiv);
outerdiv.appendChild(errorCard);
}
};
let allprod = [
...products.cakes,
...products.cupcakes,
...products.sweets,
...products.doughnuts,
];
var allProd = () => {
loadCard(allprod);
};
var cake = () => {
const prod = [...products.cakes];
loadCard(prod);
};
var cupCakes = () => {
const prod = [...products.cupcakes];
loadCard(prod);
};
var sweets = () => {
const prod = [...products.sweets];
loadCard(prod);
};
var doughnuts = () => {
const prod = [...products.doughnuts];
loadCard(prod);
};
document.getElementById("search").addEventListener("submit", function (event) {
console.log("hi");
event.preventDefault();
const itemval = document.getElementById("searchval").value;
let newProd = [];
for (let item of allprod) {
let tempval = item.name.toLowerCase();
if (tempval.includes(itemval.toLowerCase())) {
newProd.push(item);
}
}
document.getElementById("searchval").value = "";
loadCard(newProd);
});
allProd();