/** * 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() { // 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() { // 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(); } }; 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(); } }; })();