-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (25 loc) · 1 KB
/
index.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
const searchBar = document.querySelector('.search-bar');
const apiURL = 'http://www.omdbapi.com/?apikey=b78d8af3&';
const Http = new XMLHttpRequest();
let mediaItem;
var searchValue;
searchBar.addEventListener('keydown', event => {
if(event.keyCode == 13) {
searchValue = searchBar.value;
apiResult = getMediaInformationFromAPIWithTitle(searchValue);
}
});
function getMediaInformationFromAPIWithTitle(mediaName) {
let urlWithQuery = apiURL + 't=' + mediaName;
fetch(urlWithQuery)
.then(response => response.json())
.then(data => showApiResults(data));
}
function showApiResults(data) {
document.querySelector('.media-item').style.visibility = 'visible';
document.querySelector('.media-item--img').src = data.Poster;
document.querySelector('.media-item--title').innerHTML = data.Title;
document.querySelector('.media-item--year').innerHTML = data.Year;
document.querySelector('.media-item--plot').innerHTML = data.Plot;
document.querySelector('.media-item--genre').innerHTML = data.Genre;
}