(function(){
var Activity_ch07 = Activity_manuscript.extend({
congratulations_msg: undefined,
show_grade_saved_message: function() {
safe_log("show_grade_saved_message: enter");
safe_log("show_grade_saved_message: congratulations_msg = " + this.congratulations_msg);
// if the user has answered all queries AND the user hasn't been told this already,
// tell them now
if (player.activity.answered_all_queries && !player.user_has_received_completion_alert) {
var msg = "You have completed the activity, and your grade has been submitted.";
if (player.activity.congratulations_msg !== undefined) {
msg = player.activity.congratulations_msg;
}
function show_message() {
Standard_Dialog.alert(msg);
}
setTimeout(show_message, 20);
player.user_has_received_completion_alert = true;
}
},
submit_question: function (question_index) {
// the arg may be a number or an event object; in the latter case...
if (typeof question_index == "object") {
// extract the question_index from the object
question_index = question_index.data.question_index;
}
//force all queries to be answered before doing anything.
var queries = player.activity.questions[question_index].queries;
var allQueriesAnswered = true;
for (var i = 0; i < queries.length; i++) {
if (!queries[i].user_has_answered()) {
allQueriesAnswered = false;
}
}
if (!allQueriesAnswered) {
Standard_Dialog.open("
Please answer all of the questions before submitting.
", {
from: this,
modal: true,
buttons: [{
text: "OK",
click: function () {
Standard_Dialog.close();
}
}]
});
return false;
}
this._super(question_index);
// the arg may be a number or an event object; in the latter case...
if (typeof question_index == "object") {
// extract the question_index from the object
question_index = question_index.data.question_index;
}
player.activity.questions[question_index].checkModelUpdateConditionals(question_index);
var curSection = player.get_current_section();
if (curSection.slide && !curSection.slide.isPassed) {
player.get_current_section_jq().find(".next_screen_button").show();
player.get_current_section_jq().find(".next_button").hide();
player.last_available_section = player.section_currently_showing;
} else {
player.get_current_section_jq().find(".next_screen_button").hide();
}
// show text after submitting
//var curSection = player.get_current_section();
var lastSectionIndex = player.sections.length - 1;
var submitMessageDiv = document.createElement('div');
submitMessageDiv.setAttribute('class', 'submit_message');
if (curSection.index != lastSectionIndex) {
if (player.section_currently_showing != 3) {
safe_log("submit_question: removing nextScreenBtn, showing next_button");
$(".next_button").show();
$(this.nextScreenBtn).remove();
}
Standard_Dialog.open("Your answers have been submitted. Please click NEXT to move to the next screen.
", {
from: player.sections[player.section_currently_showing].jq.find('.next_screen_button')
|| player.sections[player.section_currently_showing].jq.find('.next_button'),
modal: true,
buttons: [{
text: "OK",
click: function () {
Standard_Dialog.close();
player.sections[player.section_currently_showing].jq.find('.next_button').focus();
}
}]
});
}
//insert any variables that may be newly displayed in the question feedback
player.show_variables();
// calculate score
//move the feedback into a nice popup
$("[data-question_index=" + question_index + "]").find(".query_mc_feedback_correct_incorrect").dialog({
buttons: [{
text: "OK",
click: function () {
$(this).dialog("close");
}
}]
});
var feedback = document.querySelector(".question_feedback_part");
if( feedback ) {
feedback.setAttribute("tabindex", "0");
var feedbackAriaLabel = feedback.textContent;
feedback.setAttribute("aria-label", feedbackAriaLabel);
}
var finalQuestionIndex = player.activity.questions.length - 1;
var curQuestion = player.activity.questions[finalQuestionIndex];
var numOfQuestions = curQuestion.queries.length;
if( curSection.all_questions_answered && question_index == finalQuestionIndex ) {
var userAnswer, correctAnswer, curQuery, boldAnswer;
var score = 0;
for( i = 0; i < numOfQuestions; i++ ) {
if( curQuestion.queries[i].answerType == "string" ) {
userAnswer = curQuestion.queries[i].user_answer;
correctAnswer = curQuestion.queries[i].correct_answer;
if ( userAnswer.toLowerCase() == correctAnswer.toLowerCase() ) {
score++;
}
} else {
userAnswer = curQuestion.queries[i].user_answer_index;
correctAnswer = curQuestion.queries[i].correct_answer_index;
if (userAnswer == correctAnswer) {
score++;
}
curQuery = curSection.jq.find('[data-type=query]')[i];
boldAnswer = curQuery.querySelectorAll('label')[correctAnswer];
boldAnswer.style.fontWeight = "bold";
}
}
var activityName = player.md.activity_type_title;
var conString = "Congratulations! You have completed the activity \"" +
activityName + "\" Your score (100%) has been reported to the Gradebook.";
player.activity.congratulations_msg = conString;
safe_log("setting congratulations_msg to " + player.activity.congratulations_msg);
/*
var conDialog = "" + conString + "
";
Standard_Dialog.open(conDialog,{
modal: true,
buttons: [{
text: "OK",
click: function () {
Standard_Dialog.close();
feedback.focus();
}
}]
});
*/
return false;
}
return false;
},
is_instructor: function() {
return ( player.ARGA_running && Get_ARGA_Data('user_rights') == '3_instructor' || player.instructor );
}
});
var Player_ch07 = Player_ays.extend({
update_section_status: function () {
this._super();
if (player.section_currently_showing == 3) {
this.set_my_score();
}
},
set_my_score: function() {
safe_log("set_my_score: ch07");
var total = 0;
var i;
for (i=0; i<16; i++) {
var checked = $("#digfir_section_1 #query_answer_" + i).is(":checked");
safe_log("set_my_score: checkbox " + i + " is " + checked);
if (checked) {
if (i==2 || i==5 || i==5 || i==7 || i==8 | i==12 || i== 14 || i == 15) {
total++;
}
}
}
$('[data-block_type="my_score"]').text(total);
if (total > 1) {
$("#digfir_section_2 [data-conditional='2']").css('display','block');
}
else if (total == 1) {
$("#digfir_section_2 [data-conditional='1']").css('display','block');
}
else if (total == 0) {
$("#digfir_section_2 [data-conditional='3']").css('display','block');
}
// we also have a score in Build This Strength to set
var las;
var total2 = 0;
// questions are disabled then we know they have been answered
var disabled = false;
if (player.ARGA_running) {
var las = Get_ARGA_Data("LASX");
}
safe_log("set_my_score: las = " + las);
if (las >= 4) {
for (i=16; i<31; i++) {
var $cb_ques = $("#digfir_section_3 #query_answer_" + i);
var checked = $cb_ques.is(":checked");
disabled = $cb_ques.is(":disabled");
// we found a question that is not disabled, so not all of the
// questions have been answered and we won't set the score
if (!disabled) {
break;
}
safe_log("set_my_score: checkbox " + i + " is " + checked);
if (checked) {
if (i==19 || i==22 || i==23 || i==24 || i==26 | i==27 || i== 14 || i == 29) {
total2++;
}
}
}
// only set the score if all questions were disabled
if (disabled) {
$('[data-block_type="my_score2"]').text(total2);
if (total2 > 1) {
$("#digfir_section_3 [data-conditional2='2']").css('display','block');
}
else if (total2 == 1) {
$("#digfir_section_3 [data-conditional2='1']").css('display','block');
}
else if (total2 == 0) {
$("#digfir_section_3 [data-conditional2='3']").css('display','block');
}
}
if (total > 1) {
$("#digfir_section_3 [data-conditional3='2']").css('display','block');
}
else if (total == 1) {
$("#digfir_section_3 [data-conditional3='1']").css('display','block');
}
else if (total == 0) {
$("#digfir_section_3 [data-conditional3='3']").css('display','block');
}
}
},
show_variables: function (index) {
var curSection = this.get_current_section();
//var curSection = player.sections[curSectionIndex];
if(curSection.slide) {
//look through all the p nodes
var section = this.get_current_section_jq();
var regex = new RegExp("{(.+?)}", "gmi");
// old parsed tags is [p, label, option, table]
$(curSection.slide.screenName[index+1]).find("p, label").each(function (index, element) {
var oldText = $(element).html();
var newText = oldText.replace(regex, function (a, b) {
return eval("player." + b);
});
if (oldText.localeCompare(newText) !== 0) {
var attr = element.getAttribute("aria-label");
if (attr) {
attr = attr.replace(regex, function (a, b) {
return eval("player." + b);
});
element.setAttribute("aria-label", attr);
}
$(element).html(newText);
}
});
} else {
this._super();
}
},
initialize: function () {
this._super();
this.activity = new Activity_ch07();
//player.sections[1].attr('tabindex', '-1');
$('[data-block_type="screen_3"]').find('li').attr('tabindex', '0');
$('[data-block_type="screen_9"]').find('li').attr('tabindex', '0');
$('[data-block_type="screen_9"]').find('p').attr('tabindex', '0');
}
});
player = new Player_ch07();
function Activity( section ){
this.createNextScreenBtn( section );
this.isPassed = false;
}
Activity.prototype.createScreens = function( initScreen, finalScreen ) {
this.initScreen = initScreen;
this.finalScreen = finalScreen;
this.screenName = [];
for( var i = 0; i < this.initScreen; i++ ) {
this.screenName[i] = "";
}
for( i = this.initScreen; i <= this.finalScreen; i++ ) {
this.screenName[i] = '[data-block_type="screen_' + i + '"]';
$(this.screenName[i]).hide();
//$(this.screenName[i]).attr('tabindex', '0');
//$(this.screenName[i]).attr('role', 'tabpanel');
}
$(this.screenName[this.initScreen]).show();
//$(this.screenName[3]).attr('tabindex', '0');
};
Activity.prototype.showNextScreen = function( index ) {
//var curSection = player.get_current_section();
//curSection.slide.hideNextBtn(curSection);
var curSection = player.sections[player.section_currently_showing];
safe_log("showNextScreen: index = " + index);
player.show_variables(index);
$(this.screenName[index]).hide();
$(this.screenName[index + 1]).show();
if((index == 2 && curSection.index == 1) || (index == 8 && curSection.index == 3)) {
$(this.screenName[index + 1]).find('li')[0].focus();
} else {
if(index == 4 || index == 9) {
curSection.jq.attr('aria-label', $('[data-block_type=query_text] p').html());
} else {
curSection.jq.attr('aria-label', '');
}
curSection.jq.focus();
}
//$(this.screenName[index + 1]).focus();
if($(this.screenName[index + 1]).find("[data-type=question]").length > 0) {
$(this.nextScreenBtn).hide();
}
this.index++;
if( this.index == this.finalScreen ) {
if($(this.screenName[index + 1]).find(".question_submit_button").length == 0
&& $(this.screenName[index + 1]).find(".next_screen_button").length == 0) {
safe_log("showNextScreen: show next_button (100)");
$(".next_button").show();
player.last_available_section = player.section_currently_showing + 1;
}
this.isPassed = true;
}
var first_questions_answered = $('#query_answer_0').is(':disabled');
var second_questions_answered = $('#query_answer_16').is(':disabled');
safe_log("showNextScreen: index = " + index);
if (index == 4) {
if (first_questions_answered) {
safe_log("showNextScreen: removing nextScreenBtn, showing next_button");
$(this.nextScreenBtn).remove();
$(".next_button").show();
}
}
/*
else if (index == 5) {
if (first_questions_answered) {
$(this.nextScreenBtn).remove();
}
}
*/
else if (index == 9) {
if (second_questions_answered) {
safe_log("showNextScreen: showing nextScreenBtn");
$(this.nextScreenBtn).show();
}
}
else if (index == 10) {
if (second_questions_answered) {
// we need to do this here because the user may have exited before
// completing the second set of questions and so the modal.total
// will not be set and thus we need to use set_my_score to make
// sure this page is set up properly
player.set_my_score();
safe_log("showNextScreen: removing nextScreenBtn, showing next_button");
$(this.nextScreenBtn).remove();
$(".next_button").show();
}
}
//$(this.screenName[index + 1]).focus();
player.process_conditional_display(curSection);
};
Activity.prototype.createNextScreenBtn = function( section ) {
this.nextScreenBtn = document.createElement("button");
this.nextScreenBtn.classList.add("next_screen_button");
this.nextScreenBtn.textContent = "NEXT";
section.jq.append(this.nextScreenBtn);
};
Activity.prototype.hideNextBtn = function( section ) {
$(section.slide.screenName).each( function( index, value ){
if($(value).find("[data-type=question]").length > 0) {
$(value).find(".next_screen_button").hide();
}
} );
};
window.mheAYS = window.mheAYS || {};
window.mheAYS['test_memory'] = {
initialize: function( section ) {
section.slide = new Activity( section );
section.slide.initScreen = 2;
section.slide.finalScreen = 5;
section.slide.index = section.slide.initScreen;
section.slide.createScreens( section.slide.initScreen, section.slide.finalScreen );
$(section.slide.nextScreenBtn).click( function() { section.slide.showNextScreen(section.slide.index); } );
},
hide: function( section ){
if(this.isPassed) {
$(section.slide.nextScreenBtn).remove();
}
},
show: function( section ){
$(section.slide.nextScreenBtn).show();
$(section).focus();
}
};
window.mheAYS['build_memory'] = {
initialize: function( section ) {
section.slide = new Activity( section );
section.slide.initScreen = 7;
section.slide.finalScreen = 11;
section.slide.index = section.slide.initScreen;
section.slide.createScreens( section.slide.initScreen, section.slide.finalScreen );
$(section.slide.nextScreenBtn).click( function() { section.slide.showNextScreen(section.slide.index); } );
},
hide: function( section ){
if(this.isPassed) {
$(section.slide.nextScreenBtn).remove();
}
},
show: function( section ){
$(section.slide.nextScreenBtn).show();
$(section).focus();
}
};
})();