Skip to content

Commit

Permalink
Add display
Browse files Browse the repository at this point in the history
  • Loading branch information
amandine-sahl committed Nov 7, 2024
1 parent 5958a3d commit 1dc5132
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions js/display.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

function displayTaxonsCard(taxonList) {
var myContainer = document.getElementById("taxons-results");
// proper call to the function
taxonList.forEach((el) => {
addTaxon(el, myContainer);
});
}


function addTaxon(arrayTaxon, refContainer) {
// from an array of dicts describing taxons, populates "table_contenu" with cards describing each
// get image from taxon
let imgTaxon = arrayTaxon["mediaUrl"];

// Create card element to be appened to card-group
let cardCont = document.createElement("div");
cardCont.className = "card col cursor-pointer";
let myCard = document.createElement("div");
myCard.classList = "card-body";

let myCardFoot = document.createElement("div");
myCardFoot.classList = "card-footer";

// set title and text
let cardTitle = document.createElement("h5");
cardTitle.innerText = arrayTaxon["species"];
cardTitle.className = "card-title";

let myFigure = document.createElement("img");
myFigure.id = arrayTaxon["species"];
myFigure.src = arrayTaxon["mediaUrl"];
myFigure.className = "card-img-top";

let myStatus = document.createElement("small");
myStatus.innerText = arrayTaxon["status"];
myStatus.className = "text-muted";

// Build elements
myCardFoot.appendChild(myStatus);

myCard.appendChild(myFigure);
myCard.appendChild(cardTitle);
cardCont.appendChild(myCard);
cardCont.appendChild(myCardFoot);
refContainer.appendChild(cardCont);
return;
}


//https://nc.iucnredlist.org/redlist/resources/files/1646067752-FINAL_IUCN_Red_List_colour_chart.pdf
var colorStatus = {
"Near threatened (NT)": "#CCE226",
"Vulnerable (VU)": "#F9E814",
"Endangered (EN)": "#FC7F3F",
"Critically Endangered (CR)": "#D81E05",
};

0 comments on commit 1dc5132

Please sign in to comment.