| @@ -1,15 +1,20 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace ABlocks\Blocks\Video; |
| 3 | 3 | |
| 4 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 5 | + exit; | |
| 6 | +} | |
| 7 | + | |
| 4 | 8 | use ABlocks\Classes\BlockBaseAbstract; |
| 5 | 9 | use ABlocks\Classes\CssGenerator; |
| 10 | +use ABlocks\Classes\CssGeneratorV2; | |
| 6 | 11 | use ABlocks\Controls\CssFilter; |
| 7 | 12 | |
| 8 | 13 | class Block extends BlockBaseAbstract { |
| 9 | 14 | protected $block_name = 'video'; |
| 10 | 15 | |
| 11 | - public function build_css( $attributes ) { | |
| 16 | + public function build_css_v1( $attributes ) { | |
| 12 | 17 | |
| 13 | 18 | // Generate CSS start |
| 14 | 19 | $css_generator = new CssGenerator( $attributes, $this->block_name ); |
| 15 | 20 | |
| @@ -23,9 +28,32 @@ | ||
| 23 | 28 | |
| 24 | 29 | return $css_generator->generate_css(); |
| 25 | 30 | // Generate CSS end |
| 26 | 31 | } |
| 32 | + public function build_css_v2( $attributes ) { | |
| 27 | 33 | |
| 34 | + // Generate CSS start | |
| 35 | + $css_generator = new CssGeneratorV2( $attributes, $this->block_name ); | |
| 36 | + | |
| 37 | + // Video Container CSS | |
| 38 | + $css_generator->add_class_styles( | |
| 39 | + '{{WRAPPER}}', | |
| 40 | + $this->get_video_container_css( $attributes ), | |
| 41 | + $this->get_video_container_css( $attributes, 'Tablet' ), | |
| 42 | + $this->get_video_container_css( $attributes, 'Mobile' ), | |
| 43 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_video_container_css( $attributes, $device ); } ) | |
| 44 | + ); | |
| 45 | + | |
| 46 | + return $css_generator->generate_css(); | |
| 47 | + // Generate CSS end | |
| 48 | + } | |
| 49 | + | |
| 50 | + public function build_css( $attributes ) { | |
| 51 | + if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) { | |
| 52 | + return $this->build_css_v2( $attributes ); | |
| 53 | + } | |
| 54 | + return $this->build_css_v1( $attributes ); | |
| 55 | + } | |
| 28 | 56 | public function get_video_container_css( $attributes, $device = '' ) { |
| 29 | 57 | $css = []; |
| 30 | 58 | if ( ! empty( $attributes['aspectRatio'] ) ) { |
| 31 | 59 | $css['aspect-ratio'] = $attributes['aspectRatio']; |