Fix bug when letter isn't recognized

This commit is contained in:
Mylloon 2022-06-25 19:40:55 +02:00
parent d28859b018
commit 5490ccb4b2
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -52,10 +52,14 @@ const setString = (firstname = String, data = Object) => {
firstname.split("").forEach(letter_value => { firstname.split("").forEach(letter_value => {
// Create the letter // Create the letter
const letter = document.createElement("p"); const letter = document.createElement("p");
const infos = document.createElement("span");
// Fill elements with data // Fill elements with data
letter.textContent = letter_value; letter.textContent = letter_value;
// Check if the letter is inside part of the constant
if (Object.keys(data).includes(clearText(letter_value))) {
// Info about a specific constant
const infos = document.createElement("span");
Object.keys(data[clearText(letter_value)]).forEach(key => { Object.keys(data[clearText(letter_value)]).forEach(key => {
const link = document.createElement("a"); const link = document.createElement("a");
link.href = data[clearText(letter_value)][key]; link.href = data[clearText(letter_value)][key];
@ -63,19 +67,20 @@ const setString = (firstname = String, data = Object) => {
infos.append(link); infos.append(link);
}); });
// Change parameter of tags // Change parameter of the info card
infos.hidden = true; infos.hidden = true;
infos.style.position = "absolute"; infos.style.position = "absolute";
// Link info to the letter // Link info to the letter
letter.append(infos); letter.append(infos);
// Add the letter // Add behaviour when hovering over the letter
string_div.append(letter);
// Add behaviour when clicking on letters
letter.addEventListener("mouseenter", (e) => e.target.firstElementChild.hidden = false); letter.addEventListener("mouseenter", (e) => e.target.firstElementChild.hidden = false);
letter.addEventListener("mouseleave", (e) => e.target.firstElementChild.hidden = true); letter.addEventListener("mouseleave", (e) => e.target.firstElementChild.hidden = true);
}
// Add the letter
string_div.append(letter);
}); });
}; };