From cb2223309c2610339433fbd3b0bb59b23cabe51c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pr=C3=A9nom=20Nom?= <adresse@mail.com> Date: Sat, 22 Feb 2025 17:48:24 +0100 Subject: [PATCH] correction affichage def lexique --- src/utils/definitions.js | 158 +++++++++++++++++++++------------------ 1 file changed, 85 insertions(+), 73 deletions(-) diff --git a/src/utils/definitions.js b/src/utils/definitions.js index a510319..93b9bf4 100644 --- a/src/utils/definitions.js +++ b/src/utils/definitions.js @@ -352,92 +352,102 @@ function displayDefinitions(definitions) { const lexiconGroups = {}; definitions.forEach(({ source, text, definitionsByPOS }) => { - if (!source || !definitionsByPOS) return; + if (!source || !text) return; const definitionContainer = document.createElement("div"); definitionContainer.classList.add("definition-item"); - // 🔊 1. Affichage des prononciations globales si disponibles - const allPronunciations = new Set(); - Object.values(definitionsByPOS).forEach(posData => { - posData.pronunciations.forEach(pron => allPronunciations.add(pron)); - }); + // 🔹 1. **Gestion des définitions des lexiques** + if (!definitionsByPOS) { + // C'est une définition provenant des lexiques utilisateur + const li = document.createElement("li"); + li.textContent = text; + definitionContainer.appendChild(li); - if (allPronunciations.size > 0) { - const pronDiv = document.createElement("div"); - pronDiv.style.fontWeight = "bold"; - pronDiv.style.color = "#94608a"; - pronDiv.style.marginBottom = "5px"; - pronDiv.textContent = `Prononciations possibles : ${[...allPronunciations].join(", ")}`; - definitionContainer.appendChild(pronDiv); - } + // Ajout dans le bon groupe + if (!lexiconGroups[source]) { + lexiconGroups[source] = []; + } + lexiconGroups[source].push(definitionContainer); + hasLexiconDefinitions = true; + + } else { + // C'est une définition provenant du Wiktionnaire + log(`Traitement des définitions du Wiktionnaire pour "${source}"`); - // 2. Affichage des définitions triées par POS - Object.entries(definitionsByPOS).forEach(([pos, posData]) => { - if (posData.definitions.length === 0) return; // Évite les POS vides - - // Titre du POS - const posTitle = document.createElement("h4"); - posTitle.style.marginTop = "10px"; - posTitle.style.color = "#e3e3e3"; - posTitle.textContent = `${pos.toUpperCase()}`; - definitionContainer.appendChild(posTitle); - - // Prononciations spécifiques au POS - if (posData.pronunciations.length > 0) { - const posPronDiv = document.createElement("div"); - posPronDiv.style.fontStyle = "italic"; - posPronDiv.style.color = "#94608a"; - // posPronDiv.textContent = `${posData.pronunciations.join(", ")}`; - // definitionContainer.appendChild(posPronDiv); + // 2. Affichage des prononciations globales si disponibles + const allPronunciations = new Set(); + Object.values(definitionsByPOS).forEach(posData => { + posData.pronunciations.forEach(pron => allPronunciations.add(pron)); + }); + + if (allPronunciations.size > 0) { + const pronDiv = document.createElement("div"); + pronDiv.style.fontWeight = "bold"; + pronDiv.style.color = "#94608a"; + pronDiv.style.marginBottom = "5px"; + pronDiv.textContent = `Prononciations possibles : ${[...allPronunciations].join(", ")}`; + definitionContainer.appendChild(pronDiv); } - // Liste des définitions - const defList = document.createElement("ul"); - defList.style.margin = "0"; - defList.style.paddingLeft = "20px"; - - posData.definitions.forEach(def => { - const li = document.createElement("li"); - - // 3. Gestion du bouton "Lire la suite" - let displayedText = def.trim(); - if (displayedText.length > MAX_LENGTH) { - const truncatedText = displayedText.slice(0, MAX_LENGTH) + "... "; - const readMoreLink = document.createElement("a"); - readMoreLink.href = "#"; - readMoreLink.textContent = "[Lire la suite]"; - readMoreLink.style.marginLeft = "5px"; - readMoreLink.style.color = "#8d5c70"; - readMoreLink.style.textDecoration = "underline"; - readMoreLink.style.cursor = "pointer"; - readMoreLink.addEventListener("click", (event) => { - event.preventDefault(); - openDefinitionPopup(displayedText); - }); - - li.appendChild(document.createTextNode(truncatedText)); - li.appendChild(readMoreLink); - } else { - li.textContent = displayedText; + // 3. Affichage des définitions triées par POS + Object.entries(definitionsByPOS).forEach(([pos, posData]) => { + if (posData.definitions.length === 0) return; // Évite les POS vides + + // Titre du POS + const posTitle = document.createElement("h4"); + posTitle.style.marginTop = "10px"; + posTitle.style.color = "#FFFFFF"; + posTitle.textContent = `${pos.toUpperCase()}`; + definitionContainer.appendChild(posTitle); + + // Prononciations spécifiques au POS + if (posData.pronunciations.length > 0) { + const posPronDiv = document.createElement("div"); + posPronDiv.style.fontStyle = "italic"; + posPronDiv.style.color = "#94608a"; + // posPronDiv.textContent = `${posData.pronunciations.join(", ")}`; + // definitionContainer.appendChild(posPronDiv); } - defList.appendChild(li); - }); + // Liste des définitions + const defList = document.createElement("ul"); + defList.style.margin = "0"; + defList.style.paddingLeft = "20px"; + + posData.definitions.forEach(def => { + const li = document.createElement("li"); + + // 4. Gestion du bouton "Lire la suite" + let displayedText = def.trim(); + if (displayedText.length > MAX_LENGTH) { + const truncatedText = displayedText.slice(0, MAX_LENGTH) + "... "; + const readMoreLink = document.createElement("a"); + readMoreLink.href = "#"; + readMoreLink.textContent = "[Lire la suite]"; + readMoreLink.style.marginLeft = "5px"; + readMoreLink.style.color = "#8d5c70"; + readMoreLink.style.textDecoration = "underline"; + readMoreLink.style.cursor = "pointer"; + readMoreLink.addEventListener("click", (event) => { + event.preventDefault(); + openDefinitionPopup(displayedText); + }); + + li.appendChild(document.createTextNode(truncatedText)); + li.appendChild(readMoreLink); + } else { + li.textContent = displayedText; + } + + defList.appendChild(li); + }); - definitionContainer.appendChild(defList); - }); + definitionContainer.appendChild(defList); + }); - // 4. Ajout dans la bonne section (Lexique ou Wiktionnaire) - if (source === "Wiktionnaire") { wiktionnaireList.appendChild(definitionContainer); hasWiktionaryDefinitions = true; - } else { - if (!lexiconGroups[source]) { - lexiconGroups[source] = []; - } - lexiconGroups[source].push(definitionContainer); - hasLexiconDefinitions = true; } }); @@ -464,13 +474,15 @@ function displayDefinitions(definitions) { }); // 6. Gestion des sections vides + if (!hasLexiconDefinitions && noLexiconDefinitionsContainer) { + noLexiconDefinitionsContainer.style.display = "block"; + } if (!hasWiktionaryDefinitions && noWiktionaryDefinitionsContainer) { noWiktionaryDefinitionsContainer.style.display = "block"; } } - // ───────────────────────────────────────────────────────────────────────────── // ▌ Gestion du popup pour afficher la définition complète du Wiktionnaire // ───────────────────────────────────────────────────────────────────────────── -- GitLab