mandalorian/scripts/planets.js

56 lines
1.6 KiB
JavaScript
Raw Normal View History

import { api_call, API_URL, createPagination } from "./util";
2021-10-18 15:32:20 +00:00
2021-10-19 07:47:51 +00:00
2021-10-19 15:35:05 +00:00
const planetes = document.getElementById("resultats");
2021-10-18 15:32:20 +00:00
2021-10-19 13:23:08 +00:00
2021-10-19 14:04:18 +00:00
function remplissage(results) {
2021-10-19 08:31:51 +00:00
planetes.innerHTML = "";
2021-10-19 08:31:51 +00:00
const previousUrl = results.previous;
const nextUrl = results.next;
const tabResults = results.results;
2021-10-19 14:04:18 +00:00
for (resultPlanet of tabResults) {
2021-10-19 08:31:51 +00:00
const nom = resultPlanet.name;
const diametre = resultPlanet.diameter;
const climate = resultPlanet.climate;
const terrain = resultPlanet.terrain;
const population = resultPlanet.population;
const tabResidents = resultPlanet.residents;
2021-10-19 09:52:12 +00:00
const tabFilms = resultPlanet.films;
2021-10-19 08:31:51 +00:00
2021-10-19 14:04:18 +00:00
planetes.innerHTML +=
2021-10-19 20:23:22 +00:00
`<section class="resultat accordeon_item">
<h1 class="accordeon_item_header">${nom}</h1>
<div class="accordeon_item_body">
2021-10-20 08:37:54 +00:00
<div class="column1">
<p>${terrain}</p>
<p>${climate}</p>
<p>${diametre}Km</p>
</div>
2021-10-20 08:37:54 +00:00
<div class="column2">${tabResidents}</div>
<div class="column3">${tabFilms}</div>
</div>
</section>`;
2021-10-19 08:31:51 +00:00
}
2021-10-19 07:47:51 +00:00
2021-10-20 08:37:54 +00:00
//Pagination
createPagination(previousUrl, nextUrl, planetes, remplissage);
2021-10-19 20:23:22 +00:00
const accordeonItemHeader = document.querySelectorAll(".accordeon_item_header");
2021-10-20 08:53:02 +00:00
accordeonItemHeader.forEach(accordeonItemHeader => {
accordeonItemHeader.addEventListener("click", event => {
accordeonItemHeader.classList.toggle("active");
2021-10-19 20:23:22 +00:00
});
2021-10-20 08:53:02 +00:00
});
2021-10-19 13:23:08 +00:00
}
2021-10-19 13:23:08 +00:00
api_call(API_URL + "/planets", remplissage);
2021-10-19 15:35:05 +00:00
console.log('planet.js loaded');