mirror of
https://github.com/moodle/moodle.git
synced 2025-02-19 15:45:59 +01:00
MDL-75692 core_h5p: Debounce resize events
* Make sure that we don't call the resize event too often to avoid infinite loop when content is auto resizing (fonts for example)
This commit is contained in:
parent
7f6d05ad04
commit
0ae1c37e6d
@ -159,6 +159,17 @@ var getH5PObject = async (iFrame) => {
|
||||
return H5P;
|
||||
};
|
||||
|
||||
/* eslint-disable promise/no-native */
|
||||
/**
|
||||
* Load the core/pending module.
|
||||
* @returns {Promise<Pending>}
|
||||
*/
|
||||
const getPendingClass = () => new Promise((resolve) => {
|
||||
require(['core/pending'], (Pending) => {
|
||||
resolve(Pending);
|
||||
});
|
||||
});
|
||||
|
||||
document.onreadystatechange = async() => {
|
||||
// Wait for instances to be initialize.
|
||||
if (document.readyState !== 'complete') {
|
||||
@ -212,6 +223,9 @@ document.onreadystatechange = async() => {
|
||||
H5P.trigger(instance, 'resize');
|
||||
});
|
||||
|
||||
const Pending = await getPendingClass();
|
||||
var resizePending = new Pending('core_h5p/iframe:resize');
|
||||
|
||||
H5P.on(instance, 'resize', function() {
|
||||
if (H5P.isFullscreen) {
|
||||
return; // Skip iframe resize.
|
||||
@ -231,7 +245,8 @@ document.onreadystatechange = async() => {
|
||||
} else {
|
||||
H5PEmbedCommunicator.send('hello');
|
||||
}
|
||||
}, 0);
|
||||
resizePending.resolve();
|
||||
}, 150);
|
||||
});
|
||||
|
||||
// Get emitted xAPI data.
|
||||
@ -294,6 +309,5 @@ document.onreadystatechange = async() => {
|
||||
}
|
||||
});
|
||||
|
||||
// Trigger initial resize for instance.
|
||||
H5P.trigger(instance, 'resize');
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user