-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
270 lines (224 loc) · 8.37 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
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 = Number(quantity.parent().siblings('div').children().last().text());
let count = Number(quantity.text());
if ($(this)[0].className.search('plus') > -1) {
count = count + 1;
quantity.text(count);
ToCart(foodNameClicked, count, 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, singleFoodAmount);
}
}
});
function ToCart(foodNameClicked, foodQuantity, singleFoodAmount) {
let foodAlreadyThere = false;
let foodPos;
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]);
} else {
food.push([foodNameClicked, foodQuantity, singleFoodAmount]);
}
// 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"> <p>' + food[i][0] + ' </p> <p class="text-muted-small"><i class="fas fa-rupee-sign"></i>' + food[i][2] + '</p> </div> <div class="col-2"> <span class="cartQuantity">' + food[i][1] + '</span> <p class="text-muted-small"><i class="fas fa-rupee-sign"></i>' + food[i][1] * food[i][2] + '</p> </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('Total Amount: ' + totalAmount);
}
});
function openWhatsapp() {
// console.log($('#address'));
if ($('#address')[0].value === "") {
alert("Please Enter Address");
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/919871198882?text=" + wTxtEncoded);
}
}
// Did not work out code
// let totalAmount = 0;
// let foodNameClickedArray = [];
// let singleFoodAmountArray = [];
// let foodQuantityArray = [];
//
// function addToCart(foodNameClicked, foodQuantity, singleFoodAmount) {
//
// if (foodNameClickedArray.indexOf(foodNameClicked) > -1) {
//
// foodNameClickedArray.splice(foodNameClickedArray.indexOf(foodNameClicked), 1);
// foodNameClickedArray.push(foodNameClicked.trim());
//
// if (singleFoodAmountArray.indexOf(singleFoodAmount) > -1) {
// singleFoodAmountArray.splice(singleFoodAmountArray.indexOf(singleFoodAmount), 1);
// singleFoodAmountArray.push(singleFoodAmount);
// }
//
// if (foodQuantityArray.indexOf(foodQuantity - 1) > -1) {
// foodQuantityArray.splice(foodQuantityArray.indexOf(foodQuantity - 1), 1);
// foodQuantityArray.push(foodQuantity);
// }
//
// } else {
// foodNameClickedArray.push(foodNameClicked.trim());
// singleFoodAmountArray.push(singleFoodAmount);
// foodQuantityArray.push(foodQuantity);
// }
//
// totalAmount = totalAmount + singleFoodAmount;
//
// console.log(foodNameClickedArray);
// console.log(foodQuantityArray);
// console.log(singleFoodAmountArray);
// console.log('Total Bill: ', totalAmount);
// }
// function removeFromCart(foodNameClicked, foodQuantity, singleFoodAmount) {
// if (foodQuantity > 0) {
// if (foodQuantityArray.indexOf(foodQuantity + 1) > -1) {
// console.log(foodQuantityArray.indexOf(foodQuantity + 1));
//
// foodQuantityArray.splice(foodQuantityArray.indexOf(foodQuantity + 1), 1);
// foodNameClickedArray.splice(foodQuantityArray.indexOf(foodQuantity + 1), 1);
// singleFoodAmountArray.splice(foodQuantityArray.indexOf(foodQuantity + 1), 1);
//
// foodQuantityArray.push(foodQuantity);
// foodNameClickedArray.push(foodNameClicked);
// singleFoodAmountArray.push(singleFoodAmount);
// }
//
// }
//
// totalAmount = totalAmount - singleFoodAmount;
//
//
// console.log(foodNameClickedArray);
// console.log(foodQuantityArray);
// console.log(singleFoodAmountArray);
// console.log('Total Bill: ', totalAmount);
// }