-
Notifications
You must be signed in to change notification settings - Fork 0
/
MOVIE3.html
291 lines (230 loc) · 6.74 KB
/
MOVIE3.html
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Movie 3</title>
<style>
body{
background-color: rgb(24, 24, 24);
}
.searchbox{
display: flex;
align-items: center;
justify-content: center;
}
#search2{
margin:1%;
width: 50%;
height:2px;
color:white;
overflow:hidden;
overflow-y:scroll;
border-top: none;
margin-left: 5%;
}
#search2:hover{
height:200px;
}
.searchbox>input{
padding:1%;
width: 50%;
background-color: white;
border:none;
outline: none;
}
.searchbox>button{
padding:1% 5%;
color: white;
font-weight: 600;
background-color: red;
border:none;
}
#data{
color:whitesmoke;
width:100%;
justify-self: center;
font-size: medium;
display: grid;
grid-template-columns: 20% 20% 20% 20%;
gap:5%;
}
#ind{
justify-content: center;
text-align: center;
display: flex;
margin-bottom: 10%;
margin-top: 5%;
text-align: left;
}
#ind:hover{
background-color: coral;
}
.img{
width:100%;
height:200px
}
.img2{
width:200px;
height:300px
}
.divs:hover{
border: 2px solid yellow;
}
.divs2{
color:whitesmoke;
margin-top: 8%;
margin-left: 3%;
}
.divsI{
display: flex;
border:1px solid yellow;
width:80%;
height:70%;
margin:2%;
padding:1%;
}
.divsI2{
padding:2%;
}
.imageI{
width:20%;
height:100%;
}
#signin{
margin-left: 50px;
}
</style>
</head>
<body>
<div class="searchbox">
<input oninput="debounce(main,1000)" id="search" type="text" placeholder="What's in your mind today?"/>
<button onclick="search()">Search</button>
<h3 style="margin-left: 5% ;"><a href="MOVIEpopular.html">Popular Movies</a></h3>
<h3><a href="signUpMovie.html" id="signin">Sign In </a></h3>
</div>
<div id="search2"></div>
<div id="ind"></div>
<div id="data"></div>
<script>
let parent=document.getElementById("data");
let secparent=document.getElementById("ind");
let thirdparent=document.getElementById("search2");
//To show movies on screen
async function search(){
thirdparent.innerHTML=null;//toempty search after search is pressed
try{
var input=document.getElementById("search").value;
var res = await fetch(`http://www.omdbapi.com/?apikey=440690ce&s=${input}`);
var Data=await res.json();
//console.log(Data);
appendMovies(Data.Search);
}
catch{
parent.innerHTML=null;
secparent.innerHTML=null;
let img=document.createElement("img");
img.src="https://i.pinimg.com/originals/ef/8b/bd/ef8bbd4554dedcc2fd1fd15ab0ebd7a1.gif";
secparent.append(img);
}
}
function appendMovies(movies){
parent.innerHTML=null;
secparent.innerHTML=null;
movies.forEach(function(movie){
var divs=document.createElement("div");
divs.setAttribute("class","divs");
var image=document.createElement("img");
image.setAttribute("class","img");
image.src=movie.Poster;
var title=document.createElement("p");
title.textContent="Title:- "+movie.Title;
var relDate=document.createElement("p");
relDate.textContent="Release Date:- "+movie.Year;
var btn=document.createElement("button");
btn.textContent="Go to Movie";
btn.onclick=function(){
details(movie);
}
divs.append(image,title,relDate,btn);
parent.append(divs);
})
}
function details(m){
secparent.innerHTML=null;
var divs2=document.createElement("div");
divs2.setAttribute("class","divs2");
var image2=document.createElement("img");
image2.setAttribute("class","img2");
image2.src=m.Poster;
var title2=document.createElement("p");
title2.textContent="Title:- "+m.Title;
var relDate2=document.createElement("p");
relDate2.textContent="Release Date:- "+m.Year;
divs2.append(title2,relDate2);
secparent.append(image2,divs2);
}
//Debouncing Part
var timerId;
async function searchMovies(movie_name){
try{
let res=await fetch(`http://www.omdbapi.com/?apikey=440690ce&s=${movie_name}`);
let data=await res.json();
return data;
}
catch(e){
console.log(e);
}
}
function appendMovies2(movies){
if(movies===undefined){
return false;
}
thirdparent.innerHTML=null; //instead of appending names, i am creating a new structure of movie data and appending it to the serach2 part
movies.forEach(function(movie){
let divsI=document.createElement("div");
divsI.setAttribute("class","divsI");
let imageI=document.createElement("img");
imageI.src=movie.Poster;
imageI.setAttribute("class","imageI");
let divsI2=document.createElement("div");
divsI2.setAttribute("class","divsI2");
let titleI=document.createElement("p");
titleI.textContent=movie.Title;
divsI2.append(titleI);
let relDateI=document.createElement("p");
relDateI.textContent=movie.Year;
divsI2.append(relDateI);
divsI.onclick=function(){ // to show the movie in enlarged form separately
details(movie);
}
divsI.append(imageI,divsI2);
thirdparent.append(divsI);
})
}
async function main(){
thirdparent.innerHTML=null; // to make sure the debounced data gets updated with respect to updation on screen
let name=document.getElementById("search").value;
let res=await searchMovies(name);
let movie_data=res.Search;
appendMovies2(movie_data);
}
//Debouncing
//debounce would be called at input
function debounce(func,delay){
if(timerId){
clearTimeout(timerId);
}
timerId= setTimeout(function(){
func();
},delay)
}
let nameChange=document.getElementById("signin");
var a= localStorage.getItem("active");
if(a!=null){
nameChange.textContent=a;
}
</script>
</body>
</html>