From 71f92ff664cb6f7c09abcd0a0093b7605351a375 Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Mon, 4 Jul 2016 11:54:28 +0200 Subject: [PATCH] Prevent stealing focus when page loads HFJ-2040 --- js/questionset.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/js/questionset.js b/js/questionset.js index dd231c5..9c2eac7 100644 --- a/js/questionset.js +++ b/js/questionset.js @@ -204,7 +204,7 @@ H5P.QuestionSet = function (options, contentId) { } }; - var _showQuestion = function (questionNumber) { + var _showQuestion = function (questionNumber, preventAnnouncement) { // Sanitize input. if (questionNumber < 0) { questionNumber = 0; @@ -242,21 +242,23 @@ H5P.QuestionSet = function (options, contentId) { toggleCurrentDot(questionNumber, true); } - // Announce question number of total, must use timeout because of buttons logic - setTimeout(function () { - var humanizedProgress = params.texts.readSpeakerProgress - .replace('@current', (currentQuestion + 1).toString()) - .replace('@total', questionInstances.length.toString()); + if (!preventAnnouncement) { + // Announce question number of total, must use timeout because of buttons logic + setTimeout(function () { + var humanizedProgress = params.texts.readSpeakerProgress + .replace('@current', (currentQuestion + 1).toString()) + .replace('@total', questionInstances.length.toString()); - $('.qs-progress-announcer', $myDom) - .show() - .html(humanizedProgress) - .focus(); + $('.qs-progress-announcer', $myDom) + .show() + .html(humanizedProgress) + .focus(); - if (instance && instance.readFeedback) { - instance.readFeedback(); - } - }, 0); + if (instance && instance.readFeedback) { + instance.readFeedback(); + } + }, 0); + } // Remember where we are _updateButtons(); @@ -661,7 +663,7 @@ H5P.QuestionSet = function (options, contentId) { // Hide all but initial Question. - _showQuestion(params.initialQuestion); + _showQuestion(params.initialQuestion, true); if (renderSolutions) { showSolutions();