From 5ccd8cb174c7e2cab89c2d1e8d6ae7f1eb0abd7f Mon Sep 17 00:00:00 2001 From: buttle Date: Mon, 30 Aug 2021 18:14:25 +0200 Subject: [PATCH] respects user defined widths --- config/module.config.php | 1 - src/Form/VimeoBlockForm.php | 5 ----- src/Site/BlockLayout/Vimeo.php | 22 +++++----------------- view/common/block-layout/vimeo.phtml | 4 ++-- 4 files changed, 7 insertions(+), 25 deletions(-) diff --git a/config/module.config.php b/config/module.config.php index 802147e..f120f76 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -32,7 +32,6 @@ return [ 'title' => '', 'renderSourceLink' => true, 'width' => 100, - 'ratio' => '2', 'wrapStyle' => 'overflow-y: hidden;display: flex;flex-direction: column;justify-content: center;', ] ] diff --git a/src/Form/VimeoBlockForm.php b/src/Form/VimeoBlockForm.php index 2ecec5a..22de305 100644 --- a/src/Form/VimeoBlockForm.php +++ b/src/Form/VimeoBlockForm.php @@ -17,11 +17,6 @@ class VimeoBlockForm extends Form 'label' => 'Width', 'value_options' => Module::IMAGE_WIDTH, ], - /* - 'attributes' => [ - 'min' => '100', - ], - */ ]); $this->add([ diff --git a/src/Site/BlockLayout/Vimeo.php b/src/Site/BlockLayout/Vimeo.php index 8561185..e00f182 100644 --- a/src/Site/BlockLayout/Vimeo.php +++ b/src/Site/BlockLayout/Vimeo.php @@ -49,7 +49,6 @@ class Vimeo extends AbstractBlockLayout $form->setData([ 'o:block[__blockIndex__][o:data][title]' => $data['title'], 'o:block[__blockIndex__][o:data][width]' => $data['width'], - 'o:block[__blockIndex__][o:data][ratio]' => $data['ratio'], 'o:block[__blockIndex__][o:data][renderSourceLink]' => $data['renderSourceLink'], ]); $form->prepare(); @@ -71,14 +70,10 @@ class Vimeo extends AbstractBlockLayout return ''; } $media = $attachments[0]->item()->media()[0]; - $width = $media->mediaData()['width']; - $width = 100; - $height = 0; + $ratio = $media->mediaData()['width'] / $media->mediaData()['height']; - // creates an iframe injecting our width and calculated ratio and height - $attribs=" "; - $original_width = 0; - $original_height = 0; + // creates an iframe injecting our width and calculated ratio + $attribs= 'ratio="'.$ratio.'"'.PHP_EOL; $doc = new DOMDocument(); $doc->loadHTML($media->mediaData()['html']); $html_element= $doc->getElementsByTagName('iframe')->item(0); @@ -87,12 +82,11 @@ class Vimeo extends AbstractBlockLayout $name = $attr->nodeName; $value = $attr->nodeValue; if ($name == 'height') { - $original_height = $value; + // we will calculate height with jQuery continue; } if ($name == 'width') { - $original_width = $value; - $attrib = $name.'="'.$width.'%"'; + $attrib = 'width="'.$block->dataValue('width').'%"'; $attribs .= $attrib.PHP_EOL; continue; } @@ -100,18 +94,12 @@ class Vimeo extends AbstractBlockLayout $attribs .= $attrib.PHP_EOL; } } - if ($original_height !== 0) { - $ratio = $original_width / $original_height; - $attrib = 'ratio="'.$ratio.'"'; - $attribs .= $attrib.PHP_EOL; - } $iframe = ""; 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 ]); } diff --git a/view/common/block-layout/vimeo.phtml b/view/common/block-layout/vimeo.phtml index 86b1d20..369f5ee 100644 --- a/view/common/block-layout/vimeo.phtml +++ b/view/common/block-layout/vimeo.phtml @@ -3,7 +3,7 @@ $this->headScript()->appendFile($this->assetUrl('js/height_calculator.js', 'Vimeo')); ?> -
@@ -24,7 +24,7 @@ $this->headScript()->appendFile($this->assetUrl('js/height_calculator.js',