Skip to content

Instantly share code, notes, and snippets.

@Dizolivemint
Last active March 11, 2021 19:51
Show Gist options
  • Save Dizolivemint/7aa97633b47b53a296a5eada50fc1ab9 to your computer and use it in GitHub Desktop.
Save Dizolivemint/7aa97633b47b53a296a5eada50fc1ab9 to your computer and use it in GitHub Desktop.
H5P Resize Event
/* Wait for DOM to load */
document.addEventListener('DOMContentLoaded', function() {
/* Add event listener to TOC links */
const buttons = document.querySelectorAll('.chapter-title');
buttons.forEach(function(button) {
button.addEventListener('click', function () {
// Need a timeout to wait for the active page getting the correct class
setTimeout(function() {
const iframes = document.querySelectorAll('iframe');
iframes.forEach(function(iframe) {
if (iframe.src.indexOf('h5p') !== -1) {
iframe.contentWindow.postMessage({context: 'h5p', action: 'ready'}, '*');
}
})
}, 300);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment