From 439aee0a82d7919376fd0d64c7248d9a6b0fc5e9 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Fri, 1 May 2015 14:29:53 +0200 Subject: [PATCH] Automatically resize iframe if no height was provided. --- include/oembed.php | 9 +++++++-- js/main.js | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/include/oembed.php b/include/oembed.php index a793bd8006..6fc9817299 100755 --- a/include/oembed.php +++ b/include/oembed.php @@ -199,10 +199,15 @@ function oembed_format_object($j){ } function oembed_iframe($src,$width,$height) { + if(! $width || strstr($width,'%')) $width = '640'; - if(! $height || strstr($height,'%')) + if(! $height || strstr($height,'%')) { $height = '300'; + $resize = 'onload="resizeIframe(this);"'; + } else + $resize = ''; + // try and leave some room for the description line. $height = intval($height) + 80; $width = intval($width) + 40; @@ -210,7 +215,7 @@ function oembed_iframe($src,$width,$height) { $a = get_app(); $s = $a->get_baseurl()."/oembed/".base64url_encode($src); - return ''; + return ''; } diff --git a/js/main.js b/js/main.js index d7381c96a4..25029c1b05 100644 --- a/js/main.js +++ b/js/main.js @@ -1,3 +1,7 @@ + function resizeIframe(obj) { + obj.style.height = 0; + obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px'; + } function openClose(theID) { if(document.getElementById(theID).style.display == "block") {