Fixed so that iframes can be loaded before resizer script.

d6
Frode Petterson 2015-03-02 15:53:29 +01:00
parent 553ae243d2
commit e961f614a4
3 changed files with 22 additions and 4 deletions

View File

@ -66,7 +66,6 @@ var H5POldEmbed = H5POldEmbed || (function () {
loadResizer(h5ps[i].getAttribute('data-h5p'));
}
addIframe(h5ps[i]);
}
}

View File

@ -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, '*');
}
}
})();

View File

@ -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