(function(){ 'use strict'; var FBReview = { CORRECT: "Select the NEXT button and move to the Conclusion.", INCORRECT: "Perhaps you should go back to review the basic process of evolution guided by natural selection." }; var FBPractice2 = { FEEDBACK: "All around the world, males on average are more interested in a mate that is young, physically attractive, and in good health, with a slim waist. According to evolutionary psychologists, these traits indicate high fertility. Across many centuries, men who preferred “mates with these traits” had more offspring to carry on their genes. On the other hand, all around the world, the typical female is more interested in a slightly older mate with wealth and status, especially if that person is willing to commit to a long-term relationship. Evolutionary psychologists point out that raising children is difficult and expensive. Across many centuries, women who preferred stable, prosperous mates were more likely to have children who survived to adulthood and passed on those genetic tendencies to future generations." }; var count = 0; var fb; var answers = [ 0, 1, 0, 1, 1, 0]; var currentAnswers = [ 0, 0, 0, 0, 0, 0]; var ReviewSlide = function(section) { this.section = section; this.section.points_possible = 1; this.section.points_earned = 0; this.section.section_completed = false; section.jq.addClass( 'review_3' ); this.buttons = this.section.jq[0].querySelectorAll( "button" ); var nameMC = this.section.jq.find('.movieclip').data('name'); this.mc = window.mheContpract.movieclips[nameMC]; addButtonsReview.call(this); // Add aria description addAriaElementReview.call( this ); initEventsReview.call( this ); updateButtons.call(this); }; ReviewSlide.prototype.showSlide = function() { this.ariaReader.focus(); }; ReviewSlide.prototype.finishSlide = function() { this.section.points_earned = this.section.points_possible; this.section.section_completed = true; player.activity.grade_activity(); player.update_section_status(); document.querySelector('.navigation' + '_button.next_button').focus(); }; var PracticeSlide1 = function(section) { this.section = section; this.section.points_possible = 1; this.section.points_earned = 0; this.section.section_completed = false; section.jq.addClass( 'practice_1' ); this.prefer = this.section.jq[0].querySelectorAll( ".babiesPrefer" ); this.avoid = this.section.jq[0].querySelectorAll( ".babiesAvoid" ); var nameMC = this.section.jq.find('.movieclip').data('name'); this.mc = window.mheContpract.movieclips[nameMC]; addButtonsPractice1.call(this); // Add aria description addAriaElementPractice1.call( this ); initEventsPractice1.call( this ); this.btnCheck.attr('disabled', (count === 0 ? 'disabled' : false)); }; PracticeSlide1.prototype.showSlide = function() { this.ariaReader.focus(); }; PracticeSlide1.prototype.finishSlide = function() { this.section.points_earned = this.section.points_possible; this.section.section_completed = true; player.activity.grade_activity(); player.update_section_status(); document.querySelector('.navigation' + '_button.next_button').focus(); }; var PracticeSlide2 = function(section) { this.section = section; this.section.points_possible = 1; this.section.points_earned = 0; this.section.section_completed = false; this.genderCheck = this.section.jq[0].querySelectorAll( ".gender" ); this.rows = this.section.jq[0].querySelectorAll( ".Row" ); section.jq.addClass( 'practice_2' ); var nameMC = this.section.jq.find('.movieclip').data('name'); this.mc = window.mheContpract.movieclips[nameMC]; addButtonsPractice2.call(this); // Add aria description addAriaElementPractice2.call( this ); initEventsPractice2.call( this ); this.btnCheck.attr('disabled', (count === 0 ? 'disabled' : false)); }; PracticeSlide2.prototype.showSlide = function() { this.ariaReader.focus(); }; PracticeSlide2.prototype.finishSlide = function() { this.section.points_earned = this.section.points_possible; this.section.section_completed = true; player.activity.grade_activity(); player.update_section_status(); document.querySelector('.navigation' + '_button.next_button').focus(); }; var addButtonsReview = function() { this.btnReset = $(''); this.btnCheck = $(''); this.btnCheck.bind('click', checkAnswerReview.bind(this)); this.btnReset.bind('click', resetAnswerReview.bind(this)); var btnContainer = $('
'); btnContainer.append(this.btnReset, this.btnCheck); this.section.jq.append(btnContainer); }; var addButtonsPractice1 = function() { this.btnCheck = $(''); this.btnCheck.bind('click', checkAnswerPractice1.bind(this)); var btnContainer = $(''); btnContainer.append(this.btnCheck); this.section.jq.append(btnContainer); }; var addButtonsPractice2 = function() { this.btnCheck = $(''); this.btnCheck.bind('click', checkAnswerPractice2.bind(this)); var btnContainer = $(''); btnContainer.append(this.btnCheck); this.section.jq.append(btnContainer); }; var resetAnswerReview = function(){ for( var i = 0; i < this.buttons.length; i++ ) { this.buttons[i].setAttribute('class', 'off'); this.buttons[i].style.background = "#FFF"; currentAnswers[i] = 0 } updateButtons.call(this); count = 0; } var checkAnswerReview = function(){ count = 0; for (var i = 0; i < this.buttons.length; i++) { //console.log(answers[i] + " - " + currentAnswers[i]) if ( answers[i] == currentAnswers[i] ) { if(answers[i]=== 1){ this.buttons[i].style.background = "#AAFF6C";} count++; } else { currentAnswers[i] = 0; this.buttons[i].setAttribute('class', 'off'); this.buttons[i].style.background = "#FFF"; } } if ( count === 6) { fb = FBReview.CORRECT; this.finishSlide(); this.btnCheck.attr('disabled', 'disabled'); Standard_Dialog.open(fb, { title: "Correct", "width": 485 }); } else { fb = FBReview.INCORRECT; Standard_Dialog.open(fb, { title: "Incorrect", "width": 485 }); } } var checkAnswerPractice1 = function(){ count = 0; this.btnCheck.hide() this.finishSlide(); for (var i = 0; i < this.prefer.length; ++i){ this.prefer[i].checked = false; this.avoid[i].checked = false; } this.prefer[0].checked = true; this.avoid[1].checked = true; this.avoid[2].checked = true; this.prefer[3].checked = true; this.prefer[4].checked = true; document.querySelectorAll(".feedback")[0].style.display = "block"; count++; }; var checkAnswerPractice2 = function(){ var blFeedback = document.querySelectorAll(".feedback")[1]; count = 0; this.finishSlide(); blFeedback.setAttribute('aria-live', 'assertive'); blFeedback.setAttribute('role', 'alert'); blFeedback.innerHTML = FBPractice2.FEEDBACK; count++; }; var updateButtons = function() { this.btnCheck.attr('disabled', (count === 0 ? 'disabled' : false)); this.btnReset.attr('disabled', (count === 0 ? 'disabled' : false)); }; var initEventsReview = function(){ for (var i = 0; i < this.buttons.length; i++) { this.buttons[i].addEventListener("click", (function(index, context) { return function() { //console.log(context.buttons[index]); context.buttons[index].setAttribute('class', 'on'); context.buttons[index].style.background = "#5A87DC"; currentAnswers[index] = 1; if ( index % 2 == 1 ) { if ( currentAnswers[index - 1] != 0 ) { currentAnswers[index - 1] = 0; context.buttons[index - 1].setAttribute('class', 'off'); context.buttons[index - 1].style.background = "#FFF"; } } else { if ( currentAnswers[index + 1] != 0 ) { currentAnswers[index + 1] = 0; context.buttons[index + 1].setAttribute('class', 'off'); context.buttons[index + 1].style.background = "#FFF"; } } count++; updateButtons.call(context); } })(i, this)); } }; var initEventsPractice1 = function(){ this.btnCheck.attr('disabled', false); for (var i = 0; i < this.prefer.length; ++i){ this.prefer[i].addEventListener("click", function(){ if ((this.prefer[0].checked || this.avoid[0].checked)&& (this.prefer[1].checked || this.avoid[1].checked) && (this.prefer[2].checked || this.avoid[2].checked) && (this.prefer[3].checked || this.avoid[3].checked) && (this.prefer[4].checked || this.avoid[4].checked)){ this.btnCheck.attr('disabled', false); }}.bind(this)); this.avoid[i].addEventListener("click", function(){ if ((this.prefer[0].checked || this.avoid[0].checked)&& (this.prefer[1].checked || this.avoid[1].checked) && (this.prefer[2].checked || this.avoid[2].checked) && (this.prefer[3].checked || this.avoid[3].checked) && (this.prefer[4].checked || this.avoid[4].checked)){ this.btnCheck.attr('disabled', false); }}.bind(this)) } }; var initEventsPractice2 = function(){ for (var i = 0; i < this.genderCheck.length; ++i){ this.genderCheck[i].addEventListener("click", function(){ if ((this.genderCheck[0].checked || this.genderCheck[1].checked) && ((this.genderCheck[2].checked || this.genderCheck[3].checked)) && ((this.genderCheck[4].checked || this.genderCheck[5].checked)) && ((this.genderCheck[6].checked || this.genderCheck[7].checked)) && ((this.genderCheck[8].checked || this.genderCheck[9].checked)) && ((this.genderCheck[10].checked || this.genderCheck[11].checked))){ this.btnCheck.attr('disabled', false); }}.bind(this)) } for (var j = 0; j < this.rows.length; ++j){ this.rows[j].addEventListener("keyup", function(){ if (arguments[0].keyCode == 37){ arguments[0].currentTarget.querySelectorAll(".gender")[0].checked = !arguments[0].currentTarget.querySelectorAll(".gender")[0].checked; } else if (arguments[0].keyCode == 39){ arguments[0].currentTarget.querySelectorAll(".gender")[1].checked = !arguments[0].currentTarget.querySelectorAll(".gender")[1].checked; } }.bind(this)) } }; var addAriaElementReview = function() { var ariaLabel = this.section.title + '.'; this.ariaReader = $(''); this.section.jq.prepend(this.ariaReader); }; var addAriaElementPractice1 = function() { var ariaLabel = this.section.title + '.'; this.ariaReader = $(''); this.section.jq.prepend(this.ariaReader); }; var addAriaElementPractice2 = function() { var ariaLabel = this.section.title + '.'; this.ariaReader = $(''); this.section.jq.prepend(this.ariaReader); }; var preventTab = function(e) { e = e || window.event; if ( !e.shiftKey && e.keyCode === 9 ) { // !Shift + Tab key e.preventDefault(); document.querySelector('.navigation_button.next_button').focus(); } }; var stopMC = function(i) { var mc = this.mc.root['step' + (i + 1)]; mc.onStop = function() {}; mc.gotoAndStop(0); }; var hideAnswers = function() { for (var i = 0; i < this.answers.length; i++) { this.answers[i].style.display = 'none'; } }; var showStep = function(i) { hideStep.call(this, this.currentStep); this.currentStep = i; this.buttons[i].addClass('selected'); this.steps[i].style.display = ''; hideAnswers.call(this); this.mc.root.gotoAndStop(this.mc.root.labels['step' + (i + 1)]); this.ansButtons[2].show(); this.inst.style.display = ''; this.ansButtons[3].hide(); }; var hideStep = function(i) { if ( i === null ) { return; } stopMC.call(this, i); $(this.buttons[i]).removeClass('selected'); this.steps[i].style.display = 'none'; }; window.mheContpract = window.mheContpract || {}; window.mheContpract['review_3'] = { initialize: function(section) { section.slide = new ReviewSlide(section); }, show: function(section) { section.slide.showSlide(); } }; window.mheContpract['practice_1'] = { initialize: function(section) { section.slide = new PracticeSlide1(section); }, show: function(section) { section.slide.showSlide(); } }; window.mheContpract['practice_2'] = { initialize: function(section) { section.slide = new PracticeSlide2(section); }, show: function(section) { section.slide.showSlide(); } }; })();