mandalorian/scripts/films.js

33 lines
1.3 KiB
JavaScript
Raw Normal View History

2021-10-20 08:07:16 +00:00
import { api_call } from './util';
2021-10-19 15:47:47 +00:00
2021-10-20 08:07:16 +00:00
const films = document.getElementById("resultats");
2021-10-19 15:47:47 +00:00
const API_URL = "https://swapi.dev/api/films/"; // déclare la localisation de la liste des films
2021-10-20 08:07:16 +00:00
2021-10-20 08:53:02 +00:00
function remplissage(EPISODES) {
console.log(EPISODES);
for (index in EPISODES.results) {
films.innerHTML += `
2021-10-20 08:07:16 +00:00
<section class="resultat accordeon_item">
2021-10-20 08:53:02 +00:00
<h1 class="accordeon_item_header">${EPISODES.results[index].title}</h1>
<div class="accordeon_item_body">
<div class="column1">
<p class= "episode">Episode : ${EPISODES.results[index].episode_id}</p>
<p class= "directeur">Directeur : ${EPISODES.results[index].director}</p>
<p class= "producteur">Producteur : ${EPISODES.results[index].producer}</p>
<p class= "sortie">Date de Sortie : ${EPISODES.results[index].release_date}</p>
</div>
</div>
2021-10-20 08:07:16 +00:00
</section>`
2021-10-20 08:53:02 +00:00
}
const accordeonItemHeader = document.querySelectorAll(".accordeon_item_header");
accordeonItemHeader.forEach(accordeonItemHeader => {
2021-10-20 08:07:16 +00:00
accordeonItemHeader.addEventListener("click", event => {
2021-10-20 08:53:02 +00:00
accordeonItemHeader.classList.toggle("active");
2021-10-20 08:07:16 +00:00
})
2021-10-20 08:53:02 +00:00
})
}
2021-10-19 15:47:47 +00:00
2021-10-20 08:07:16 +00:00
api_call(API_URL, remplissage);