-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
75 lines (59 loc) · 2.45 KB
/
Copy pathmain.js
File metadata and controls
75 lines (59 loc) · 2.45 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
import TheMealDB from "./theMealDB.mjs"
console.log("loading js");
function show_meal(meal) {
const meal_container = document.getElementById("meal_container");
meal_container.classList.remove("hidden");
const meal_id = meal.idMeal;
const title = meal.strMeal;
const category = meal.strCategory;
const area = meal.strArea;
const instructions = meal.strInstructions;
const image = meal.strMealThumb;
// ingredients and their measures under "strIngredient1" and "strMeasure1", incrementing
// add information to document
document.getElementById("meal_title").innerText = title;
document.getElementById("meal_category").innerText = category;
document.getElementById("meal_area").innerText = area;
document.getElementById("meal_image").src = image;
// add ingredients to table
const ingredient_table = document.getElementById("meal_ingredients");
let i = 1;
let ingredient_key = `strIngredient`;
let measurement_key = `strMeasure`;
while (meal[ingredient_key+i] !== undefined && meal[ingredient_key+i] !== "") {
const row = document.createElement("tr");
row.className = "meal_ingredients_entry";
const ingredient = document.createElement("td");
ingredient.innerText = `${meal[ingredient_key+i]}`;
const measure = document.createElement("td");
measure.innerText = `${meal[measurement_key+i]}`;
row.appendChild(ingredient);
row.appendChild(measure);
ingredient_table.appendChild(row);
i++;
}
// add instructions
document.getElementById("meal_instructions").innerText = instructions;
// hide iframe if no content
// const iframe_youtube = document.getElementById("meal_youtube");
// iframe_youtube.src = meal.strYoutube;
// if (meal.strYoutube === "") {
// iframe_youtube.style.display = 'none';
// } else {
// iframe_youtube.style.display = 'block';
// }
}
function removeElementsByClass(className){
let elements = document.getElementsByClassName(className);
while(elements.length > 0){
elements[0].parentNode.removeChild(elements[0]);
}
}
function clear_meal() {
removeElementsByClass("meal_ingredients_entry");
}
document.getElementById("button_show_random").onclick = function() {
clear_meal();
const random_meal = TheMealDB.get_random()['meals'][0];
show_meal(random_meal);
};