-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
162 lines (149 loc) · 5.53 KB
/
script.js
File metadata and controls
162 lines (149 loc) · 5.53 KB
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
class Dish {
constructor(name, country, prepTime, servings, ingredients, description, nutrition, allergies, image, month, image2, continent, recipeImg1, recipeImg2, recipe1, recipe2, resturantImg1, resturantImg2, resturant1, resturant2) {
this.name = name;
this.country = country;
this.prepTime = prepTime;
this.servings = servings;
this.ingredients = ingredients;
this.description = description;
this.nutrition = nutrition;
this.allergies = allergies;
this.image = image;
this.month = month;
this.image2 = image2;
this.continent = continent;
this.recipeImg1 = recipeImg1;
this.recipeImg2 = recipeImg2;
this.recipe1 = recipe1;
this.recipe2 = recipe2;
this.resturantImg1 = resturantImg1;
this.resturantImg2 = resturantImg2;
this.resturant1 = resturant1;
this.resturant2 = resturant2;
}
generateHTML() {
const newName = this.name.toLowerCase().replace(/ /g, '-');
console.log(this);
return `
<div class="food-item" onclick="setDishData('${this.name}', '${this.country}', '${this.prepTime}', '${this.description}', '${this.nutrition}', '${this.allergies}', '${this.image}', '${this.image2}', '${this.continent}', '${this.recipeImg1}', '${this.recipeImg2}', '${this.recipe1}', '${this.recipe2}', '${this.resturantImg1}', '${this.resturantImg2}', '${this.resturant1}', '${this.resturant2}')">
<img src="${this.image}" alt="${this.name}">
<a href="./foodPages/${newName}.html" class="foodButton0">
<div class="overlay">
<h3>${this.name}</h3>
</div>
</a>
</div>
`;
}
insertHTML(id) {
const container = document.getElementById(id); // Use the single container
container.innerHTML += this.generateHTML(); // Add the HTML to the unified container
}
}
function filterByContinent() {
const selectedContinent = document.getElementById("continent").value;
const foodContainer = document.getElementById("foodContainer1");
console.log(selectedContinent);
// Clear current dishes
foodContainer.innerHTML = "";
for(let i = 0; i < 12; i++){
for(let j = 0; j < dishes[i].length; j++){
if (i != months[thisMonth]) {
if(dishes[i][j].continent === selectedContinent || selectedContinent === "Worldwide"){
dishes[i][j].insertHTML("foodContainer1");
}
}
}
}
}
function setDishData(name, country, prepTime, description, nutrition, allergies, image, image2, continent, recipeImg1, recipeImg2, recipe1, recipe2, resturantImg1, resturantImg2, resturant1, resturant2) {
const dishData = {
name,
country,
prepTime,
description,
nutrition,
allergies,
image,
image2,
continent,
recipeImg1,
recipeImg2,
recipe1,
recipe2,
resturantImg1,
resturantImg2,
resturant1,
resturant2
};
localStorage.setItem('selectedDish', JSON.stringify(dishData));
}
const months = {
January: 0,
February: 1,
March: 2,
April: 3,
May: 4,
June: 5,
July: 6,
August: 7,
September: 8,
October: 9,
November: 10,
December: 11
};
const date = new Date();
const options = { month: 'long' };
const thisMonth = date.toLocaleDateString('en-US', options);
const dishes = [[], [], [], [], [], [], [], [], [], [], [], []];
try {
fetch('data.json')
.then(response => response.json())
.then(data => {
console.log(data)
for(let i = 0; i < data.length; i++){
const dish = new Dish(
data[i].name,
data[i].country,
data[i].prepTime,
data[i].servings,
data[i].ingredients,
data[i].description,
data[i].nutrition,
data[i].allergies,
data[i].image,
data[i].month,
data[i].image2,
data[i].continent,
data[i].recipeImg1,
data[i].recipeImg2,
data[i].recipe1,
data[i].recipe2,
data[i].resturantImg1,
data[i].resturantImg2,
data[i].resturant1,
data[i].resturant2
);
dishes[(data[i].month) - 1].push(dish);
}
console.log("this is how many months" + dishes[months[thisMonth]].length);
for (let i = 0; i < dishes[months[thisMonth]].length; i++) {
dishes[months[thisMonth]][i].insertHTML("foodContainer0");
}
for (let i = 0; i < 12; i++){
for (let j = 0; j < dishes[i].length; j++) {
if (i != months[thisMonth]){
dishes[i][j].insertHTML("foodContainer1");
}
}
}
});
} catch (error) {
console.error('Error fetching json data:', error);
}
function getMonth(){
const date = new Date();
const options = { month: 'long' };
return date.toLocaleDateString('en-US', options);
}
document.getElementById("currentMonth").textContent = getMonth();