From 6413e664b1b454073c30bf10298fc6a40ed9f73b Mon Sep 17 00:00:00 2001 From: Oliver Tacke Date: Sun, 1 Mar 2020 13:53:46 +0100 Subject: [PATCH] Fix intro image scaling if used in compound content types When using QS in compount content types (in Column in particular), the intro div may not have been rendered when determining its width. In consequence, instead of scaling the intro image to full width, it would be displayed in its natural dimensions in Column. This pull request fixes this behavior and the intro image will scale properly in Column as well. --- js/questionset.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/js/questionset.js b/js/questionset.js index 267f8d5..ad672eb 100644 --- a/js/questionset.js +++ b/js/questionset.js @@ -946,11 +946,14 @@ H5P.QuestionSet = function (options, contentId, contentData) { if ($intro.length) { var bgImg = params.introPage.backgroundImage; var bgImgRatio = (bgImg.height / bgImg.width); - $intro.css({ - background: '#fff url("' + H5P.getPath(bgImg.path, contentId) + '") no-repeat 50% 50%', - backgroundSize: 'auto 100%', - minHeight: bgImgRatio * +window.getComputedStyle($intro[0]).width.replace('px','') - }); + + setTimeout(function () { + $intro.css({ + background: '#fff url("' + H5P.getPath(bgImg.path, contentId) + '") no-repeat 50% 50%', + backgroundSize: 'auto 100%', + minHeight: bgImgRatio * +window.getComputedStyle($intro[0]).width.replace('px','') + }); + }, 0); } }