-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.html
104 lines (81 loc) · 2.39 KB
/
search.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Search</title>
<link rel="stylesheet" href="./styles/navbar.css">
<link rel="stylesheet" href="./styles/search.css">
<style>
</style>
</head>
<body>
<div id="navbar"></div>
<h1>Search Here</h1>
<!-- <input id="query" oninput="getData()"> -->
<input type="text" id="query" oninput="de_bouncing(main,1000)" placeholder="Enter your favorite Dish">
<div id="inputBox"></div>
<div id="display"></div>
</body>
</html>
<script type="module">
import nav from "./components/navbar.js";
document.getElementById("navbar").innerHTML=nav()
</script>
<script>
let id;
let myFunction = async (q)=> {
let url = `https://www.themealdb.com/api/json/v1/1/search.php?s=${q}`;
// let url = `www.themealdb.com/api/json/v1/1/search.php?f=${q}`
let res = await fetch(url);
let data = await res.json()
data = data.meals
return data
}
let main = async() =>{
var q = document.getElementById("query").value;
let getData = await myFunction(q)
append(getData)
// console.log(getData)
}
let de_bouncing = (func,delay) => {
if(id){
clearTimeout(id)
}
id = setTimeout(function(){
func()
},delay)
}
let cont = document.getElementById("display")
let inputBox = document.getElementById("inputBox")
let append = (data)=>{
cont.innerHTML=""
inputBox.innerHTML=null;
data.forEach(({strMeal,strMealThumb})=>{
let obj ={
name:strMeal,
img:strMealThumb
}
//console.log(obj)
let name = document.createElement("p");
name.innerText=strMeal;
name.addEventListener("click",function(){
cardFun(obj)
})
inputBox.append(name)
})
}
let cardFun = (data) =>{
cont.innerHTML=""
let card = document.createElement("div");
card.setAttribute("class","card")
let img = document.createElement("img");
img.src=data.img;
let name = document.createElement("p");
name.innerText=data.name;
card.append(name,img)
cont.append(card)
console.log(data)
}
</script>