diff --git a/js/h5p-embed.js b/js/h5p-embed.js index 3196fa1..c141456 100644 --- a/js/h5p-embed.js +++ b/js/h5p-embed.js @@ -66,7 +66,6 @@ var H5POldEmbed = H5POldEmbed || (function () { loadResizer(h5ps[i].getAttribute('data-h5p')); } addIframe(h5ps[i]); - } } diff --git a/js/h5p-resizer.js b/js/h5p-resizer.js index d1a1905..6318fc8 100644 --- a/js/h5p-resizer.js +++ b/js/h5p-resizer.js @@ -108,4 +108,17 @@ }); } }, false); + + // Let h5p iframes know we're ready! + var iframes = document.getElementsByTagName('iframe'); + var ready = { + context: 'h5p', + action: 'ready' + }; + for (var i = 0; i < iframes.length; i++) { + if (iframes[i].src.indexOf('h5p') !== -1) { + iframes[i].contentWindow.postMessage(ready, '*'); + } + } + })(); diff --git a/js/h5p.js b/js/h5p.js index 8ade0e6..1937f43 100644 --- a/js/h5p.js +++ b/js/h5p.js @@ -145,6 +145,11 @@ H5P.init = function () { // External embed var parentIsFriendly = false; + // Handle that the resizer is loaded after the iframe + H5P.communicator.on('ready', function () { + H5P.communicator.send('hello'); + }); + // Handle hello message from our parent window H5P.communicator.on('hello', function () { // Initial setup/handshake is done @@ -153,7 +158,8 @@ H5P.init = function () { // Hide scrollbars for correct size document.body.style.overflow = 'hidden'; - H5P.communicator.send('prepareResize'); + // Content need to be resized to fit the new iframe size + H5P.trigger(instance, 'resize'); }); // When resize has been prepared tell parent window to resize @@ -192,14 +198,14 @@ H5P.init = function () { H5P.jQuery(window.top).resize(function () { if (window.parent.H5P.isFullscreen) { // Use timeout to avoid bug in certain browsers when exiting fullscreen. Some browser will trigger resize before the fullscreenchange event. - H5P.trigger(instance, 'resize'); + H5P.trigger(instance, 'resize'); } else { H5P.trigger(instance, 'resize'); } }); } - + H5P.instances.push(instance); // Resize content.