diff --git a/js/questionset.js b/js/questionset.js index 88e3847..ad1686b 100644 --- a/js/questionset.js +++ b/js/questionset.js @@ -233,32 +233,37 @@ H5P.QuestionSet = function (options, contentId) { finishButtonText: params.endGame.resultPage.finishButtonText }; endTemplate.update(target.attr('id'), eparams); + + var $video; + if (params.endGame.animations.showAnimations) { + var sources = ""; + var videoData = success ? params.endGame.animations.successVideo : params.endGame.animations.failVideo; + + if (videoData) { + for (var key in videoData) { + sources += ''; + } + // TODO: Width/height from somewhere. + $video = $(''); + $video[0].autoplay = false; + $video[0].load(); + } + } + $('.qs-finishbutton').click(function (ev) { // Display animation if present. - if (params.endGame.animations.showAnimations) { - // Init anims. - console.log("Now we should have started some anims..."); - var sources = ""; - var videoData = success ? params.endGame.animations.successVideo : params.endGame.animations.failVideo; - - if (videoData) { - for (var key in videoData) { - sources += ''; - } - // TODO: Width/height from somewhere. - var $video = $(''); - - target.html($video); - $video.on('play', function(ev) { - console.log('Video started playing!!!'); - }).on('ended', function(ev) { - console.log('Video is finished, quitting now!'); - // On animation finished: - $(returnObject).trigger('h5pQuestionSetFinished', eventData); - }); - // Play vidoi! - $video[0].play(); - } + if ($video) { + // Start video. + target.html($video); + $video.on('play', function(ev) { + console.log('Video started playing!!!'); + }).on('ended', function(ev) { + console.log('Video is finished, quitting now!'); + // On animation finished: + $(returnObject).trigger('h5pQuestionSetFinished', eventData); + }); + // Press play on tape! + $video[0].play(); } else { // Trigger finished event. $(returnObject).trigger('h5pQuestionSetFinished', eventData);