diff --git a/js/h5p-resizer.js b/js/h5p-resizer.js index 6318fc8..bbfb009 100644 --- a/js/h5p-resizer.js +++ b/js/h5p-resizer.js @@ -1,8 +1,9 @@ // H5P iframe Resizer (function () { - if (!window.postMessage || !window.addEventListener) { + if (!window.postMessage || !window.addEventListener || window.h5pResizerInitialized) { return; // Not supported } + window.h5pResizerInitialized = true; // Map actions to handlers var actionHandlers = {}; @@ -47,6 +48,11 @@ actionHandlers.prepareResize = function (iframe, data, respond) { responseData = {}; + // Create spaceholder and insert after iframe. + var spaceholder = document.createElement('div'); + spaceholder.style.height = (iframe.clientHeight - 1) + 'px'; + iframe.parentNode.insertBefore(spaceholder, iframe.nextSibling); + // Reset iframe height, in case content has shrinked. iframe.style.height = '1px'; @@ -64,6 +70,7 @@ actionHandlers.resize = function (iframe, data, respond) { // Resize iframe so all content is visible. iframe.style.height = data.height + 'px'; + iframe.parentNode.removeChild(iframe.nextSibling); }; /** diff --git a/js/h5p-x-api.js b/js/h5p-x-api.js index 14cbb7e..87a6267 100644 --- a/js/h5p-x-api.js +++ b/js/h5p-x-api.js @@ -3,10 +3,6 @@ var H5P = H5P || {}; // Create object where external code may register and listen for H5P Events H5P.externalDispatcher = new H5P.EventDispatcher(); -if (H5P.isFramed && H5P.externalEmbed === false) { - H5P.externalDispatcher.on('*', window.top.H5P.externalDispatcher.trigger); -} - // EventDispatcher extensions /** diff --git a/js/h5p.js b/js/h5p.js index 42b28f9..b77a113 100644 --- a/js/h5p.js +++ b/js/h5p.js @@ -67,7 +67,7 @@ H5P.init = function (target) { // Determine if we can use full screen if (H5P.canHasFullScreen === undefined) { - H5P.canHasFullScreen = (H5P.isFramed && H5P.externalEmbed !== false) ? (document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullScreenEnabled || document.msFullscreenEnabled) : true; + H5P.canHasFullScreen = (H5P.isFramed && H5P.externalEmbed !== false) ? ((document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullScreenEnabled || document.msFullscreenEnabled) ? true : false) : true; } // H5Ps added in normal DIV. @@ -111,7 +111,7 @@ H5P.init = function (target) { var instance = H5P.newRunnable(library, contentId, $container, true); // Check if we should add and display a fullscreen button for this H5P. - if (contentData.fullScreen == 1) { + if (contentData.fullScreen == 1 && H5P.canHasFullScreen) { H5P.jQuery('
').prependTo($container).children().click(function () { H5P.fullScreen($container, instance); }); @@ -1395,7 +1395,7 @@ H5P.cssLoaded = function (path) { * @returns {array} The passed array is returned for chaining. */ H5P.shuffleArray = function (array) { - if (! array instanceof Array) { + if (!(array instanceof Array)) { return; } @@ -1747,12 +1747,16 @@ H5P.createTitle = function(rawTitle, maxLength) { if (state !== undefined) { // Async is not used to prevent the request from being cancelled. H5P.setUserData(instance.contentId, 'state', state, {deleteOnChange: true, async: false}); - } } } }); } + + // Relay events to top window. + if (H5P.isFramed && H5P.externalEmbed === false) { + H5P.externalDispatcher.on('*', window.top.H5P.externalDispatcher.trigger); + } }); })(H5P.jQuery);