Skip to content
Snippets Groups Projects
Commit cb222330 authored by Prénom Nom's avatar Prénom Nom
Browse files

correction affichage def lexique

parent 72231105
No related branches found
No related tags found
1 merge request!9Affichage stats
......@@ -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
// ─────────────────────────────────────────────────────────────────────────────
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment