-
Notifications
You must be signed in to change notification settings - Fork 0
/
imdb-API.js
67 lines (64 loc) · 2.67 KB
/
imdb-API.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
$(".input-keyword").on("change", function () {
$.ajax({
url:
"http://www.omdbapi.com/?apikey=77f07a9d&s=" + $(".input-keyword").val(),
success: (result) => {
const movies = result.Search;
let cards = "";
movies.forEach((m) => {
cards += showCards(m);
});
$(".movie-container").html(cards);
// todo Ketika tombol Detail di klik
$(".modal-detail-button").on("click", function () {
$.ajax({
url:
"http://www.omdbapi.com/?apikey=77f07a9d&i=" + $(this).data("id"),
success: (m) => {
const movies = showMoviesDetails(m);
$(".modal-body").html(movies);
},
error: (e) => {
console.log(e.responseText);
},
});
});
},
error: (e) => {
console.log(e.responseText);
},
});
});
const showCards = (m) => {
return `<div class="col-md-4 my-3">
<div class="card">
<img src="${m.Poster}" class="card-img-top">
<div class="card-body">
<h5 class="card-title">${m.Title}</h5>
<h6 class="card-subtitle mb-2 text-muted">${m.Year}</h6>
<a href="#" class="btn btn-primary modal-detail-button" data-bs-toggle="modal" data-bs-target="#movieDetailModal" data-id="${m.imdbID}">Show Details</a>
</div>
</div>
</div>`;
};
const showMoviesDetails = (m) => {
return `<div class="container-fluid">
<div class="row">
<div class="col-md-3">
<img src="${m.Poster}" alt="" class="img-fluid">
</div>
<div class="col-md">
<ul class="list-group list-group-flush">
<li class="list-group-item">
<h2>${m.Title} (${m.Year})</h2>
</li>
<li class="list-group-item"><strong>Director : </strong>${m.Director}</li>
<li class="list-group-item"><strong>Actors : </strong>${m.Actors}</li>
<li class="list-group-item"><strong>Genre : </strong>${m.Genre}</li>
<li class="list-group-item"><strong>Writer : </strong>${m.Writer}</li>
<li class="list-group-item"><strong>Plot : </strong><br>${m.Plot}</li>
</ul>
</div>
</div>
</div>`;
};