Fix Issue #2823 - Ugly scrollbars in oembed iframes and broken resizing
This commit is contained in:
Michael Vogel 2016-10-01 10:40:08 +02:00 committed by GitHub
commit 40fbe1644d
3 changed files with 30 additions and 25 deletions

View file

@ -209,25 +209,32 @@ function oembed_format_object($j){
return mb_convert_encoding($ret, 'HTML-ENTITIES', mb_detect_encoding($ret)); return mb_convert_encoding($ret, 'HTML-ENTITIES', mb_detect_encoding($ret));
} }
function oembed_iframe($src,$width,$height) { /**
* Generates the iframe HTML for an oembed attachment. Width and height are given
if(! $width || strstr($width,'%')) * by the remote, and are regularly too small for the generated iframe.
$width = '640'; *
if(! $height || strstr($height,'%')) { * The width is entirely discarded for the actual width of the post, while fixed
$height = '300'; * height is used as a starting point before the inevitable resizing.
$resize = 'onload="resizeIframe(this);"'; *
} else * Since the iframe is automatically resized on load, there are no need for ugly
$resize = ''; * and impractical scrollbars.
*
// try and leave some room for the description line. * @param string $src Original remote URL to embed
$height = intval($height) + 80; * @param string $width
$width = intval($width) + 40; * @param string $height
* @return string
*
* @see oembed_format_object()
*/
function oembed_iframe($src, $width, $height) {
if (!$height || strstr($height,'%')) {
$height = '200';
}
$width = '100%';
$a = get_app(); $a = get_app();
$s = $a->get_baseurl() . '/oembed/'.base64url_encode($src);
$s = $a->get_baseurl()."/oembed/".base64url_encode($src); return '<iframe onload="resizeIframe(this);" class="embed_rich" height="' . $height . '" width="' . $width . '" src="' . $s . '" scrolling="no" frameborder="no">' . t('Embedded content') . '</iframe>';
return '<iframe '.$resize.' class="embed_rich" height="'.$height.'" width="'.$width.'" src="'.$s.'" frameborder="no">'.t('Embedded content').'</iframe>';
} }

View file

@ -5,17 +5,14 @@
function _resizeIframe(obj, desth) { function _resizeIframe(obj, desth) {
var h = obj.style.height; var h = obj.style.height;
var ch = obj.contentWindow.document.body.scrollHeight + 'px'; var ch = obj.contentWindow.document.body.scrollHeight;
if (h==ch) { if (h == (ch + 'px')) {
return; return;
} }
//console.log("_resizeIframe", obj, desth, ch); if (desth == ch && ch>0) {
if (desth!=ch) { obj.style.height = ch + 'px';
setTimeout(_resizeIframe, 500, obj, ch);
} else {
if (ch>0) obj.style.height = ch;
setTimeout(_resizeIframe, 1000, obj, ch);
} }
setTimeout(_resizeIframe, 100, obj, ch);
} }
function openClose(theID) { function openClose(theID) {

View file

@ -115,6 +115,7 @@ span.connector {
.embed_rich { .embed_rich {
display: block; display: block;
transition: height .75s;
} }
/* Shared Messages */ /* Shared Messages */