/** * Created by Mitina on 19.01.2016. */ (function() { 'use strict'; var event = window.mheContpract.libs['event'].user; var ReviewSlide = function(section) { this.section = section; this.section.points_possible = 1; this.section.points_earned = 0; this.section.section_completed = false; this.section.jq.addClass('review_2'); var nameMC = this.section.jq.find('.movieclip').data('name'); this.mc = window.mheContpract.movieclips[nameMC]; this.mc.root['main'].onStop = showQuestion.bind(this); this.question = this.section.jq.find('.question').hide(); this.answer = this.section.jq.find('.answer').hide(); this.answer[0].addEventListener('keydown', function(e) { e = e || window.event; if ( !e.shiftKey && e.keyCode === 9 ) { // !Shift + Tab key e.preventDefault(); document.querySelector('.navigation_button.next_button').focus(); } }); addButtons.call(this); // Add aria description addAriaElement.call(this); }; var addButtons = function() { this.btnReset = $(''); this.btnAnswer = $(''); this.btnPlay = $(''); this.btnPlay.bind('click', playMC.bind(this)); this.btnAnswer.bind('click', showAnswer.bind(this)); this.btnReset.bind('click', resetAll.bind(this)); var btnContainer = $('
'); btnContainer.append( this.btnAnswer, this.btnReset); this.section.jq.find('.svg-container').append(this.btnPlay); this.section.jq.append(btnContainer); // At first hide buttons this.btnAnswer.hide(); this.btnReset.hide(); }; var showQuestion = function() { this.question.show(); // Show buttons this.btnAnswer.show(); this.btnReset.show(); this.question.focus(); }; var resetAll = function() { var allAriaTexts = document.getElementsByClassName("aria-text"); // Clear aria-text divs for (var i = 0; i < allAriaTexts.length; i++) { allAriaTexts[i].innerText = ""; } // Hide buttons this.btnAnswer.hide(); this.btnReset.hide(); // Hide question and answer this.question.hide(); this.answer.hide(); resetMovieClip.call(this); }; var resetMovieClip = function() { this.mc.root['main'].onStop = function() {}; this.mc.root['main'].gotoAndStop(0); this.mc.root['main'].onStop = showQuestion.bind(this); }; var showAnswer = function() { if ( !this.section.section_completed ) { finishSlide.call(this); } this.answer.show(); this.answer.focus(); }; var playMC = function() { var allAriaTexts = document.getElementsByClassName("aria-text"); var currentSlide; // Movie doesn't play if ( !this.mc.root['main'].isPlayable ) { // Movie is not in the beginning if ( this.mc.root['main'].currentFrame !== 0 ) { this.mc.root['main'].gotoAndStop(0); } this.mc.root['main'].play(); if (this.section.index === 7) { currentSlide = 0; allAriaTexts[currentSlide].innerText = "Here is a rat in an operant conditioning chamber. The rat is hungry and is exploring the environment, looking for food. As the rat explores the bar or lever mounted in the wall, by chance the rat presses the bar. The bar-pressing behavior is followed by a pleasant consequence: a food dispenser opens and food is available for 10 seconds."; } if (this.section.index === 8) { currentSlide = 1; allAriaTexts[currentSlide].innerText = "An electric current has been connected to the metal floor of the same chamber, giving the rat a painful shock. As the rat jumps around in panic, looking for a way to escape the shock, by chance the rat presses the bar. The bar-pressing behavior is followed by a pleasant consequence: the shock stops for 10 seconds."; } if (this.section.index === 9) { currentSlide = 2; allAriaTexts[currentSlide].innerText = "Here is a rat in an operant conditioning chamber. The rat is hungry and is exploring the environment, looking for food. As the rat explores the bar or lever mounted in the wall, by chance the rat presses the bar. The bar-pressing behavior is followed by an unpleasant consequence: the floor of the chamber is connected to an electric current for 10 seconds, giving the rat a painful shock."; } if (this.section.index === 10) { currentSlide = 3; allAriaTexts[currentSlide].innerText = "The rat has eaten some of the food from the food dispenser, but is still exploring the environment. As the rat explores the bar or lever mounted in the wall, by chance the rat presses the bar. The bar-pressing behavior is followed by an unpleasant consequence; the food dispenser closes and the food is gone for 10 seconds."; } } }; var addAriaElement = function() { var ariaLabel = this.section.title + '. ' + this.section.instructions; this.ariaReader = $(''); this.section.jq.prepend(this.ariaReader); }; var finishSlide = function() { this.section.points_earned = this.section.points_possible; this.section.section_completed = true; player.activity.grade_activity(); player.update_section_status(); }; ReviewSlide.prototype.hideSlide = function() { resetMovieClip.call(this); }; ReviewSlide.prototype.showSlide = function() { this.ariaReader.focus(); }; window.mheContpract = window.mheContpract || {}; window.mheContpract['review_2'] = { initialize: function(section) { section.slide = new ReviewSlide(section); }, show: function(section) { section.slide.showSlide(); }, hide: function(section) { section.slide.hideSlide(); } }; })();