Skip to content

Commit 474db21

Browse files
committed
Refactor spotlight quiz JavaScript to remove support for 'draw_image' and 'pin_image' question types. This change simplifies the quiz functionality by focusing on supported question types and enhancing code maintainability.
1 parent 73519a3 commit 474db21

1 file changed

Lines changed: 2 additions & 34 deletions

File tree

assets/src/js/front/course/_spotlight-quiz.js

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ window.jQuery(document).ready($ => {
22
const { __ } = window.wp.i18n;
33

44
// Currently only these types of question supports answer reveal mode.
5-
const revealModeSupportedQuestions = ['true_false', 'single_choice', 'multiple_choice', 'draw_image', 'pin_image'];
5+
const revealModeSupportedQuestions = ['true_false', 'single_choice', 'multiple_choice'];
66

77
let quiz_options = _tutorobject.quiz_options
88
let interactions = new Map();
@@ -102,14 +102,6 @@ window.jQuery(document).ready($ => {
102102
});
103103
}
104104

105-
// Reveal mode for draw_image & pin_image: show reference (instructor mask) and explanation.
106-
if (is_reveal_mode() && ['draw_image', 'pin_image'].includes($question_wrap.data('question-type'))) {
107-
$question_wrap.find('.tutor-quiz-explanation-wrapper').removeClass('tutor-d-none');
108-
$question_wrap.find('.tutor-draw-image-reference-wrapper').removeClass('tutor-d-none');
109-
$question_wrap.find('.tutor-pin-image-reference-wrapper').removeClass('tutor-d-none');
110-
goNext = true;
111-
}
112-
113105
if (validatedTrue) {
114106
goNext = true;
115107
}
@@ -168,25 +160,7 @@ window.jQuery(document).ready($ => {
168160
var $inputs = $required_answer_wrap.find('input');
169161
if ($inputs.length) {
170162
var $type = $inputs.attr('type');
171-
// Draw image: require mask (hidden input with [answers][mask]) to have a value.
172-
if ($question_wrap.data('question-type') === 'draw_image') {
173-
var $maskInput = $required_answer_wrap.find('input[name*="[answers][mask]"]');
174-
if ($maskInput.length && !$maskInput.val().trim().length) {
175-
$question_wrap.find('.answer-help-block').html(`<p style="color: #dc3545">${__('Please draw on the image to answer this question.', 'tutor')}</p>`);
176-
validated = false;
177-
}
178-
} else if ($question_wrap.data('question-type') === 'pin_image') {
179-
// Pin image: require normalized pin coordinates (hidden inputs [answers][pin][x|y]).
180-
var $pinX = $required_answer_wrap.find('input[name*="[answers][pin][x]"]');
181-
var $pinY = $required_answer_wrap.find('input[name*="[answers][pin][y]"]');
182-
if (
183-
!$pinX.length || !$pinY.length ||
184-
!$pinX.val().trim().length || !$pinY.val().trim().length
185-
) {
186-
$question_wrap.find('.answer-help-block').html(`<p style="color: #dc3545">${__('Please drop a pin on the image to answer this question.', 'tutor')}</p>`);
187-
validated = false;
188-
}
189-
} else if ($type === 'radio') {
163+
if ($type === 'radio') {
190164
if ($required_answer_wrap.find('input[type="radio"]:checked').length == 0) {
191165
$question_wrap.find('.answer-help-block').html(`<p style="color: #dc3545">${__('Please select an option to answer', 'tutor')}</p>`);
192166
validated = false;
@@ -245,12 +219,6 @@ window.jQuery(document).ready($ => {
245219
}
246220
});
247221

248-
$(document).on('change', '.quiz-attempt-single-question input[name*="[answers][mask]"]', function () {
249-
if ($('.tutor-quiz-time-expired').length === 0 && $(this).val().trim().length) {
250-
$('.tutor-quiz-next-btn-all').prop('disabled', false);
251-
}
252-
});
253-
254222
$(document).on('click', '.tutor-quiz-answer-next-btn, .tutor-quiz-answer-previous-btn', function (e) {
255223
e.preventDefault();
256224

0 commit comments

Comments
 (0)