-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
78 lines (71 loc) · 2.12 KB
/
script.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
let api_key = "41bfffe9"
let id;
let result = document.getElementById("result")
async function search(query) {
let link = `https://www.omdbapi.com/?s=${query}&apikey=${api_key}`
let res = await fetch(link)
let data = await res.json()
displayData(data.Search)
// console.log(data.Search)
}
function main() {
let query = document.getElementById("search-box").value
// console.log(query)
search(query)
}
function displayData(movie) {
if (movie == undefined) {
return false
}
console.log(movie)
result.innerHTML = null
movie.forEach(function (el) {
// console.log(el)
let card = document.createElement("div")
card.setAttribute("class", "card")
card.addEventListener("click",function(){
showData(el)
})
let p = document.createElement("p")
p.setAttribute("class", "p")
p.innerText = el.Title
let image = document.createElement("img")
image.setAttribute("class", "image")
image.src = el.Poster
image.alt = "Poster Not Available"
// console.log(p)
card.append(image, p)
result.append(card)
})
}
function debounce(fun, delay) {
if (id) {
clearTimeout(id)
}
id = setTimeout(function () {
fun()
}, delay)
}
function showData(ele){
result.innerHTML=null
let picture=document.getElementById("display_box")
picture.innerHTML=null
let div=document.createElement("div")
div.setAttribute("class","select")
let poster=document.createElement("div")
poster.setAttribute("class","top")
let content=document.createElement("div")
content.setAttribute("class","bottom")
let photo=document.createElement("img")
photo.src=ele.Poster
photo.setAttribute("class","photo")
let name=document.createElement("h3")
name.setAttribute("class","name")
name.innerText=`Movie Name - ${ele.Title}`
let year=document.createElement("h3")
year.innerText=`Year of release - ${ele.Year}`
content.append(name,year)
poster.append(photo)
div.append(poster,content)
picture.append(div)
}