(function(){
var Activity_ch05 = Activity_manuscript.extend({
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);
//check if we need to show the next button
safe_log(player.get_current_section_jq().find(".next_section_button").attr("role"));
player.get_current_section_jq().find(".next_section_button").show();
// 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 ) {
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_button'),
modal: true,
buttons: [{
text: "OK",
click: function () {
Standard_Dialog.close();
}
}]
});
}
//STG set focus on continue button, so 'continue' button shows up in the window, not below
$('button.next_section_button').focus();
//insert any variables that may be newly displayed in the question feedback
player.show_variables();
// calculate score
player.activity.calculate_score(curSection, question_index);
$(".next_button").show();
return false;
},
calculate_score: function(curSection, question_index) {
//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 + "." + "\" You scored " +
score + " of " +
numOfQuestions +
" possible points on the Quiz, and this score has been reported to the Gradebook.";
var conDialog = "" + conString + "
";
Standard_Dialog.open(conDialog,{
modal: true,
buttons: [{
text: "OK",
click: function () {
Standard_Dialog.close();
feedback.focus();
}
}]
});
return false;
}
},
is_instructor: function() {
return ( player.ARGA_running && Get_ARGA_Data('user_rights') == '3_instructor' || player.instructor );
}
});
var Player_ch05 = Player_ays.extend({
initialize: function () {
this._super();
this.activity = new Activity_ch05();
},
update_section_status: function () {
this._super();
var curSection = player.get_current_section_jq();
var curSectionIndex = player.get_current_section().index;
var lastSectionIndex = player.last_available_section;
var sectionsCount = player.sections.length - 1;
var section = player.sections[curSectionIndex];
if( (curSection.find(".esp_container").length > 0) &&
(lastSectionIndex < sectionsCount) && !section.slide.isPassed ) {
player.last_available_section = curSectionIndex;
$(".next_button").hide();
} //else {
//$(".next_button").show();
//}
}
});
player = new Player_ch05();
var MAX_COUNT = 50;
var FEEDBACK = {
MAIN_PART: "You correctly guessed",
LESS_THAN_15: "You have not demonstrated ESP. Your score falls within the range of what we would expect based on chance guessing.",
MORE_THAN_15: " which is above the range we might expect by chance. So, do you have ESP, or is this the sort of very occasional chance result that we expect a few times in every hundred? You might want to retake the test another few times to see if you can consistently replicate this performance level."
};
var espAria = "For each of the 50 predictions, select one of these cards by pressing Spacebar: hollow circle, Greek cross, three vertical wavy lines, hollow square, hollow five pointed star. Use arrows to move between the cards.";
var url = [
"asset/ch05/circle.gif",
"asset/ch05/cross.gif",
"asset/ch05/waves.gif",
"asset/ch05/square.gif",
"asset/ch05/star.gif"
];
var LEFT_ARROW_KEY = 37;
var RIGHT_ARROW_KEY = 39;
var currentScore = 0;
function Activity( section ){
this.isPassed = false;
this.section = section;
this.sectionNode = section.jq[0];
this.espNode = this.sectionNode.querySelector(".esp_container");
this.espNode.setAttribute("role", "application");
this.espNode.setAttribute("tabindex", "0");
this.espNode.setAttribute("aria-label", espAria);
this.symbols = this.sectionNode.querySelectorAll( ".choice-img-item" );
this.cmpChoiceNode = this.sectionNode.querySelector( "#cmpChoice" );
this.userChoiceNode = this.sectionNode.querySelector( "#userChoice" );
this.hiddenImagesNode = this.sectionNode.querySelector(".hidden-img");
this.countNode = this.sectionNode.querySelector(".count-text");
//this.countNode.innerHTML = "You have completed
0 of 50
predictions.
";
this.countText = $(this.countNode).find('strong');
this.scoreNode = this.sectionNode.querySelector(".score-text");
//this.scoreNode.innerHTML = "Successful predictions:
0
";
this.scoreText = $(this.scoreNode).find('strong');
//this.hiddenUserImage = document.createElement("div");
//this.hiddenUserImage.classList.add("hidden-aria");
//this.espNode.appendChild(this.hiddenUserImage);
this.hiddenCmpImage = document.createElement("div");
this.hiddenCmpImage.classList.add("hidden-aria");
this.hiddenImagesNode.appendChild(this.hiddenCmpImage);
this.countNode.setAttribute("aria-live", "polite");
this.countNode.setAttribute("aria-atomic", "true");
this.scoreNode.setAttribute("aria-live", "polite");
this.scoreNode.setAttribute("aria-atomic", "true");
this.hiddenCmpImage.setAttribute("aria-live", "assertive");
this.hiddenCmpImage.setAttribute("aria-atomic", "true");
//this.hiddenUserImage.setAttribute("aria-live", "assertive");
//this.hiddenUserImage.setAttribute("aria-atomic", "true");
var i;
for( i = 0; i < this.symbols.length; i++ ) {
var th = this;
this.symbols[i].setAttribute("tabindex", "-1");
this.symbols[i].setAttribute("aria-hidden", "false");
this.symbols[i].style.backgroundImage = 'url(' + url[i] + ')' ;
this.symbols[i].addEventListener( "click", this.userChoice.bind( this, i ) );
this.symbols[i].addEventListener( "keydown", function (e) {
th.userKeyChoice(e);
} );
}
this.score = 0;
this.counter = 0;
this.index = 0;
this.setFocus(this.index);
}
Activity.prototype.randomChoice = function(){
var randIndex = Math.floor( Math.random() * this.symbols.length );
var cmpBackground = this.symbols[randIndex].style.backgroundImage;
this.cmpChoiceNode.style.backgroundImage = cmpBackground;
this.cmpChoiceNode.aria = this.symbols[randIndex].getAttribute("aria-label");
//var cmpNode = this.symbols[randIndex].cloneNode(true);
//this.cmpChoiceNode.innerHTML = "";
//this.cmpChoiceNode.appendChild(cmpNode);
this.cmpIndex = randIndex;
};
Activity.prototype.userImage = function (e) {
var i;
for( i = 0; i < this.symbols.length; i++ ) {
if (e.target === this.symbols[i] ) {
return i;
}
}
};
Activity.prototype.setFocus = function(index) {
this.prevIndex = this.index;
this.index = index;
this.symbols[this.prevIndex].setAttribute("tabindex", "-1");
this.symbols[this.index].setAttribute("tabindex", "0");
this.symbols[this.index].focus();
};
Activity.prototype.userKeyChoice = function(e) {
var index = this.userImage(e);
var length = this.symbols.length - 1;
if( e.keyCode == 32 || e.keyCode == 13 ) {
this.userChoice(index);
}
if( e.keyCode == LEFT_ARROW_KEY && index > 0 && !this.isPassed ) {
this.setFocus(index - 1);
}
if( e.keyCode == RIGHT_ARROW_KEY && index < length && !this.isPassed ) {
this.setFocus(index + 1);
}
};
Activity.prototype.userChoice = function( index ){
if( this.isPassed ) return;
var userBackground = this.symbols[index].style.backgroundImage;
this.userChoiceNode.style.backgroundImage = userBackground;
//this.userChoiceNode.aria = this.symbols[index].getAttribute("aria-label");
//var userNode = this.symbols[index].cloneNode(true);
//
//this.userChoiceNode.innerHTML = "";
//this.userChoiceNode.appendChild(userNode);
this.userIndex = index;
this.setFocus(index);
this.randomChoice();
this.checkChoice();
this.liveImages();
};
Activity.prototype.liveImages = function() {
//var cmpChoiceImage = this.cmpChoiceNode.querySelector("img");
var cmpChoiceAlt = this.cmpChoiceNode.aria;
var cmpChoiceText = "Computer selected ";
this.hiddenCmpImage.innerHTML = cmpChoiceText + cmpChoiceAlt;
};
Activity.prototype.checkChoice = function(){
this.counter++;
this.countText.html(this.counter);
if( this.userIndex === this.cmpIndex ) {
this.score++;
this.scoreText.html(this.score);
}
if( this.counter == MAX_COUNT ) {
Standard_Dialog.open("Thank you, you have made 50 predictions.
",{
modal: true,
from: "next",
buttons: [{
text: "OK",
click: function () {
Standard_Dialog.close();
$(".next_button").show();
$(".next_button").focus();
}
}]
});
currentScore = this.score;
this.reset();
this.isPassed = true;
this.espNode.style.opacity = "0.5";
this.espNode.classList.add('disabled');
player.last_available_section++;
}
};
Activity.prototype.reset = function(){
this.userChoiceNode.innerHTML = "";
this.cmpChoiceNode.innerHTML = "";
this.score = 0;
this.counter = 0;
for( var i = 0; i < this.symbols.length; i++ ) {
this.symbols[i].setAttribute("tabindex", "-1");
this.symbols[i].setAttribute("outline", "none");
}
};
window.mheAYS = window.mheAYS || {};
window.mheAYS['test_ESP'] = {
initialize: function(section) {
section.slide = new Activity(section);
},
hide: function(section){
section.slide.reset();
},
show: function(section){
if(section.slide.isPassed) {
$(".next_button").show();
}
}
};
var scoreNode;
window.mheAYS['ESP_score'] = {
initialize: function(section) {
scoreNode = section.jq[0].querySelector(".scoreText");
},
show: function(section){
var strongNode = scoreNode.querySelector("strong");
var spanNode = $(section.jq[0].querySelectorAll(".scoreText")).find("span");
if ( currentScore <= 15 ) {
strongNode.innerHTML = currentScore;
//strongNode.innerHTML = FEEDBACK.MAIN_PART;
spanNode.html(FEEDBACK.LESS_THAN_15);
} else {
strongNode.innerHTML = currentScore;
//strongNode.innerHTML = FEEDBACK.MAIN_PART;
spanNode.html(FEEDBACK.MORE_THAN_15);
}
}
};
})();