-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
322 lines (290 loc) · 8.79 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
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
let food = [];
let totalAmount = 0;
$(document).ready(function () {
if ($(document).width() <= 992) {
$(".navbar-nav").removeClass("ml-auto");
$(".navbar-nav").addClass("mr-auto");
} else {
$(".navbar-nav").removeClass("mr-auto");
$(".navbar-nav").addClass("ml-auto");
}
var scrollToTopBtn = $("#scrollToTop");
$(window).scroll(function () {
if ($(window).scrollTop() > 300) {
scrollToTopBtn.addClass("show");
} else {
scrollToTopBtn.removeClass("show");
}
});
scrollToTopBtn.on("click", function (event) {
event.preventDefault();
$("html, body").animate(
{
scrollTop: 0,
},
"500"
);
});
$(".navbar a").on("click", function (event) {
// Make sure this.hash has a value before overriding default behavior
if (this.hash !== "") {
// console.log(this);
// console.log(this.hash);
// Prevent default anchor click behavior
event.preventDefault();
// Store hash
var hash = this.hash;
// Using jQuery's animate() method to add smooth page scroll
// The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area
$("html, body").animate(
{
scrollTop: $(hash).offset().top,
},
800,
function () {
// Add hash (#) to URL when done scrolling (default click behavior)
window.location.hash = hash;
}
);
} // End if
});
$(".homeBtn").click(function (event) {
if (this.hash !== "") {
event.preventDefault();
let hash = this.hash;
$("html, body").animate(
{
scrollTop: $(hash).offset().top,
},
800,
function () {
// Add hash (#) to URL when done scrolling (default click behavior)
window.location.hash = hash;
}
);
}
});
$(".product-box-layout4").click(function () {
$(this)
.toggleClass("productClicked")
.parent()
.siblings("div")
.children()
.removeClass("productClicked");
if ($(this)[0].className.search("momos productClicked") > -1) {
$("#momos").show().siblings("div").hide();
$("html, body").animate(
{
scrollTop: $("#momos").offset().top,
},
800,
function () {}
);
} else if ($(this)[0].className.search("chinese productClicked") > -1) {
$("#chinese").show().siblings("div").hide();
$("html, body").animate(
{
scrollTop: $("#chinese").offset().top,
},
800,
function () {}
);
} else if ($(this)[0].className.search("beverages productClicked") > -1) {
$("#beverages").show().siblings("div").hide();
$("html, body").animate(
{
scrollTop: $("#beverages").offset().top,
},
800,
function () {}
);
}
});
$(".menuBtn").click(function () {
let quantity = $(this).siblings(".quantity");
let foodNameClicked = quantity
.parent()
.siblings("div")
.children()
.first()
.text()
.trim();
let singleFoodAmount= quantity.parent().siblings("div").children().last().text();
let numericPart = singleFoodAmount.replace(/[^\d.]/g, '');
if (!isNaN(numericPart)) {
singleFoodAmount = parseFloat(numericPart);
}
let isVeg = quantity
.parent()
.siblings("div")
.children()
.first()
.children()
.first()
.children()
.hasClass("vegIcon");
let count = Number(quantity.text());
if ($(this)[0].className.search("plus") > -1) {
count = count + 1;
quantity.text(count);
ToCart(foodNameClicked, count, isVeg, singleFoodAmount);
} else if ($(this)[0].className.search("minus") > -1) {
if (count <= 0) {
quantity.text(0);
} else {
count = count - 1;
quantity.text(count);
ToCart(foodNameClicked, count, isVeg, singleFoodAmount);
}
}
});
function ToCart(foodNameClicked, foodQuantity, isVeg, singleFoodAmount) {
let foodAlreadyThere = false;
let foodPos;
let node;
if (isVeg) {
node = '<img class="vegIcon" src="./images/veg.webp" alt="" />';
} else {
node = '<img class="vegIcon" src="./images/veg.webp" alt="" />';
}
for (var i = 0; i < food.length; i++) {
if (food[i][0] === foodNameClicked) {
foodAlreadyThere = true;
foodPos = i;
break;
} else {
foodAlreadyThere = false;
}
}
if (foodAlreadyThere) {
food.splice(foodPos, 1);
food.push([foodNameClicked, foodQuantity, singleFoodAmount, node]);
} else {
food.push([foodNameClicked, foodQuantity, singleFoodAmount, node]);
}
// Remove Food items with quantity = 0
for (var i = 0; i < food.length; i++) {
if (food[i][1] === 0) {
food.splice(i, 1);
}
}
if (food.length !== 0) {
$(".shoppingCart").addClass("shoppingCartWithItems");
$(".cartContentDiv").empty();
for (var i = 0; i < food.length; i++) {
let cartTxt =
'<div class="row cartContentRow"><div class="col-10"><div style="display:flex;"><p>' +
food[i][0] +
'</p> <p class="text-muted-small">' +
food[i][3] +
'<p></div><i class="fas fa-rupee-sign"> ' +
food[i][2] +
'</i></p> </div> <div class="col-2"> <p class="text-muted-small" > <i class="fas fa-rupee-sign"></i> ' +
food[i][1] * food[i][2] +
'</p> <span class="cartQuantity"> ' +
" <span> Qty : </span>" +
food[i][1] +
'</span> </div> </div> <hr class="cartHr">';
$(".cartContentDiv").append(cartTxt);
}
} else {
$(".shoppingCart").removeClass("shoppingCartWithItems");
$(".cartContentDiv").empty();
$(".cartContentDiv").append(
'<h1 class="text-muted">Your Cart is Empty</h1>'
);
}
$(".shoppingCartAfter").text(food.length);
if (food.length === 0) {
totalAmount = 0;
}else {
totalAmount = totalAmount + singleFoodAmount;
}
$(".totalAmountDiv").empty();
$(".totalAmountDiv").append(
'<span class="totalAmountText">TOTAL AMOUNT : </span><br/>' +
'<i class="fas fa-rupee-sign"></i> ' +
totalAmount
);
}
});
function openWhatsapp() {
// console.log($('#address'));
if ($("#address")[0].value === "") {
alert("Please Enter your room number");
return;
} else {
let total = 0;
let address = $("#address")[0].value;
let note = $("#note")[0].value;
let wTxt = "*name* *quantity* \n";
for (var i = 0; i < food.length; i++) {
let name = food[i][0];
let quantity = food[i][1];
total = total + food[i][1] * food[i][2];
wTxt = wTxt + name + " " + quantity + " \n";
}
if ($("#note")[0].value === "") {
wTxt =
wTxt + "\n *Total Bill: " + total + "*" + "\n\n Address: " + address;
} else {
wTxt =
wTxt +
"\n *Total Bill: " +
total +
"*" +
"\n\n Address: " +
address +
"\n Note: " +
note;
}
let wTxtEncoded = encodeURI(wTxt);
window.open("https://wa.me/7459943936?text=" + wTxtEncoded);
}
}
// function openWhatsapp() {
// if ($("#address")[0].value === "") {
// alert("Please Enter your room number");
// return;
// } else {
// let total = 0;
// let address = $("#address")[0].value;
// let note = $("#note")[0].value;
// let wTxt = "*name* *quantity* \n";
// for (var i = 0; i < food.length; i++) {
// let name = food[i][0];
// let quantity = food[i][1];
// total = total + food[i][1] * food[i][2];
// wTxt = wTxt + name + " " + quantity + " \n";
// }
// if ($("#note")[0].value === "") {
// wTxt =
// wTxt + "\n *Total Bill: " + total + "*" + "\n\n Address: " + address;
// } else {
// wTxt =
// wTxt +
// "\n *Total Bill: " +
// total +
// "*" +
// "\n\n Address: " +
// address +
// "\n Note: " +
// note;
// }
// let wTxtEncoded;
// let idValue = $("#id").val();
// // Situation 1: id="id1" redirect to first whatsapp number
// if (idValue === "momos") {
// wTxtEncoded = encodeURI(wTxt);
// window.open("https://wa.me/9696279459?text=" + wTxtEncoded);
// // Situation 2: id="id2" redirect to second whatsapp number
// } else if (idValue === "chinese") {
// wTxtEncoded = encodeURI(wTxt);
// window.open("https://wa.me/955677085?text=" + wTxtEncoded);
// // Situation 3: id="id3" redirect to third whatsapp number
// } else if (idValue === "beverages") {
// wTxtEncoded = encodeURI(wTxt);
// window.open("https://wa.me/7965306761?text=" + wTxtEncoded);
// }
// }
// }