From a7ad58b4529fe94130699d3aa1ec3e5230bbef27 Mon Sep 17 00:00:00 2001 From: buttle Date: Mon, 30 Aug 2021 18:38:04 +0200 Subject: [PATCH] fixes multiple script rendering --- asset/js/height_calculator.js | 4 ---- asset/js/media_dimensions.js | 20 ++++++++++++++++++++ view/common/block-layout/vimeo.phtml | 18 +++--------------- 3 files changed, 23 insertions(+), 19 deletions(-) delete mode 100644 asset/js/height_calculator.js create mode 100644 asset/js/media_dimensions.js diff --git a/asset/js/height_calculator.js b/asset/js/height_calculator.js deleted file mode 100644 index 1411939..0000000 --- a/asset/js/height_calculator.js +++ /dev/null @@ -1,4 +0,0 @@ -function get_height(container, ratio) { - var height = $(container).width() / ratio - return height -} diff --git a/asset/js/media_dimensions.js b/asset/js/media_dimensions.js new file mode 100644 index 0000000..48793d2 --- /dev/null +++ b/asset/js/media_dimensions.js @@ -0,0 +1,20 @@ +function get_height(container, ratio) { + var height = $(container).width() / ratio + return height +} + +function adjust_height() { + $(".embeded-vimeo-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(); +}); diff --git a/view/common/block-layout/vimeo.phtml b/view/common/block-layout/vimeo.phtml index 369f5ee..d7de0d4 100644 --- a/view/common/block-layout/vimeo.phtml +++ b/view/common/block-layout/vimeo.phtml @@ -1,9 +1,9 @@ headScript()->appendFile($this->assetUrl('js/height_calculator.js', +$this->headScript()->appendFile($this->assetUrl('js/media_dimensions.js', 'Vimeo')); ?> -
@@ -23,17 +23,5 @@ $this->headScript()->appendFile($this->assetUrl('js/height_calculator.js',