diff --git a/Module.php b/Module.php index 0910944..24d8645 100644 --- a/Module.php +++ b/Module.php @@ -9,10 +9,11 @@ class Module extends AbstractModule { const NAMESPACE = __NAMESPACE__; - const RATIOS = [ - '1.777' => '16:9', - '1.333' => '4:3', - '2' => '2:1', + const MODEL_WIDTH = [ + '25' => '25 %', + '50' => '50 %', + '75' => '75 %', + '100' => '100 %', ]; public function getConfig() diff --git a/asset/js/height_calculator.js b/asset/js/height_calculator.js new file mode 100644 index 0000000..1411939 --- /dev/null +++ b/asset/js/height_calculator.js @@ -0,0 +1,4 @@ +function get_height(container, ratio) { + var height = $(container).width() / ratio + return height +} diff --git a/config/module.config.php b/config/module.config.php index c8d1953..ad259de 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -31,8 +31,7 @@ return [ 'SketchfabBlockForm' => [ 'title' => '', 'renderSourceLink' => true, - 'width' => 600, - 'ratio' => '2', + 'width' => 100, 'wrapStyle' => 'overflow-y: hidden;display: flex;flex-direction: column;justify-content: center;', ] ] diff --git a/src/Form/SketchfabBlockForm.php b/src/Form/SketchfabBlockForm.php index 9df3b48..b3f54da 100644 --- a/src/Form/SketchfabBlockForm.php +++ b/src/Form/SketchfabBlockForm.php @@ -12,13 +12,11 @@ class SketchfabBlockForm extends Form $this->add([ 'name' => 'o:block[__blockIndex__][o:data][width]', - 'type' => Element\Number::class, - 'options' => [ - 'label' => 'Width in pixels', - ], - 'attributes' => [ - 'min' => '100', - ], + 'type' => Element\Select::class, + 'options' => [ + 'label' => 'Width', + 'value_options' => Module::MODEL_WIDTH, + ], ]); $this->add([ diff --git a/src/Site/BlockLayout/Sketchfab.php b/src/Site/BlockLayout/Sketchfab.php index 44d56c1..55ab815 100644 --- a/src/Site/BlockLayout/Sketchfab.php +++ b/src/Site/BlockLayout/Sketchfab.php @@ -49,7 +49,6 @@ class Sketchfab 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(); @@ -75,15 +74,18 @@ class Sketchfab extends AbstractBlockLayout static $id = 0; $media = $attachments[0]->item()->media()[0]; - $width = 900; - //$height = $width / $block->dataValue('ratio'); - $height = $width / 1.333; + $media = $attachments[0]->item()->media()[0]; + $sketchfab_width = $media->mediaData()['width']; + $sketchfab_height = $media->mediaData()['height']; + $ratio = $sketchfab_width / $sketchfab_height; + return $view->partial('common/block-layout/sketchfab', [ 'title' => $block->dataValue('title'), + 'model_id' => $block->dataValue('identifier'), 'renderSourceLink' => $block->dataValue('renderSourceLink'), 'item_url' => $attachments[0]->item()->url(), - 'width' => $width, - 'height' => $height, + 'width' => $block->dataValue('width'), + 'ratio' => $ratio, 'sketchfab_iframe' => $media->mediaData()['html'], ]); } diff --git a/view/common/block-layout/sketchfab.phtml b/view/common/block-layout/sketchfab.phtml index c05670b..d5275f9 100644 --- a/view/common/block-layout/sketchfab.phtml +++ b/view/common/block-layout/sketchfab.phtml @@ -1,4 +1,9 @@ -
+headScript()->appendFile($this->assetUrl('js/height_calculator.js', + 'Sketchfab')); +?> + +