Skip to content

Commit

Permalink
Fixed so that iframes can be loaded before resizer script.
Browse files Browse the repository at this point in the history
  • Loading branch information
icc committed Mar 2, 2015
1 parent 553ae24 commit e961f61
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
1 change: 0 additions & 1 deletion js/h5p-embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ var H5POldEmbed = H5POldEmbed || (function () {
loadResizer(h5ps[i].getAttribute('data-h5p'));
}
addIframe(h5ps[i]);

}
}

Expand Down
13 changes: 13 additions & 0 deletions js/h5p-resizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, '*');
}
}

})();
12 changes: 9 additions & 3 deletions js/h5p.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit e961f61

Please sign in to comment.