-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjs.js
175 lines (150 loc) · 4.74 KB
/
js.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
let app_id = config.app_id;
let app_key = config.app_key;
let b = false;
let count = 0;
let o = false;
let isdrop = false;
let spinner = `<div class="spinner-border text-primary"
id="spinner" role="status">
<span class="sr-only"></span>
</div>`
document.querySelector("#content").innerHTML = spinner;
let modal = document.querySelector("#staticBackdrop");
const button = document.getElementById("search");
let counter = 0;
const quantity = 10;
button.addEventListener("click", ()=>
{
b = true;
console.log(document.getElementById('inp').value);
document.querySelector("#content").innerHTML = spinner;
counter = 0;
count = 0;
getData();
})
function dropdown(event)
{
isdrop = true;
window.cuisine = event.dataset.cuisine;
counter = 0;
document.querySelector("#content").innerHTML = spinner;
dropdowndata();
}
function dropdowndata()
{
const start = counter;
const end = start + quantity;
counter = end+1;
isdrop = true;
let app_id = "ae9ec6b9";
let app_key = "14b9a265b9446d71415e30308065834f";
fetch(`https://api.edamam.com/search?app_id=${app_id}&app_key=${app_key}&q&cuisineType=${window.cuisine}&from=${start}&to=${end}`)
.then(response => response.json())
.then(data =>{
console.log(data);
d(data);
})
.catch(error =>{
window.location.reload();
})
}
function onl(){
const start = counter;
const end = start + quantity;
counter = end+1;
let app_id = "ae9ec6b9";
let app_key = "14b9a265b9446d71415e30308065834f";
fetch(`https://api.edamam.com/search?app_id=${app_id}&app_key=${app_key}&q&cuisineType=Chinese&from=${start}&to=${end}`)
.then(response => response.json())
.then(data =>{
console.log(data);
d(data);
});
}
function getData()
{
const start = counter;
const end = start + quantity;
counter = end+1;
let inp = document.getElementById("inp").value;
fetch(`https://api.edamam.com/search?app_id=${app_id}&app_key=${app_key}&q=${inp}&from=${start}&to=${end}`)
.then(response => response.json())
.then(data =>{
console.log(data);
d(data);
})
}
function md(recipe)
{
console.log(recipe);
document.getElementById('staticBackdropLabel').innerHTML = recipe.label;
document.getElementById('link').href = recipe.url;
let ing = document.getElementById('ingredients');
ing.innerHTML = "";
document.getElementById('nutrients').innerHTML = "";
document.getElementById('mealType').innerHTML = recipe.mealType;
document.getElementById('dishType').innerHTML = recipe.dishType;
document.getElementById('dietLabel').innerHTML = recipe.dietLabels;
document.getElementById('yield').innerHTML = recipe.yield;
document.getElementById('cal').innerHTML = parseInt(recipe.calories);
for(let i = 0;i<recipe.ingredients.length;i++)
{
let ingredient = document.createElement('li');
ingredient.innerHTML = recipe.ingredientLines[i];
console.log(recipe.ingredientLines[i]);
ing.appendChild(ingredient);
}
const nutlabel = Object.values(recipe.totalNutrients);
for(let i =0;i<nutlabel.length;i++)
{
let nutrient = document.createElement('div');
nutrient.innerHTML = nutlabel[i].label;
document.getElementById('nutrients').appendChild(nutrient);
}
}
function d(data)
{
for(let i = 0;i<data.hits.length;i++)
{
let rec = JSON.stringify(data.hits[i].recipe);
document.getElementById('spinner').style.display = 'none';
let toAdd = document.createElement('div');
toAdd.className = "col";
toAdd.innerHTML =`
<div class="card" style="width:18rem;">
<img class="card-img-top" src="${data.hits[i].recipe.image}" alt="Card image cap">
<div class="card-body">
<h6 class="card-title">${data.hits[i].recipe.label}</h6>
</div>
<div><button id='but' type='button' class='btn btn-primary' data-bs-toggle='modal' data-bs-target='#staticBackdrop' onclick='md(${rec})'>Recipe</button></div>
</div>`
;
document.querySelector("#content").appendChild(toAdd);
}
if(b & !count || isdrop){
setTimeout(2000);
document.querySelector("#content").scrollIntoView(true);
}
o = true;
}
// window.onscroll = () => {
// if(window.innerHeight + window.scrollY >= document.body.offsetHeight && o)
// {
// if(isdrop)
// {
// dropdowndata();
// }
// else
// {
// if(!b)
// {
// onl();
// }
// else
// {
// count+=1;
// getData();
// }
// }
// }
// }