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\View\Renderer\PhpRenderer;
|
||||||
|
|
||||||
use Laminas\Form\FormElementManager;
|
use Laminas\Form\FormElementManager;
|
||||||
|
|
||||||
use Vimeo\Form\VimeoBlockForm;
|
use Vimeo\Form\VimeoBlockForm;
|
||||||
|
use DOMDocument;
|
||||||
|
|
||||||
class Vimeo extends AbstractBlockLayout
|
class Vimeo extends AbstractBlockLayout
|
||||||
{
|
{
|
||||||
|
@ -66,27 +66,53 @@ class Vimeo extends AbstractBlockLayout
|
||||||
|
|
||||||
public function render(PhpRenderer $view, SitePageBlockRepresentation $block)
|
public function render(PhpRenderer $view, SitePageBlockRepresentation $block)
|
||||||
{
|
{
|
||||||
$attachments = $block->attachments();
|
$attachments = $block->attachments();
|
||||||
if (!$attachments) {
|
if (!$attachments) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
$media = $attachments[0]->item()->media()[0];
|
||||||
|
$width = $media->mediaData()['width'];
|
||||||
|
$width = 100;
|
||||||
|
$height = 0;
|
||||||
|
|
||||||
$thumbnails = [];
|
// creates an iframe injecting our width and calculated ratio and height
|
||||||
static $id = 0;
|
$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];
|
return $view->partial('common/block-layout/vimeo', [
|
||||||
$vimeo_width = $media->mediaData()['width'];
|
'title' => $block->dataValue('title'),
|
||||||
$vimeo_height = $media->mediaData()['height'];
|
'renderSourceLink' => $block->dataValue('renderSourceLink'),
|
||||||
$ratio = $vimeo_width / $vimeo_height;
|
'item_url' => $attachments[0]->item()->url(),
|
||||||
|
'ratio' => $ratio,
|
||||||
return $view->partial('common/block-layout/vimeo', [
|
'vimeo_iframe' => $iframe
|
||||||
'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'],
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -3,7 +3,8 @@ $this->headScript()->appendFile($this->assetUrl('js/height_calculator.js',
|
||||||
'Vimeo'));
|
'Vimeo'));
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<div id="vimeo_<?= $video_id ?>" class="vimeo-embed-wrapper" style="position:relative;">
|
<div class="vimeo-embed-wrapper"
|
||||||
|
style="position:relative;">
|
||||||
|
|
||||||
<?php if ($renderSourceLink) { ?>
|
<?php if ($renderSourceLink) { ?>
|
||||||
<div class="source-link">
|
<div class="source-link">
|
||||||
|
@ -25,9 +26,8 @@ $this->headScript()->appendFile($this->assetUrl('js/height_calculator.js',
|
||||||
function adjust_height() {
|
function adjust_height() {
|
||||||
$(".vimeo-embed-wrapper").each(function() {
|
$(".vimeo-embed-wrapper").each(function() {
|
||||||
var iframe = $(this).find('iframe')
|
var iframe = $(this).find('iframe')
|
||||||
$(iframe).prop("width", "<?= $width ?>%")
|
var ratio = $(iframe).attr('ratio')
|
||||||
var height = get_height(iframe, <?= $ratio ?>)
|
$(iframe).prop("height", get_height(iframe, ratio))
|
||||||
$(iframe).prop("height", height)
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
jQuery(document).ready(function() {
|
jQuery(document).ready(function() {
|
||||||
|
|
Loading…
Reference in New Issue