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'; });
|
requestAnimationFrame(function(){ el.style.opacity = '1'; });
|
||||||
// hide after 1.6s
|
// hide after 1.6s
|
||||||
setTimeout(function(){ el.style.opacity = '0'; }, 1600);
|
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); }
|
} catch (e) { console && console.error && console.error(e); }
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -97,7 +97,7 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block css %}
|
{% block css %}
|
||||||
<style>
|
<style>
|
||||||
/* Overview page specific styles */
|
/* Overview page specific styles */
|
||||||
.overview-text {
|
.overview-text {
|
||||||
margin-bottom: 1rem;
|
margin-bottom: 1rem;
|
||||||
@@ -161,5 +161,5 @@
|
|||||||
}
|
}
|
||||||
.overview-question-btn { font-size: .95rem }
|
.overview-question-btn { font-size: .95rem }
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -86,6 +86,8 @@
|
|||||||
try {
|
try {
|
||||||
var qnum = document.getElementById('question-number');
|
var qnum = document.getElementById('question-number');
|
||||||
if (qnum) { qnum.textContent = '{{ pos|add:"1" }}'; }
|
if (qnum) { qnum.textContent = '{{ pos|add:"1" }}'; }
|
||||||
|
// expose current question index for global listeners
|
||||||
|
window.currentQuestionPos = {{ pos }};
|
||||||
var qstem = document.getElementById('question-stem');
|
var qstem = document.getElementById('question-stem');
|
||||||
if (qstem) { qstem.innerHTML = '{{ question.stem|escapejs }}'; }
|
if (qstem) { qstem.innerHTML = '{{ question.stem|escapejs }}'; }
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user