Skip to content

Commit 66678ab

Browse files
authored
Merge pull request #66 from catalyst/stable-catalyst-fix-resize-rebase
adding control and height for proper display of control panel fix #49
2 parents b9cf2a3 + 475e6f3 commit 66678ab

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

amd/build/embed.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

amd/build/embed.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

amd/src/embed.js

+19-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ define(['jquery', 'mod_hvp/communicator'], function($, H5PEmbedCommunicator) {
2222
var resizeDelay;
2323
var instance = H5P.instances[0];
2424
var parentIsFriendly = false;
25+
var completionheight = 0;
26+
if (globalThis.completion) {
27+
var completionactivity = document.getElementsByClassName('activity-header')[0];
28+
var completionmargin = document.defaultView.getComputedStyle(completionactivity, '')
29+
.getPropertyValue('margin-bottom');
30+
completionheight = completionactivity.scrollHeight + parseInt(completionmargin, 10); // We want the first element.
31+
}
2532

2633
// Handle that the resizer is loaded after the iframe.
2734
H5PEmbedCommunicator.on('ready', function() {
@@ -41,11 +48,10 @@ define(['jquery', 'mod_hvp/communicator'], function($, H5PEmbedCommunicator) {
4148
// Content need to be resized to fit the new iframe size.
4249
H5P.trigger(instance, 'resize');
4350
});
44-
4551
// When resize has been prepared tell parent window to resize.
4652
H5PEmbedCommunicator.on('resizePrepared', function() {
4753
H5PEmbedCommunicator.send('resize', {
48-
scrollHeight: iFrame.contentDocument.body.scrollHeight
54+
scrollHeight: iFrame.contentDocument.body.scrollHeight + ((globalThis.completion) ? completionheight : 0)
4955
});
5056
});
5157

@@ -66,7 +72,7 @@ define(['jquery', 'mod_hvp/communicator'], function($, H5PEmbedCommunicator) {
6672
H5PEmbedCommunicator.send('prepareResize',
6773
{
6874
scrollHeight: iFrame.contentDocument.body.scrollHeight,
69-
clientHeight: iFrame.contentDocument.body.clientHeight
75+
clientHeight: iFrame.contentDocument.body.clientHeight + ((globalThis.completion) ? completionheight : 0)
7076
}
7177
);
7278
} else {
@@ -93,5 +99,13 @@ define(['jquery', 'mod_hvp/communicator'], function($, H5PEmbedCommunicator) {
9399
}
94100
});
95101
});
96-
97-
});
102+
return /** @alias module:mod_hvp/embed */ {
103+
/**
104+
* Initialise embed instance.
105+
* @param {boolean} completion a boolean about displaying the completion information
106+
*/
107+
init: function (completion) {
108+
globalThis.completion = completion;
109+
},
110+
};
111+
});

embed.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@
8282
// Release session while loading the rest of our assets.
8383
core\session\manager::write_close();
8484

85+
// Verify is the completion information is being displayed.
86+
$completiondisplay = false;
87+
if ($cm->completion != 0) {
88+
$completiondisplay = true;
89+
}
90+
91+
// If there is intro for the activity, we will add height for the embed.
92+
if (!empty($content['intro'])) {
93+
$completiondisplay = true;
94+
}
95+
8596
// Configure page.
8697
$PAGE->set_url(new \moodle_url('/mod/hvp/embed.php', array('id' => $id)));
8798
$PAGE->set_title(format_string($content['title']));
@@ -96,7 +107,7 @@
96107
$PAGE->add_body_class('h5p-embed');
97108
$PAGE->set_pagelayout('embedded');
98109
$root = \mod_hvp\view_assets::getsiteroot();
99-
$PAGE->requires->js_call_amd('mod_hvp/embed');
110+
$PAGE->requires->js_call_amd('mod_hvp/embed', 'init', ['completion' => $completiondisplay]);
100111
// Add H5P assets to page.
101112
$view->addassetstopage();
102113
$view->logviewed();

0 commit comments

Comments
 (0)