-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
157 lines (137 loc) · 4.74 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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
'use strict'
//const { title } = require("process");
const tdApiKey = '344207-MovieGen-7ZJ76CWA';
const tasteDive = 'https://tastedive.com/api/similar';
const omdbKey = '3e8e016d';
const omdb = "http://www.omdbapi.com/?apikey='3e8e016d'&"
//SPLASH SCREEN TO DISAPPEAR ON BUTTON CLICK
$('.entrance').on('click', function () {
$('.dashboard').removeClass('hidden');
$('.introduction').addClass('hidden');
})
//DASH SEARCH BAR CLICKED
$('.dash-search-butt').on('click', function () {
$('.dashboard').addClass('hidden');
$('.user-search').removeClass('hidden');
//$('.continous-search').removeClass('hidden');
})
$('.close').on('click', function() {
$('.user-results-screen').addClass('hidden');
$('.continous-search').addClass('hidden');
$('.dashboard').removeClass('hidden');
$('.search-bar').val("");
$('.search-bar-header').val("");
$('.user-results-screen').empty();
$('.error').addClass('hidden');
})
// $('.genre').on('click', function() {
// $('.dashboard').addClass('hidden');
// $('.scifi-page').removeClass('hidden');
// })
$('.start-over').on('click', function () {
$('.restart').removeClass('hidden');
$('.movie-title-screen').removeClass('hidden');
$('.search-bar').val("");
$('.user-results-screen').addClass('hidden');
$('.user-results-screen').empty();
$('.restart-footer').addClass('hidden');
$('.continous-search').addClass('hidden');
})
$('.hide').on('click', function () {
$('.snackbar').addClass('hidden');
})
function watchTitleForm() {
$('.user-title-form').submit(event => {
event.preventDefault();
$('.loader').removeClass('hidden')
let title = $('.search-bar').val();
$('.dashboard').addClass('hidden');
$('.movie-title-screen').addClass('hidden');
$('.continous-search').removeClass('hidden');
$('.restart').addClass('hidden');
getMovies(title);
});
$('.header-form').submit(event => {
event.preventDefault();
let title = $('.search-bar-header').val();
$('.restart-footer').addClass('hidden');
$('.loader').removeClass('hidden')
$('.error').addClass('hidden');
$('.user-results-screen').empty();
getMovies(title);
})
}
function getMovies(title) {
var params = {
q: title,
type: 'movies',
info: 0,
limit: 20,
k: '344207-MovieGen-7ZJ76CWA',
callback: 'result'
};
var results = $.ajax({
url: "https://tastedive.com/api/similar",
data: params,
dataType: "jsonp",
type: "GET"
})
.done(function (output) {
if (output.Similar.Results.length == 0) {
$('.error').removeClass('hidden');
$('.loader').addClass('hidden');
$('.movie-title-screen').addClass('hidden');
$('.search-bar').val("");
$('.continous-search').removeClass('hidden');
$('.restart').addClass('hidden');
$('.search-bar-header').val("");
} else {
for (let i = 0; i < output.Similar.Results.length; i++) {
titleInfo(output.Similar.Results[i].Name);
}
}
})
};
function titleInfo(title) {
fetch(`https://www.omdbapi.com/?apikey=3e8e016d&t=${title}`)
.then(res => res.json())
.then(data => {
console.log(data)
$('.loader').addClass('hidden')
displayResults(data)
})
}
function displayResults(data) {
$('.user-results-screen').append(`
<section class="single-result">
<div class="poster-container">
<img id="poster" src="${data.Poster}" alt="Movie Poster">
</div>
<div class="main-container">
<div class="title-container">
<h2 id="title">${data.Title}</h2>
</div>
<div class="sub-container">
<div class="rating-container">
<p id="rating">${data.Rated}</p>
</div>
<div class="score-container">
<img src="IMG/rotten-tomatoes-rating-icons-3@2x 1.png">
<p id="score">${data.Metascore}</p>
</div>
<div class="year-container">
<p id="year">${data.Year}</p>
</div>
</div>
<div class="actors-container">
<p id="actors">${data.Genre}</p>
</div>
</a>
</section>
`);
$('.snackbar').removeClass('hidden');
$('.user-results-screen').removeClass('hidden');
$('.restart-footer').removeClass('hidden');
$('.movie-title-screen').addClass('hidden');
}
$(watchTitleForm);