Compare commits
3 Commits
34713d9acb
...
267d382535
Author | SHA1 | Date |
---|---|---|
buttle | 267d382535 | |
buttle | a7ad58b452 | |
buttle | 5ccd8cb174 |
|
@ -1,4 +0,0 @@
|
|||
function get_height(container, ratio) {
|
||||
var height = $(container).width() / ratio
|
||||
return height
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
function adjust_vimeo_height() {
|
||||
$(".embeded-vimeo-wrapper").each(function() {
|
||||
var iframe = $(this).find('iframe')
|
||||
var height = $(iframe).width() / $(iframe).attr('ratio')
|
||||
$(iframe).prop("height", height)
|
||||
});
|
||||
}
|
||||
|
||||
jQuery(document).ready(function() {
|
||||
adjust_vimeo_height();
|
||||
});
|
||||
|
||||
$(window).resize(function() {
|
||||
adjust_vimeo_height();
|
||||
});
|
|
@ -32,7 +32,6 @@ return [
|
|||
'title' => '',
|
||||
'renderSourceLink' => true,
|
||||
'width' => 100,
|
||||
'ratio' => '2',
|
||||
'wrapStyle' => 'overflow-y: hidden;display: flex;flex-direction: column;justify-content: center;',
|
||||
]
|
||||
]
|
||||
|
|
|
@ -17,11 +17,6 @@ class VimeoBlockForm extends Form
|
|||
'label' => 'Width',
|
||||
'value_options' => Module::IMAGE_WIDTH,
|
||||
],
|
||||
/*
|
||||
'attributes' => [
|
||||
'min' => '100',
|
||||
],
|
||||
*/
|
||||
]);
|
||||
|
||||
$this->add([
|
||||
|
|
|
@ -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 = "<iframe ".$attribs." >".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
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
$this->headScript()->appendFile($this->assetUrl('js/height_calculator.js',
|
||||
$this->headScript()->appendFile($this->assetUrl('js/media_dimensions.js',
|
||||
'Vimeo'));
|
||||
?>
|
||||
|
||||
<div class="vimeo-embed-wrapper"
|
||||
<div class="embeded-vimeo-wrapper"
|
||||
style="position:relative;">
|
||||
|
||||
<?php if ($renderSourceLink) { ?>
|
||||
|
@ -23,17 +23,5 @@ $this->headScript()->appendFile($this->assetUrl('js/height_calculator.js',
|
|||
</div>
|
||||
|
||||
<script>
|
||||
function adjust_height() {
|
||||
$(".vimeo-embed-wrapper").each(function() {
|
||||
var iframe = $(this).find('iframe')
|
||||
var ratio = $(iframe).attr('ratio')
|
||||
$(iframe).prop("height", get_height(iframe, ratio))
|
||||
});
|
||||
}
|
||||
jQuery(document).ready(function() {
|
||||
adjust_height();
|
||||
});
|
||||
$( window ).resize(function() {
|
||||
adjust_height();
|
||||
});
|
||||
|
||||
</script>
|
||||
|
|
Loading…
Reference in New Issue