From 59bb32fa44066efec0e33ab8feed569c2c78ff71 Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Mon, 20 Apr 2015 15:37:49 +0200 Subject: [PATCH 1/4] Create a spaceholder when resizing iframes. --- js/h5p-resizer.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/js/h5p-resizer.js b/js/h5p-resizer.js index 6318fc8..3d83db6 100644 --- a/js/h5p-resizer.js +++ b/js/h5p-resizer.js @@ -46,6 +46,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 +69,7 @@ actionHandlers.resize = function (iframe, data, respond) { // Resize iframe so all content is visible. iframe.style.height = data.height + 'px'; + iframe.nextSibling.remove(); }; /** From 8433f654af1ff9fee495d492d66e6de98f9d7e75 Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Tue, 21 Apr 2015 13:56:24 +0200 Subject: [PATCH 2/4] Remove element from DOM the correct way. --- js/h5p-resizer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/h5p-resizer.js b/js/h5p-resizer.js index 3d83db6..894951b 100644 --- a/js/h5p-resizer.js +++ b/js/h5p-resizer.js @@ -46,7 +46,7 @@ */ 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'; @@ -69,7 +69,7 @@ actionHandlers.resize = function (iframe, data, respond) { // Resize iframe so all content is visible. iframe.style.height = data.height + 'px'; - iframe.nextSibling.remove(); + iframe.parentNode.removeChild(iframe.nextSibling); }; /** From 27a0a332988155f1846aae8cefc407bf8275cc59 Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Tue, 21 Apr 2015 15:08:59 +0200 Subject: [PATCH 3/4] Prevent running multiple resizer. --- js/h5p-resizer.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/h5p-resizer.js b/js/h5p-resizer.js index 894951b..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 = {}; From 10918905966344220c8832ec30ed9303422b83f2 Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Tue, 21 Apr 2015 16:22:51 +0200 Subject: [PATCH 4/4] Fixed fullscreen checker. --- js/h5p.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/h5p.js b/js/h5p.js index 42b28f9..2978239 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); });