-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
124 lines (109 loc) · 4.44 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
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
$(document).ready(() => {
$('#searchForm').on('submit', (e) => {
let searchText = $('#searchText').val();
getMovies(searchText);
$('.display__search--header').text('Search results for ' + '"' + searchText + '"');
e.preventDefault();
})
});
$(document).ready(() => {
$('.btn--submit').on('click', (e) => {
let searchText = $('#searchText').val();
getMovies(searchText);
$('.display__search--header').text('Search results for ' + '"' + searchText + '"');
e.preventDefault();
})
});
function getMovies(searchText) {
axios.get('https://www.omdbapi.com/?apikey=957dcbb0&s=' + searchText + '/')
.then((res) => {
console.log(res);
let movies = res.data.Search;
let output = '';
$.each(movies, (index, movie) => {
console.log(movie.Poster);
if (movie.Poster !== "N/A") {
output += `
<div class="movie">
<figure class="movie__img--wrapper">
<img src="${movie.Poster}" alt="" class="movie__img">
</figure>
<h5 class="movie__title">${movie.Title}</h5>
<a href="#" class="btn" onclick="movieSelected('${movie.imdbID}')">Movie Details</a>
</div>
`;
}
})
$('#movies').html(output);
})
.catch((err) => {
console.log(err);
})
}
function movieSelected(id) {
sessionStorage.setItem('movieId', id);
window.location = 'movie.html';
return false;
}
function getMovie() {
let movieId = sessionStorage.getItem('movieId');
axios.get('https://www.omdbapi.com/?apikey=957dcbb0&i=' + movieId)
.then((res) => {
console.log(res);
let movie = res.data;
let output = `
<div class="showcase-movie__about-section">
<figure class="showcase-movie__img--wrapper">
<img src="${movie.Poster}" class="movie__img-thumbnail" alt="">
</figure>
<div class="showcase-movie__about">
<h2 class="showcase-movie__about--title">${movie.Title}</h2>
<ul class="showcase-movie__lists">
<li class="showcase-movie__list">
<Strong>Genre:</Strong> ${movie.Genre}
</li>
<li class="showcase-movie__list">
<Strong>Released:</Strong> ${movie.Released}
</li>
<li class="showcase-movie__list">
<Strong>Rated:</Strong> ${movie.Rated}
</li>
<li class="showcase-movie__list">
<Strong>IMDB Rating:</Strong> ${movie.imdbRating}
</li>
<li class="showcase-movie__list">
<Strong>Director:</Strong> ${movie.Director}
</li>
<li class="showcase-movie__list">
<Strong>Writer:</Strong> ${movie.Writer}
</li>
<li class="showcase-movie__list">
<Strong>Actors:</Strong> ${movie.Actors}
</li>
</ul>
</div>
</div>
<div class="showcase-movie__description">
<div class="showcase-movie__description--para">
<h3 class="showcase-movie__description--title">Plot</h3>
${movie.Plot}
<hr />
<div class="showcase-movie__links--list">
<a class="showcase-movie__link click" href='https://imdb.com/title/${movie.imdbID}/' target="_blank">View IMDB</a>
<a class="showcase-movie__link click" href="index.html">Go Back to Search</a>
</div>
</div>
</div>
`;
$('#showcase-movie').html(output);
})
.catch((err) => {
console.log(err);
})
}
function openMenu() {
document.body.classList += " menu--open";
}
function closeMenu() {
document.body.classList.remove("menu--open");
}