From 6374504868d6bc99e3f9be6999c5892837ed2b20 Mon Sep 17 00:00:00 2001 From: Andreas Nergaard Date: Tue, 9 May 2017 10:27:50 +0200 Subject: [PATCH] HFP-815 Added function to limit number of auto plays at a time. --- js/questionset.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/js/questionset.js b/js/questionset.js index 0fdd085..512bf58 100644 --- a/js/questionset.js +++ b/js/questionset.js @@ -353,6 +353,8 @@ H5P.QuestionSet = function (options, contentId, contentData) { currentQuestion = questionNumber; + handleAutoPlay(currentQuestion); + // Hide all questions $('.question-container', $myDom).hide().eq(questionNumber).show(); @@ -403,6 +405,21 @@ H5P.QuestionSet = function (options, contentId, contentData) { return currentQuestion; }; + /** + * Handle autoplays, limit to one at a time + */ + var handleAutoPlay = function (currentQuestion) { + for (var i = 0; i < questionInstances.length; i++) { + questionInstances[i].pause(); + } + + var hasAutoPlay = params.questions[currentQuestion].params.media.params.playback.autoplay; + + if (hasAutoPlay) { + questionInstances[currentQuestion].play(); + } + }; + /** * Show solutions for subcontent, and hide subcontent buttons. * Used for contracts with integrated content.