Enhance exam question fragment by exposing current question index for global listeners and updating question list state locally to reflect answered questions
This commit is contained in:
@@ -298,6 +298,16 @@
|
||||
requestAnimationFrame(function(){ el.style.opacity = '1'; });
|
||||
// hide after 1.6s
|
||||
setTimeout(function(){ el.style.opacity = '0'; }, 1600);
|
||||
// Update the question list state locally so the menu reflects answered questions
|
||||
try {
|
||||
var pos = (typeof window.currentQuestionPos === 'number') ? window.currentQuestionPos : (document.getElementById('question-number') ? parseInt(document.getElementById('question-number').textContent, 10) - 1 : NaN);
|
||||
if (!isNaN(pos)) {
|
||||
window.examQuestionAnswered = window.examQuestionAnswered || new Array({{ exam_length }}).fill(false);
|
||||
window.examQuestionAnswered[pos] = true;
|
||||
var btn = document.querySelector('#menu-list [data-qn="' + pos + '"]');
|
||||
if (btn) btn.classList.add('answered');
|
||||
}
|
||||
} catch (e) { console && console.error && console.error(e); }
|
||||
} catch (e) { console && console.error && console.error(e); }
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -97,7 +97,7 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block css %}
|
||||
<style>
|
||||
<style>
|
||||
/* Overview page specific styles */
|
||||
.overview-text {
|
||||
margin-bottom: 1rem;
|
||||
@@ -161,5 +161,5 @@
|
||||
}
|
||||
.overview-question-btn { font-size: .95rem }
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
@@ -86,6 +86,8 @@
|
||||
try {
|
||||
var qnum = document.getElementById('question-number');
|
||||
if (qnum) { qnum.textContent = '{{ pos|add:"1" }}'; }
|
||||
// expose current question index for global listeners
|
||||
window.currentQuestionPos = {{ pos }};
|
||||
var qstem = document.getElementById('question-stem');
|
||||
if (qstem) { qstem.innerHTML = '{{ question.stem|escapejs }}'; }
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user