From c7cbd92f8c8a370180b03ac3cc09a0237d15b7b1 Mon Sep 17 00:00:00 2001 From: Ferran Recio Date: Thu, 11 Feb 2021 11:49:21 +0100 Subject: [PATCH] MDL-70806 h5p: fix resize glitch --- h5p/embed.php | 3 +++ h5p/templates/h5pembed.mustache | 7 ------- h5p/templates/h5perror.mustache | 11 ++++++++++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/h5p/embed.php b/h5p/embed.php index 360143649b4..779b3256ce9 100644 --- a/h5p/embed.php +++ b/h5p/embed.php @@ -87,6 +87,9 @@ if (empty($messages->error) && empty($messages->exception)) { $PAGE->add_body_class('h5p-embed'); $PAGE->set_pagelayout('embedded'); + // Load the embed.js to allow communication with the parent window. + $PAGE->requires->js(new moodle_url('/h5p/js/embed.js')); + echo $OUTPUT->header(); // Print all the errors. diff --git a/h5p/templates/h5pembed.mustache b/h5p/templates/h5pembed.mustache index 7a3502af5be..1a64f3cda1d 100644 --- a/h5p/templates/h5pembed.mustache +++ b/h5p/templates/h5pembed.mustache @@ -35,10 +35,3 @@ allowfullscreen="allowfullscreen" class="h5p-player w-100 border-0" style="height: 0px;" id="{{uniqid}}-h5player"> -{{#js}} -window.onload=function(){ - setTimeout(() => { - document.getElementById('{{uniqid}}-h5player').style.minHeight = '230px'; - }, 1000); -}; -{{/js}} diff --git a/h5p/templates/h5perror.mustache b/h5p/templates/h5perror.mustache index d4559854e2a..78f20d2fb4a 100644 --- a/h5p/templates/h5perror.mustache +++ b/h5p/templates/h5perror.mustache @@ -19,6 +19,8 @@ This template will render the embed code shown in the H5P content embed popup. + Note: this mustache is part of the H5P player and requires '/h5p/js/embed.js' already loaded. + Variables required for this template: * h5picon - The icon * message - The error messages to display. @@ -55,4 +57,11 @@ {{/error}} - \ No newline at end of file + +{{#js}} +(function() { + H5PEmbedCommunicator.send('resize', { + scrollHeight: document.body.scrollHeight + }); +})(); +{{/js}}