diff --git a/films.html b/films.html index 5d1f049..a5a7240 100644 --- a/films.html +++ b/films.html @@ -1,19 +1,18 @@ - + - Brief Star Wars - Films + Brief Star Wars - FILMS -

People

+

FILMS

+
- -
diff --git a/scripts/films.js b/scripts/films.js index 3bbd7b5..d8e1eb8 100644 --- a/scripts/films.js +++ b/scripts/films.js @@ -1,27 +1,135 @@ -const FILMS = document.getElementById('container'); -const API_URL = "https://swapi.dev/api/films"; +const API_URL = "https://swapi.dev/api/films/?page="; +let pageEnCours = 1; -fetch(API_URL) -.then((reponse) => { - //console.log(reponse); - return reponse.json() -}) -.then(reponseFormat => { - for(let index = 0; index < reponseFormat.results.length; index++){ - //console.log(reponseFormat.results[index]); - const data = reponseFormat.results[index]; - console.log(data); - - FILMS.innerHTML +=` -

${data.title}

-

${data.episode_id}

-

${data.opening_crawl}

-

${data.director}

-

${data.producer}

-

${data.release_date}

-

${data.starships}

-

${data.starships}

-
` +// function pour afficher les films et leur correspondances +async function getMovies() { + const url = 'http://swapi.dev/api/films'; + const FILMS = await fetch(API_URL+pageEnCours); + const FILM = await FILMS.json(); + const total_pages = FILM.count/FILM.results.length; + + // on vide le div + document.getElementById('container').innerHTML = ""; + + // boucle pour parser les films + for(i=0;i${film.title}

`; + // } + document.getElementById('container').innerHTML += ` +

+

${TITRE}

+ +
+ +
+ + +

+
+ `; + } + + const BUTTONS = document.querySelectorAll('.starships'); + for(var i = 0;i < BUTTONS.length;i++){ + let BUTTON = BUTTONS[i]; + BUTTON.addEventListener("click", function() { + //console.log(BUTTON.nextElementSibling); + getStarships(BUTTON.value,BUTTON.nextElementSibling.id); + }); + } + + const BUTTONS1 = document.querySelectorAll('.species'); + for(var i =0; i${VAISSEAU.name}`; + } + + + } + +async function getSpecies(liste,div){ + const url = liste.split(','); + document.getElementById(div).innerHTML = ""; + for(i=0;i${ESPECE.name}`; + } } -}) \ No newline at end of file + + +// boucle pour afficher les boutons de navigations +fetch(API_URL) + .then(response => response.json()) + .then(data => { + + let totalPages = data.count / data.results.length; + for (let index = 1; index < totalPages +1; index++) { + + + document.getElementById('buttons').innerHTML += ` + `; + } + + let buttons = document.querySelectorAll('.allButtons'); + let boutonNum = document.querySelectorAll('.boutonNum'); + console.log(boutonNum); + + for (let i = 0; i < buttons.length; i++) { + buttons[i].addEventListener("click", function(e) { + + if (e.target.name === "moins" || e.target.name === "plus"){ + + pageEnCours = pageEnCours + parseInt(e.target.value); + + if(pageEnCours < 1){ + pageEnCours = 1; + }else if(pageEnCours > boutonNum.length){ + pageEnCours = boutonNum.length; + } + + }else{ + pageEnCours = parseInt(e.target.value); + } + + getMovies(); + }); + + +}}); + +// initialisation de la page, pour un affichage au chargement +getMovies();