-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
186 lines (126 loc) · 5.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
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
const films = document.getElementById("films")
const filmList = document.getElementById('film-list');
const logo = document.getElementById('logo');
const searchBar = document.getElementById('searchBar');
const filmPoster = document.getElementsByClassName('filmPoster');
const buttons = document.getElementsByClassName('carousel-button');
const bannerList = document.getElementById('bannerList');
const overlay = document.getElementsByClassName('overlay');
const showModalBtn = document.getElementsByClassName('showModalBtn');
const closeModalBtn = document.getElementsByClassName('closeModalBtn');
const descriptionParagraph = document.getElementById('descriptionParagraph');
const backToTop = document.querySelector('footer');
// Alert: Unavailable API Disclaimer:
// alert("Hello Viewer! \nThe Studio Ghibli API that I used for this application is currently unavailable. While we wait for the API creator to fix up the bugs and get it back up and running, please do check out my code walkthrough for this project instead: https://flip.com/s/ccBeiiFHW9tp. \n \nIt's no Howl's Moving Castle, but I do explain how I made this application and what it looks like when the API works. I look forward to sharing this application with you soon! :) \n - Janhavi ");
let state;
// let filmNames;
//FETCHING API DATA
async function fetchAPIdata() {
try {
const response = await fetch("https://ghibli.rest/films")
const data = await response.json();
state = data
boxedFilms();
searchResultFilms(state);
console.log(bannerArrayFunction(state));
loop(bannerArrayFunction);
// ?unnecessary//
// retrievingBanners(state);
// ?unnecessary//
} catch (error) {
console.error(error)
}
}
fetchAPIdata();
// FILMS + THEIR DESCRIPTIONS
function boxedFilms() {
state.forEach(movie => {
const box = document.createElement('div')
box.setAttribute('class', 'box')
const h2 = document.createElement('h2')
h2.innerHTML = movie.title
const information = document.createElement('p')
information.innerHTML = `${movie.description}`
box.appendChild(h2)
box.appendChild(information)
films.appendChild(box)
})
}
// SEARCH BAR:
// EVENT LISTENER
searchBar.addEventListener("keydown", (e) => {
console.log(e.target.value);
const searchString = e.target.value.toLowerCase();
const filteredTitles = state.filter((state) => {
return (state.title.toLowerCase().includes(searchString) ||
state.director.toLowerCase().includes(searchString))
});
// console.log(filteredTitles);
searchResultFilms(filteredTitles);
});
// DISPLAY OF FILMS RETURNED FROM THE SEARCH
const searchResultFilms = (films) => {
const htmlString = films
.map((films) => {
return `
<li class ="films-list">
<h2>${films.title}</h2>
<h4>Directed by: <br> ${films.director}</h4>
<img class="filmPoster" src="${films.image}" />
<button class="showModalBtn" onclick="onClick(event)" value="${films.description}"> Description </button>
<div id="containerForHeartIcon" >
<i onclick="toggler(event)" id="heartIcon" class="fa-regular fa-heart"> </i>
</div>
</li>`;
})
.join('');
filmList.innerHTML = htmlString;
};
//Like Button
function toggler(event) {
const target = event.target;
// console.log(target)
if (target.classList.contains("fa-regular")) {
target.classList.replace('fa-regular', 'fa-solid');
} else {
target.classList.replace('fa-solid', 'fa-regular');
}
}
// MODAL
function onClick(event) {
const target = event.target;
overlay[0].classList.toggle('hidden');
descriptionParagraph.innerHTML = target.value;
}
closeModalBtn[0].addEventListener("click", (e) => {
console.log(e.target.value);
overlay[0].classList.toggle('hidden');
})
backToTop.addEventListener("click", () => {
document.documentElement.scrollTop = 0;
})
const bannerArrayFunction = (picture) => {
const listOfBannerImages = picture
.map((picture) => {
return `
<li class="banner-list">
<img src="${picture.movie_banner}" alt="${picture.title}"/>
</li>`;
})
return listOfBannerImages;
// bannerList.innerHTML = listOfBannerImages;
//consider adding a after/before pseudoElement to have the name of the respective movie, showing up in the corner?//
// console.log(listOfBannerImages)
}; //listOfBannerImages contains the (joined)array of banner images in the list tags
function loop (listOfBannerImages) {
for (let i= 0; i < listOfBannerImages.length; i++) {
}
}
// ?unnecessary//
const retrievingBanners = (picture) => {
const filmBanners = picture.map((picture) => {
return picture.movie_banner;
})
// console.log(filmBanners);
}
// ?unnecessary//