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,30 +52,35 @@ 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;
Object.keys(data[clearText(letter_value)]).forEach(key => {
const link = document.createElement("a");
link.href = data[clearText(letter_value)][key];
link.innerText = key;
infos.append(link);
});
// Change parameter of tags // Check if the letter is inside part of the constant
infos.hidden = true; if (Object.keys(data).includes(clearText(letter_value))) {
infos.style.position = "absolute"; // Info about a specific constant
const infos = document.createElement("span");
Object.keys(data[clearText(letter_value)]).forEach(key => {
const link = document.createElement("a");
link.href = data[clearText(letter_value)][key];
link.innerText = key;
infos.append(link);
});
// Link info to the letter // Change parameter of the info card
letter.append(infos); infos.hidden = true;
infos.style.position = "absolute";
// Link info to the letter
letter.append(infos);
// Add behaviour when hovering over the letter
letter.addEventListener("mouseenter", (e) => e.target.firstElementChild.hidden = false);
letter.addEventListener("mouseleave", (e) => e.target.firstElementChild.hidden = true);
}
// Add the letter // Add the letter
string_div.append(letter); string_div.append(letter);
// Add behaviour when clicking on letters
letter.addEventListener("mouseenter", (e) => e.target.firstElementChild.hidden = false);
letter.addEventListener("mouseleave", (e) => e.target.firstElementChild.hidden = true);
}); });
}; };