(function(){ 'use strict'; var FB = { CORRECT: "Select the NEXT button and move to Quiz 2.", INCORRECT: "Try to respond to the statements again." }; var count = 0; var fb; var answers = [ 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1]; var currentAnswers = [ 0, 0, 0, 0, 0, 0, 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( 'radio_quiz' ); this.buttons = this.section.jq[0].querySelectorAll( "button" ); var nameMC = this.section.jq.find('.movieclip').data('name'); this.mc = window.mheContpract.movieclips[nameMC]; addButtons.call(this); // Add aria description addAriaElement.call( this ); initEvents.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 addButtons = function() { this.btnReset = $(''); this.btnCheck = $(''); this.btnCheck.bind('click', checkAnsver.bind(this)); this.btnReset.bind('click', resetAnsver.bind(this)); var btnContainer = $('
'); btnContainer.append(this.btnReset, this.btnCheck); this.section.jq.append(btnContainer); }; var resetAnsver = 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 checkAnsver = 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 === answers.length ) { fb = FB.CORRECT; this.finishSlide(); this.btnCheck.attr('disabled', 'disabled'); Standard_Dialog.open(fb, { title: "Correct", "width": 485 }); } else { fb = FB.INCORRECT; Standard_Dialog.open(fb, { title: "Incorrect", "width": 485 }); } } var updateButtons = function() { this.btnCheck.attr('disabled', (count === 0 ? 'disabled' : false)); this.btnReset.attr('disabled', (count === 0 ? 'disabled' : false)); }; var initEvents = 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 addAriaElement = 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['radio_quiz'] = { initialize: function(section) { section.slide = new ReviewSlide(section); }, show: function(section) { section.slide.showSlide(); } }; })();