injects our attribs into iframe element
This commit is contained in:
parent
f4d75b5b78
commit
34713d9acb
|
@ -8,8 +8,8 @@ use Omeka\Site\BlockLayout\AbstractBlockLayout;
|
|||
use Laminas\View\Renderer\PhpRenderer;
|
||||
|
||||
use Laminas\Form\FormElementManager;
|
||||
|
||||
use Vimeo\Form\VimeoBlockForm;
|
||||
use DOMDocument;
|
||||
|
||||
class Vimeo extends AbstractBlockLayout
|
||||
{
|
||||
|
@ -66,27 +66,53 @@ class Vimeo extends AbstractBlockLayout
|
|||
|
||||
public function render(PhpRenderer $view, SitePageBlockRepresentation $block)
|
||||
{
|
||||
$attachments = $block->attachments();
|
||||
if (!$attachments) {
|
||||
return '';
|
||||
}
|
||||
$attachments = $block->attachments();
|
||||
if (!$attachments) {
|
||||
return '';
|
||||
}
|
||||
$media = $attachments[0]->item()->media()[0];
|
||||
$width = $media->mediaData()['width'];
|
||||
$width = 100;
|
||||
$height = 0;
|
||||
|
||||
$thumbnails = [];
|
||||
static $id = 0;
|
||||
// creates an iframe injecting our width and calculated ratio and height
|
||||
$attribs=" ";
|
||||
$original_width = 0;
|
||||
$original_height = 0;
|
||||
$doc = new DOMDocument();
|
||||
$doc->loadHTML($media->mediaData()['html']);
|
||||
$html_element= $doc->getElementsByTagName('iframe')->item(0);
|
||||
if ($html_element->hasAttributes()) {
|
||||
foreach ($html_element->attributes as $attr) {
|
||||
$name = $attr->nodeName;
|
||||
$value = $attr->nodeValue;
|
||||
if ($name == 'height') {
|
||||
$original_height = $value;
|
||||
continue;
|
||||
}
|
||||
if ($name == 'width') {
|
||||
$original_width = $value;
|
||||
$attrib = $name.'="'.$width.'%"';
|
||||
$attribs .= $attrib.PHP_EOL;
|
||||
continue;
|
||||
}
|
||||
$attrib = $name.'="'.$value.'"';
|
||||
$attribs .= $attrib.PHP_EOL;
|
||||
}
|
||||
}
|
||||
if ($original_height !== 0) {
|
||||
$ratio = $original_width / $original_height;
|
||||
$attrib = 'ratio="'.$ratio.'"';
|
||||
$attribs .= $attrib.PHP_EOL;
|
||||
}
|
||||
$iframe = "<iframe ".$attribs." >".PHP_EOL."</iframe>";
|
||||
|
||||
$media = $attachments[0]->item()->media()[0];
|
||||
$vimeo_width = $media->mediaData()['width'];
|
||||
$vimeo_height = $media->mediaData()['height'];
|
||||
$ratio = $vimeo_width / $vimeo_height;
|
||||
|
||||
return $view->partial('common/block-layout/vimeo', [
|
||||
'title' => $block->dataValue('title'),
|
||||
'renderSourceLink' => $block->dataValue('renderSourceLink'),
|
||||
'item_url' => $attachments[0]->item()->url(),
|
||||
'width' => $block->dataValue('width'),
|
||||
'video_id' => $media->mediaData()['video_id'],
|
||||
'ratio' => $ratio,
|
||||
'vimeo_iframe' => $media->mediaData()['html'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
return $view->partial('common/block-layout/vimeo', [
|
||||
'title' => $block->dataValue('title'),
|
||||
'renderSourceLink' => $block->dataValue('renderSourceLink'),
|
||||
'item_url' => $attachments[0]->item()->url(),
|
||||
'ratio' => $ratio,
|
||||
'vimeo_iframe' => $iframe
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,8 @@ $this->headScript()->appendFile($this->assetUrl('js/height_calculator.js',
|
|||
'Vimeo'));
|
||||
?>
|
||||
|
||||
<div id="vimeo_<?= $video_id ?>" class="vimeo-embed-wrapper" style="position:relative;">
|
||||
<div class="vimeo-embed-wrapper"
|
||||
style="position:relative;">
|
||||
|
||||
<?php if ($renderSourceLink) { ?>
|
||||
<div class="source-link">
|
||||
|
@ -25,9 +26,8 @@ $this->headScript()->appendFile($this->assetUrl('js/height_calculator.js',
|
|||
function adjust_height() {
|
||||
$(".vimeo-embed-wrapper").each(function() {
|
||||
var iframe = $(this).find('iframe')
|
||||
$(iframe).prop("width", "<?= $width ?>%")
|
||||
var height = get_height(iframe, <?= $ratio ?>)
|
||||
$(iframe).prop("height", height)
|
||||
var ratio = $(iframe).attr('ratio')
|
||||
$(iframe).prop("height", get_height(iframe, ratio))
|
||||
});
|
||||
}
|
||||
jQuery(document).ready(function() {
|
||||
|
|
Loading…
Reference in New Issue