Update templates/index.html
Browse files- templates/index.html +181 -169
templates/index.html
CHANGED
|
@@ -4,126 +4,96 @@
|
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
<title>Générateur de Flashcards et Quiz</title>
|
| 7 |
-
|
|
|
|
| 8 |
<style>
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
padding: 15px;
|
| 14 |
-
cursor: pointer;
|
| 15 |
-
background-color: #f8f9fa;
|
| 16 |
-
transition: transform 0.3s;
|
| 17 |
}
|
| 18 |
-
.flashcard:hover {
|
| 19 |
transform: translateY(-5px);
|
| 20 |
-
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
|
| 21 |
-
}
|
| 22 |
-
.answer {
|
| 23 |
-
display: none;
|
| 24 |
-
margin-top: 10px;
|
| 25 |
-
padding-top: 10px;
|
| 26 |
-
border-top: 1px dashed #ccc;
|
| 27 |
-
}
|
| 28 |
-
.quiz-question {
|
| 29 |
-
border: 1px solid #ddd;
|
| 30 |
-
border-radius: 8px;
|
| 31 |
-
margin-bottom: 20px;
|
| 32 |
-
padding: 15px;
|
| 33 |
-
background-color: #f8f9fa;
|
| 34 |
-
}
|
| 35 |
-
.option {
|
| 36 |
-
padding: 8px 15px;
|
| 37 |
-
margin: 5px 0;
|
| 38 |
-
border-radius: 4px;
|
| 39 |
-
cursor: pointer;
|
| 40 |
-
transition: background-color 0.2s;
|
| 41 |
-
}
|
| 42 |
-
.option:hover {
|
| 43 |
-
background-color: #e9ecef;
|
| 44 |
-
}
|
| 45 |
-
.selected {
|
| 46 |
-
background-color: #d1e7dd;
|
| 47 |
-
}
|
| 48 |
-
.correct {
|
| 49 |
-
background-color: #d4edda;
|
| 50 |
-
border-color: #c3e6cb;
|
| 51 |
-
}
|
| 52 |
-
.incorrect {
|
| 53 |
-
background-color: #f8d7da;
|
| 54 |
-
border-color: #f5c6cb;
|
| 55 |
-
}
|
| 56 |
-
.explanation {
|
| 57 |
-
display: none;
|
| 58 |
-
margin-top: 15px;
|
| 59 |
-
padding: 10px;
|
| 60 |
-
border-radius: 4px;
|
| 61 |
-
background-color: #e2f3fc;
|
| 62 |
-
}
|
| 63 |
-
#loading {
|
| 64 |
-
display: none;
|
| 65 |
}
|
| 66 |
</style>
|
| 67 |
</head>
|
| 68 |
-
<body>
|
| 69 |
-
<div class="container mt-
|
| 70 |
-
<h1 class="text-center mb-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
</div>
|
| 80 |
-
<div class="
|
| 81 |
-
<
|
| 82 |
-
<
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
Flashcards
|
| 86 |
-
</label>
|
| 87 |
-
</div>
|
| 88 |
-
<div class="form-check">
|
| 89 |
-
<input class="form-check-input" type="radio" name="contentType" id="typeQuiz" value="quiz">
|
| 90 |
-
<label class="form-check-label" for="typeQuiz">
|
| 91 |
-
Quiz
|
| 92 |
-
</label>
|
| 93 |
-
</div>
|
| 94 |
</div>
|
| 95 |
-
<button id="generateBtn" class="btn btn-primary w-100">Générer</button>
|
| 96 |
</div>
|
| 97 |
</div>
|
|
|
|
|
|
|
|
|
|
| 98 |
</div>
|
| 99 |
</div>
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
</div>
|
| 107 |
-
|
| 108 |
-
<div id="flashcardsContainer" class="row mt-4"></div>
|
| 109 |
-
<div id="quizContainer" class="row mt-4"></div>
|
| 110 |
</div>
|
| 111 |
|
| 112 |
<script>
|
| 113 |
-
document.getElementById('generateBtn')
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
if (!topic) {
|
| 116 |
alert('Veuillez entrer un sujet.');
|
| 117 |
return;
|
| 118 |
}
|
| 119 |
-
|
| 120 |
const contentType = document.querySelector('input[name="contentType"]:checked').value;
|
| 121 |
-
|
| 122 |
-
// Afficher le chargement
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
|
|
|
|
|
|
| 127 |
// Envoi de la requête
|
| 128 |
fetch('/generate', {
|
| 129 |
method: 'POST',
|
|
@@ -132,129 +102,171 @@
|
|
| 132 |
},
|
| 133 |
body: JSON.stringify({ topic, type: contentType }),
|
| 134 |
})
|
| 135 |
-
.then(response =>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
.then(data => {
|
| 137 |
-
// Masquer le chargement
|
| 138 |
-
|
| 139 |
-
|
| 140 |
if (data.error) {
|
| 141 |
alert('Erreur: ' + data.error);
|
| 142 |
return;
|
| 143 |
}
|
| 144 |
-
|
| 145 |
if (contentType === 'flashcards' && data.flashcards) {
|
|
|
|
| 146 |
displayFlashcards(data.flashcards);
|
| 147 |
} else if (contentType === 'quiz' && data.quiz) {
|
|
|
|
| 148 |
displayQuiz(data.quiz);
|
|
|
|
|
|
|
| 149 |
}
|
| 150 |
})
|
| 151 |
.catch(error => {
|
| 152 |
-
|
| 153 |
-
|
|
|
|
| 154 |
});
|
| 155 |
});
|
| 156 |
-
|
| 157 |
function displayFlashcards(flashcards) {
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
<
|
| 162 |
-
|
|
|
|
|
|
|
| 163 |
</div>
|
| 164 |
`;
|
| 165 |
-
|
|
|
|
| 166 |
flashcards.forEach((card, index) => {
|
| 167 |
const cardElement = document.createElement('div');
|
| 168 |
-
cardElement.className = '
|
|
|
|
| 169 |
cardElement.innerHTML = `
|
| 170 |
-
<div class="
|
| 171 |
-
|
| 172 |
-
<
|
| 173 |
-
<strong>Réponse:</strong> ${card.answer}
|
| 174 |
-
</div>
|
| 175 |
</div>
|
| 176 |
`;
|
| 177 |
-
|
| 178 |
});
|
| 179 |
}
|
| 180 |
-
|
| 181 |
function toggleAnswer(index) {
|
| 182 |
const answerElement = document.getElementById(`answer-${index}`);
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
} else {
|
| 186 |
-
answerElement.style.display = 'block';
|
| 187 |
-
}
|
| 188 |
}
|
| 189 |
-
|
| 190 |
function displayQuiz(quizQuestions) {
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
<
|
| 195 |
-
<p class="text-center text-muted">Sélectionnez une réponse pour chaque question</p>
|
| 196 |
</div>
|
| 197 |
-
`;
|
| 198 |
-
|
| 199 |
quizQuestions.forEach((question, qIndex) => {
|
| 200 |
const questionElement = document.createElement('div');
|
| 201 |
-
|
| 202 |
-
|
|
|
|
| 203 |
let optionsHtml = '';
|
|
|
|
|
|
|
|
|
|
| 204 |
question.options.forEach((option, oIndex) => {
|
|
|
|
| 205 |
optionsHtml += `
|
| 206 |
-
<div class="option
|
| 207 |
-
|
|
|
|
|
|
|
| 208 |
${option}
|
| 209 |
</div>
|
| 210 |
`;
|
| 211 |
});
|
| 212 |
-
|
| 213 |
questionElement.innerHTML = `
|
| 214 |
-
<
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
<
|
| 220 |
-
<strong>Explication:</strong> ${question.explanation}
|
| 221 |
-
</div>
|
| 222 |
</div>
|
| 223 |
`;
|
| 224 |
-
|
| 225 |
});
|
| 226 |
}
|
| 227 |
-
|
| 228 |
-
function selectOption(questionIndex, optionIndex
|
| 229 |
-
const
|
| 230 |
-
const
|
| 231 |
-
const explanationElement = document.getElementById(`explanation-${
|
| 232 |
-
|
| 233 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
questionOptions.forEach(option => {
|
| 235 |
-
option.classList.remove('
|
|
|
|
|
|
|
| 236 |
});
|
| 237 |
-
|
| 238 |
-
//
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
|
|
|
| 243 |
if (selectedText === correctAnswer) {
|
| 244 |
-
|
|
|
|
|
|
|
| 245 |
} else {
|
| 246 |
-
|
| 247 |
-
|
|
|
|
|
|
|
|
|
|
| 248 |
questionOptions.forEach(option => {
|
| 249 |
if (option.textContent.trim() === correctAnswer) {
|
| 250 |
-
option.classList.add('
|
|
|
|
| 251 |
}
|
| 252 |
});
|
| 253 |
}
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
}
|
|
|
|
| 258 |
</script>
|
| 259 |
</body>
|
| 260 |
</html>
|
|
|
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
<title>Générateur de Flashcards et Quiz</title>
|
| 7 |
+
<!-- Inclusion de Tailwind CSS via CDN -->
|
| 8 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 9 |
<style>
|
| 10 |
+
/* Styles personnalisés additionnels si nécessaire (peuvent être évités avec Tailwind) */
|
| 11 |
+
/* Par exemple, pour la transition de la flashcard si non couverte par Tailwind */
|
| 12 |
+
.flashcard-transform {
|
| 13 |
+
transition: transform 0.3s ease-in-out, box-shadow 0.3s ease-in-out;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
}
|
| 15 |
+
.flashcard-transform:hover {
|
| 16 |
transform: translateY(-5px);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
}
|
| 18 |
</style>
|
| 19 |
</head>
|
| 20 |
+
<body class="bg-gray-100 font-sans">
|
| 21 |
+
<div class="container mx-auto mt-8 px-4">
|
| 22 |
+
<h1 class="text-3xl font-bold text-center text-gray-800 mb-6">Générateur de Flashcards et Quiz</h1>
|
| 23 |
+
|
| 24 |
+
<!-- Section de configuration -->
|
| 25 |
+
<div class="max-w-2xl mx-auto mb-8">
|
| 26 |
+
<div class="bg-white rounded-lg shadow-md p-6">
|
| 27 |
+
<div class="mb-4">
|
| 28 |
+
<label for="topic" class="block text-sm font-medium text-gray-700 mb-1">Sujet</label>
|
| 29 |
+
<input type="text" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm" id="topic" placeholder="Entrez un sujet...">
|
| 30 |
+
</div>
|
| 31 |
+
<div class="mb-4">
|
| 32 |
+
<label class="block text-sm font-medium text-gray-700 mb-2">Type de contenu</label>
|
| 33 |
+
<div class="flex items-center space-x-4">
|
| 34 |
+
<div class="flex items-center">
|
| 35 |
+
<input id="typeFlashcards" name="contentType" type="radio" value="flashcards" checked class="h-4 w-4 text-indigo-600 border-gray-300 focus:ring-indigo-500">
|
| 36 |
+
<label for="typeFlashcards" class="ml-2 block text-sm text-gray-900">
|
| 37 |
+
Flashcards
|
| 38 |
+
</label>
|
| 39 |
</div>
|
| 40 |
+
<div class="flex items-center">
|
| 41 |
+
<input id="typeQuiz" name="contentType" type="radio" value="quiz" class="h-4 w-4 text-indigo-600 border-gray-300 focus:ring-indigo-500">
|
| 42 |
+
<label for="typeQuiz" class="ml-2 block text-sm text-gray-900">
|
| 43 |
+
Quiz
|
| 44 |
+
</label>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
</div>
|
|
|
|
| 46 |
</div>
|
| 47 |
</div>
|
| 48 |
+
<button id="generateBtn" class="w-full py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 transition duration-150 ease-in-out">
|
| 49 |
+
Générer
|
| 50 |
+
</button>
|
| 51 |
</div>
|
| 52 |
</div>
|
| 53 |
+
|
| 54 |
+
<!-- Indicateur de chargement -->
|
| 55 |
+
<div id="loading" class="hidden text-center my-10 flex flex-col items-center justify-center">
|
| 56 |
+
<svg class="animate-spin h-8 w-8 text-indigo-600" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
|
| 57 |
+
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
|
| 58 |
+
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
| 59 |
+
</svg>
|
| 60 |
+
<p class="mt-2 text-gray-600">Génération en cours... Cela peut prendre plusieurs minutes.</p>
|
| 61 |
+
</div>
|
| 62 |
+
|
| 63 |
+
<!-- Conteneur pour les Flashcards -->
|
| 64 |
+
<div id="flashcardsContainer" class="mt-6">
|
| 65 |
+
<!-- Les flashcards seront injectées ici -->
|
| 66 |
+
</div>
|
| 67 |
+
|
| 68 |
+
<!-- Conteneur pour le Quiz -->
|
| 69 |
+
<div id="quizContainer" class="mt-6 max-w-3xl mx-auto">
|
| 70 |
+
<!-- Les questions du quiz seront injectées ici -->
|
| 71 |
</div>
|
|
|
|
|
|
|
|
|
|
| 72 |
</div>
|
| 73 |
|
| 74 |
<script>
|
| 75 |
+
const generateBtn = document.getElementById('generateBtn');
|
| 76 |
+
const loadingIndicator = document.getElementById('loading');
|
| 77 |
+
const flashcardsContainer = document.getElementById('flashcardsContainer');
|
| 78 |
+
const quizContainer = document.getElementById('quizContainer');
|
| 79 |
+
const topicInput = document.getElementById('topic');
|
| 80 |
+
|
| 81 |
+
generateBtn.addEventListener('click', function() {
|
| 82 |
+
const topic = topicInput.value.trim();
|
| 83 |
if (!topic) {
|
| 84 |
alert('Veuillez entrer un sujet.');
|
| 85 |
return;
|
| 86 |
}
|
| 87 |
+
|
| 88 |
const contentType = document.querySelector('input[name="contentType"]:checked').value;
|
| 89 |
+
|
| 90 |
+
// Afficher le chargement et cacher les anciens résultats
|
| 91 |
+
loadingIndicator.classList.remove('hidden');
|
| 92 |
+
flashcardsContainer.innerHTML = '';
|
| 93 |
+
quizContainer.innerHTML = '';
|
| 94 |
+
flashcardsContainer.classList.add('hidden'); // Cacher explicitement les conteneurs
|
| 95 |
+
quizContainer.classList.add('hidden');
|
| 96 |
+
|
| 97 |
// Envoi de la requête
|
| 98 |
fetch('/generate', {
|
| 99 |
method: 'POST',
|
|
|
|
| 102 |
},
|
| 103 |
body: JSON.stringify({ topic, type: contentType }),
|
| 104 |
})
|
| 105 |
+
.then(response => {
|
| 106 |
+
if (!response.ok) {
|
| 107 |
+
throw new Error(`Erreur HTTP: ${response.status}`);
|
| 108 |
+
}
|
| 109 |
+
return response.json();
|
| 110 |
+
})
|
| 111 |
.then(data => {
|
| 112 |
+
loadingIndicator.classList.add('hidden'); // Masquer le chargement
|
| 113 |
+
|
|
|
|
| 114 |
if (data.error) {
|
| 115 |
alert('Erreur: ' + data.error);
|
| 116 |
return;
|
| 117 |
}
|
| 118 |
+
|
| 119 |
if (contentType === 'flashcards' && data.flashcards) {
|
| 120 |
+
flashcardsContainer.classList.remove('hidden');
|
| 121 |
displayFlashcards(data.flashcards);
|
| 122 |
} else if (contentType === 'quiz' && data.quiz) {
|
| 123 |
+
quizContainer.classList.remove('hidden');
|
| 124 |
displayQuiz(data.quiz);
|
| 125 |
+
} else {
|
| 126 |
+
alert('Aucune donnée reçue ou format incorrect.');
|
| 127 |
}
|
| 128 |
})
|
| 129 |
.catch(error => {
|
| 130 |
+
loadingIndicator.classList.add('hidden');
|
| 131 |
+
console.error('Erreur lors de la génération:', error);
|
| 132 |
+
alert('Erreur lors de la génération: ' + error.message + '. Vérifiez la console pour plus de détails.');
|
| 133 |
});
|
| 134 |
});
|
| 135 |
+
|
| 136 |
function displayFlashcards(flashcards) {
|
| 137 |
+
flashcardsContainer.innerHTML = `
|
| 138 |
+
<div class="mb-4">
|
| 139 |
+
<h2 class="text-2xl font-semibold text-center text-gray-700 mb-1">Flashcards générées (${flashcards.length})</h2>
|
| 140 |
+
<p class="text-center text-gray-500 text-sm">Cliquez sur une carte pour voir la réponse</p>
|
| 141 |
+
</div>
|
| 142 |
+
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
| 143 |
+
<!-- Flashcards ici -->
|
| 144 |
</div>
|
| 145 |
`;
|
| 146 |
+
const gridContainer = flashcardsContainer.querySelector('.grid');
|
| 147 |
+
|
| 148 |
flashcards.forEach((card, index) => {
|
| 149 |
const cardElement = document.createElement('div');
|
| 150 |
+
cardElement.className = 'bg-white rounded-lg shadow p-4 cursor-pointer flashcard-transform hover:shadow-lg';
|
| 151 |
+
cardElement.setAttribute('onclick', `toggleAnswer(${index})`); // Utilisation directe d'onclick pour simplicité ici
|
| 152 |
cardElement.innerHTML = `
|
| 153 |
+
<div class="font-semibold text-gray-800">${card.question}</div>
|
| 154 |
+
<div id="answer-${index}" class="hidden mt-3 pt-3 border-t border-dashed border-gray-300 text-sm text-gray-700">
|
| 155 |
+
<strong class="font-bold text-gray-900">Réponse:</strong> ${card.answer}
|
|
|
|
|
|
|
| 156 |
</div>
|
| 157 |
`;
|
| 158 |
+
gridContainer.appendChild(cardElement);
|
| 159 |
});
|
| 160 |
}
|
| 161 |
+
|
| 162 |
function toggleAnswer(index) {
|
| 163 |
const answerElement = document.getElementById(`answer-${index}`);
|
| 164 |
+
// Utilisation de classList.toggle pour gérer l'affichage avec Tailwind
|
| 165 |
+
answerElement.classList.toggle('hidden');
|
|
|
|
|
|
|
|
|
|
| 166 |
}
|
| 167 |
+
|
| 168 |
function displayQuiz(quizQuestions) {
|
| 169 |
+
quizContainer.innerHTML = `
|
| 170 |
+
<div class="mb-4">
|
| 171 |
+
<h2 class="text-2xl font-semibold text-center text-gray-700 mb-1">Quiz généré (${quizQuestions.length} questions)</h2>
|
| 172 |
+
<p class="text-center text-gray-500 text-sm">Sélectionnez une réponse pour chaque question</p>
|
|
|
|
| 173 |
</div>
|
| 174 |
+
`; // Titre ajouté
|
| 175 |
+
|
| 176 |
quizQuestions.forEach((question, qIndex) => {
|
| 177 |
const questionElement = document.createElement('div');
|
| 178 |
+
// Ajout de classes Tailwind pour le conteneur de question
|
| 179 |
+
questionElement.className = 'bg-white rounded-lg shadow p-5 mb-5';
|
| 180 |
+
|
| 181 |
let optionsHtml = '';
|
| 182 |
+
// Encoder la bonne réponse pour l'attribut data-correct (échapper les guillemets doubles)
|
| 183 |
+
const safeCorrectAnswer = question.correctAnswer.replace(/"/g, '"');
|
| 184 |
+
|
| 185 |
question.options.forEach((option, oIndex) => {
|
| 186 |
+
// Utilisation des data attributes et passage de 'this'
|
| 187 |
optionsHtml += `
|
| 188 |
+
<div class="option block p-3 my-2 border border-gray-200 rounded-md cursor-pointer transition duration-150 ease-in-out hover:bg-gray-100 text-gray-800"
|
| 189 |
+
id="q${qIndex}-o${oIndex}"
|
| 190 |
+
data-correct="${safeCorrectAnswer}"
|
| 191 |
+
onclick="selectOption(this, ${qIndex}, ${oIndex})">
|
| 192 |
${option}
|
| 193 |
</div>
|
| 194 |
`;
|
| 195 |
});
|
| 196 |
+
|
| 197 |
questionElement.innerHTML = `
|
| 198 |
+
<h5 class="font-semibold text-lg mb-3 text-gray-800">${qIndex + 1}. ${question.question}</h5>
|
| 199 |
+
<div class="options mt-3">
|
| 200 |
+
${optionsHtml}
|
| 201 |
+
</div>
|
| 202 |
+
<div class="explanation hidden mt-4 p-3 rounded-md bg-blue-50 border border-blue-200 text-sm text-blue-700" id="explanation-${qIndex}">
|
| 203 |
+
<strong class="font-bold">Explication:</strong> ${question.explanation}
|
|
|
|
|
|
|
| 204 |
</div>
|
| 205 |
`;
|
| 206 |
+
quizContainer.appendChild(questionElement);
|
| 207 |
});
|
| 208 |
}
|
| 209 |
+
|
| 210 |
+
function selectOption(element, questionIndex, optionIndex) {
|
| 211 |
+
const correctAnswer = element.dataset.correct; // Récupérer la réponse correcte
|
| 212 |
+
const questionOptions = quizContainer.querySelectorAll(`#q${qIndex}-o0`)[0].parentElement.querySelectorAll('.option'); // Sélectionne toutes les options de CETTE question
|
| 213 |
+
const explanationElement = document.getElementById(`explanation-${qIndex}`);
|
| 214 |
+
|
| 215 |
+
// Indicateur si la question a déjà été répondue (pour éviter les re-clics)
|
| 216 |
+
let alreadyAnswered = false;
|
| 217 |
+
questionOptions.forEach(opt => {
|
| 218 |
+
if (opt.classList.contains('correct') || opt.classList.contains('incorrect')) {
|
| 219 |
+
alreadyAnswered = true;
|
| 220 |
+
}
|
| 221 |
+
});
|
| 222 |
+
|
| 223 |
+
if (alreadyAnswered) {
|
| 224 |
+
return; // Ne rien faire si déjà répondu
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
// Retirer les classes de sélection/hover précédentes (au cas où)
|
| 228 |
questionOptions.forEach(option => {
|
| 229 |
+
option.classList.remove('bg-indigo-100', 'border-indigo-300', 'bg-green-100', 'border-green-300', 'text-green-800', 'bg-red-100', 'border-red-300', 'text-red-800');
|
| 230 |
+
// Rétablir le style de survol standard
|
| 231 |
+
option.classList.add('hover:bg-gray-100');
|
| 232 |
});
|
| 233 |
+
|
| 234 |
+
// Ajouter la classe 'sélectionnée' (style visuel temporaire ou permanent)
|
| 235 |
+
element.classList.add('bg-indigo-100', 'border-indigo-300');
|
| 236 |
+
element.classList.remove('hover:bg-gray-100'); // Retirer hover sur l'élément sélectionné
|
| 237 |
+
|
| 238 |
+
// Vérifier la réponse
|
| 239 |
+
const selectedText = element.textContent.trim();
|
| 240 |
if (selectedText === correctAnswer) {
|
| 241 |
+
// Bonne réponse: vert
|
| 242 |
+
element.classList.remove('bg-indigo-100', 'border-indigo-300'); // Retirer le style sélectionné
|
| 243 |
+
element.classList.add('bg-green-100', 'border-green-300', 'text-green-800');
|
| 244 |
} else {
|
| 245 |
+
// Mauvaise réponse: rouge
|
| 246 |
+
element.classList.remove('bg-indigo-100', 'border-indigo-300');
|
| 247 |
+
element.classList.add('bg-red-100', 'border-red-300', 'text-red-800');
|
| 248 |
+
|
| 249 |
+
// Mettre en évidence la bonne réponse en vert
|
| 250 |
questionOptions.forEach(option => {
|
| 251 |
if (option.textContent.trim() === correctAnswer) {
|
| 252 |
+
option.classList.add('bg-green-100', 'border-green-300', 'text-green-800');
|
| 253 |
+
option.classList.remove('hover:bg-gray-100');
|
| 254 |
}
|
| 255 |
});
|
| 256 |
}
|
| 257 |
+
|
| 258 |
+
// Désactiver les clics pour cette question après la réponse
|
| 259 |
+
questionOptions.forEach(option => {
|
| 260 |
+
option.onclick = null; // Supprime l'attribut onclick
|
| 261 |
+
option.classList.remove('cursor-pointer', 'hover:bg-gray-100'); // Rend visuellement non cliquable
|
| 262 |
+
option.style.cursor = 'default';
|
| 263 |
+
});
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
// Afficher l'explication (retirer 'hidden')
|
| 267 |
+
explanationElement.classList.remove('hidden');
|
| 268 |
}
|
| 269 |
+
|
| 270 |
</script>
|
| 271 |
</body>
|
| 272 |
</html>
|