/**
* Created by Abdulnasyrova on 18.04.2017.
*/
/* global KEY_CODES, Activity_manuscript_type, Player_manuscript_type,
legacy_common */
var Activity_Quiz = Activity_manuscript_type.extend({
/**
* Make feedback readable by screen readers, move evaluation feedback to feedback node for correct reading
* @param {number} question_index
*/
update_question_action_div: function (question_index) {
var question = this.questions[question_index];
// Calculate points_awarded and points_possible
var points_awarded = 0;
var points_possible = 0;
var points_provisional = false;
for (var i = 0; i < question.queries.length; ++i) {
var query = question.queries[i];
points_awarded += query.getPointsAwarded();
points_possible += query.getPointsPossible();
if (query.pointsAreProvisional()) {
points_provisional = true;
}
}
// Round to at most two decimal places
points_awarded = Math.round(points_awarded * 100) / 100;
points_possible = Math.round(points_possible * 100) / 100;
// Hide submit button (and any other similar buttons that might be added by subtypes), but show points earned
// we need to be able to focus on the feedback container, so add tabindex
var $questionAction = question.jq.find('#question_action_div_' + question.index);
// Add information about points
var pointsAwarded = '
Points awarded: ' + points_awarded + ' out of ' + points_possible;
if (points_provisional) {
pointsAwarded += ' (provisional)';
}
pointsAwarded += '
';
if (query.answer_was_just_entered && points_provisional) {
pointsAwarded +=
'
Your answer has been provisionally accepted. You\'ll get full credit for now,' +
' but your instructor may update your grade later after evaluating it.
';
}
var $button = $questionAction.find('.question_submit_button');
$button.attr({
'tabindex': '-1',
'aria-disabled': 'true'
}).addClass('disabled');
// Add points awarded
var $questionFeedback = $questionAction.find('.question_feedback');
$questionAction.find('.points_awarded_div').remove();
if ($questionFeedback.length > 0) {
$questionFeedback.append(pointsAwarded);
} else {
$questionAction.append(pointsAwarded);
}
$questionFeedback.show();
// Add space after period
var feedbackText = $questionAction.text().replace(/\./g, '. ');
// FF + NVDA doesn't read text in focused div automatically
player.setLiveText(feedbackText.replace('Feedback', 'Feedback. '));
},
/**
* We change position of individual feedback of each choice, we put it after general feedback
* @param {object} question
* @param {boolean} is_correct
* @param {boolean} try_again
*/
show_question_feedback: function (question, is_correct, try_again) {
// Remove previous feedback if there
$('#question_feedback_' + question.index).remove();
// Get individual feedback for each choice, and add it after general feedback
var feedback_correct_incorrect = question.jq.find('.query_mc_feedback_correct_incorrect').text();
var html = '
' +
'
' + this.feedbackTitle + '
';
var feedback = '';
// GENERAL feedback if there
if (question.md.feedback) {
feedback += '
' + question.md.feedback + '
';
}
// CORRECT feedback if there and the answer is correct
if (is_correct && question.md.feedback_correct) {
feedback += '
';
}
// INCORRECT or HINT feedback if there and the answer is incorrect
if (!is_correct) {
var found_feedback_string = false;
// If user gets to try again
if (try_again) {
// Check for feedback_conditional's
if (question.md.feedback_conditional.length > 0) {
for (var i in question.md.feedback_conditional) {
var fbc = question.check_conditional(question.md.feedback_conditional[i]);
if (fbc) {
feedback += '
' + fbc + '
';
found_feedback_string = true;
break;
}
}
}
// Check for feedback HINT
if (!found_feedback_string && question.md.feedback_hint) {
feedback += '
' + question.md.feedback_hint + '
';
found_feedback_string = true;
}
}
// Check for feedback INCORRECT
if (!found_feedback_string && question.md.feedback_incorrect) {
feedback += '
';
$('#question_action_div_' + question.index).prepend(html);
var question_place = $('#question_action_div_' + question.index),
points = question_place.find('.points_awarded_div');
if ( points[0] !== undefined ){
var clone_points = points[0].cloneNode(true);
points.remove();
$('#question_feedback_' + question.index)[0].appendChild(clone_points);
}
legacy_common.parseMathExpresions();
},
/**
* Return if submit is disabled
* @param {number} question_index
*/
submit_question: function (question_index) {
if (typeof question_index === 'object') {
// Extract the question_index from the object
question_index = question_index.data.question_index;
}
var question = player.activity.questions[question_index];
if (question.jq.find('.question_submit_button').attr('aria-disabled') === 'true') {
return;
}
this._super(question_index);
var s = player.get_current_section();
var $next_button = $('.next_button');
// If all questions are answered and all sequences are complete
if (s.all_questions_answered && s.all_question_sequences_completed) {
// If we're not on the final step
if (s.index < player.sections.length - 1) {
$next_button.show();
} else {
player.show_completion_message();
}
}
}
});
var Player_Quiz = Player_manuscript_type.extend({
liveFeedback: null,
slideCounter: null,
activity_title: null,
initLiveFeedback: function () {
var live = platform.IE ? 'assertive' : 'polite';
this.liveFeedback = $('');
$('body').prepend(this.liveFeedback);
},
setLiveText: function (text) {
this.liveFeedback.text(text);
},
/**
* Add toolbar, menu, navigation
*/
show_navigation: function () {
var $chapter = $('[data-type=chapter]');
// Top banner
var html = '
' +
"
" + this.activity_title.replace(/[a-z]$/, '') + "
" +
// для Map Quiz кнопку MENU убираем
//'' +
'
';
$chapter.before(html);
// Add navigational buttons
if (this.sections.length > 1) {
html = '
' +
'' +
'
slide 1 of ' +
this.sections.length + '
' +
'';
$('#manuscript').append(html);
}
this.slideCounter = $('.slide-counter');
},
/**
* Update buttons and completion message
*/
update_navigation: function () {
var $next_button = $('.next_button');
var $prev_button = $('.prev_button');
// Show next button if it is not last slide and next is available
// данную проверку пока убираем
// if (this.last_available_section > this.section_currently_showing)
// оставляем проверку на конец слайдов
if (!this.showing_last_section()) {
$next_button.show();
} else {
$next_button.hide();
}
// Prev button is visible if current slide index > 0
if (this.section_currently_showing) {
$prev_button.show();
} else {
$prev_button.hide();
}
if (this.showing_last_section() && player.activity.answered_all_queries) {
player.show_completion_message();
}
this.setLiveText('');
this.slideCounter.html('slide ' + (this.section_currently_showing + 1) + ' of ' + this.sections.length + '');
},
/**
* Open menu in dialog
*/
show_toc: function () {
var html = '';
for (var i = 0; i < this.sections.length; i++) {
var title = this.sections[i].title;
// Check whether it is available
var disabled = (this.md.sequenced_sections === 'true' && i > this.last_available_section);
var className = disabled ? 'toc_section_not_available' : '';
// Check action on disabled only if it is instructor
var action = (!disabled || player.activity.is_instructor()) ? 'onclick="player.toc_show_section(' + i + ')"' : '';
html += '