Last active
March 11, 2021 19:51
-
-
Save Dizolivemint/7aa97633b47b53a296a5eada50fc1ab9 to your computer and use it in GitHub Desktop.
H5P Resize Event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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