iframe width is modified to respect user defined width

fixes: #1
This commit is contained in:
buttle 2021-08-28 15:14:24 +02:00
parent d240f86d70
commit ce9dbd0bb3
2 changed files with 15 additions and 6 deletions

View File

@ -72,6 +72,7 @@ class Sketchfab extends AbstractBlockLayout
$thumbnails = []; $thumbnails = [];
static $id = 0; static $id = 0;
$id = $id +1;
$media = $attachments[0]->item()->media()[0]; $media = $attachments[0]->item()->media()[0];
$media = $attachments[0]->item()->media()[0]; $media = $attachments[0]->item()->media()[0];
@ -81,7 +82,8 @@ class Sketchfab extends AbstractBlockLayout
return $view->partial('common/block-layout/sketchfab', [ return $view->partial('common/block-layout/sketchfab', [
'title' => $block->dataValue('title'), 'title' => $block->dataValue('title'),
'model_id' => $block->dataValue('identifier'), //'model_id' => $block->dataValue('identifier'),
'model_id' => $id,
'renderSourceLink' => $block->dataValue('renderSourceLink'), 'renderSourceLink' => $block->dataValue('renderSourceLink'),
'item_url' => $attachments[0]->item()->url(), 'item_url' => $attachments[0]->item()->url(),
'width' => $block->dataValue('width'), 'width' => $block->dataValue('width'),

View File

@ -21,12 +21,19 @@ $this->headScript()->appendFile($this->assetUrl('js/height_calculator.js',
</div> </div>
<script> <script>
jQuery(document).ready(function() { function adjust_height() {
var sketchfab = $("#sketchfab_<?= $model_id ?>").find('iframe'); $(".sketchfab-embed-wrapper").each(function() {
var sketchfab = $(this).find('iframe')
$(sketchfab).prop("width", "<?= $width ?>%") $(sketchfab).prop("width", "<?= $width ?>%")
var height = get_height(sketchfab, <?= $ratio ?>) var height = get_height(sketchfab, <?= $ratio ?>)
$(sketchfab).prop("height", height) $(sketchfab).prop("height", height)
});
}
jQuery(document).ready(function() {
adjust_height();
});
$( window ).resize(function() {
adjust_height();
}); });
</script> </script>