| @@ -1,0 +1,69 @@ | ||
| 1 | +<?php | |
| 2 | +namespace ABlocks\Blocks\MenuChildMega; | |
| 3 | + | |
| 4 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 5 | + exit; | |
| 6 | +} | |
| 7 | + | |
| 8 | +use ABlocks\Classes\BlockBaseAbstract; | |
| 9 | +use ABlocks\Classes\CssGenerator; | |
| 10 | +use ABlocks\Controls\Range; | |
| 11 | + | |
| 12 | +class Block extends BlockBaseAbstract { | |
| 13 | + protected $parent_block_name = 'menu'; | |
| 14 | + protected $block_name = 'menu-child-mega'; | |
| 15 | + | |
| 16 | + public function build_css( $attributes ) { | |
| 17 | + | |
| 18 | + $css_generator = new CssGenerator( $attributes, $this->block_name ); | |
| 19 | + // Wrapper CSS | |
| 20 | + $css_generator->add_class_styles( | |
| 21 | + '{{WRAPPER}}', | |
| 22 | + $this->get_wrapper_css( $attributes, '' ), | |
| 23 | + $this->get_wrapper_css( $attributes, 'Tablet' ), | |
| 24 | + $this->get_wrapper_css( $attributes, 'Mobile' ), | |
| 25 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_wrapper_css( $attributes, $device ); } ) | |
| 26 | + ); | |
| 27 | + return $css_generator->generate_css(); | |
| 28 | + } | |
| 29 | + private function get_wrapper_css( $attributes, $device = '' ) { | |
| 30 | + $css = []; | |
| 31 | + $padding = isset( $attributes['padding'] ) ? $attributes['padding'] : ''; | |
| 32 | + if ( isset( $attributes['height'] ) && $attributes['height'] > 0 ) { | |
| 33 | + $css['overflow-y'] = 'auto'; | |
| 34 | + $css['overflow-x'] = 'hidden'; | |
| 35 | + } | |
| 36 | + return array_merge( | |
| 37 | + Range::get_css([ | |
| 38 | + 'attributeValue' => $attributes['width'], | |
| 39 | + 'attribute_object_key' => 'value', | |
| 40 | + 'isResponsive' => true, | |
| 41 | + 'defaultValue' => 100, | |
| 42 | + 'hasUnit' => true, | |
| 43 | + 'unitDefaultValue' => '%', | |
| 44 | + 'property' => 'width', | |
| 45 | + 'device' => $device, | |
| 46 | + ]), | |
| 47 | + Range::get_css([ | |
| 48 | + 'attributeValue' => $attributes['height'], | |
| 49 | + 'attribute_object_key' => 'value', | |
| 50 | + 'isResponsive' => true, | |
| 51 | + 'hasUnit' => true, | |
| 52 | + 'unitDefaultValue' => 'px', | |
| 53 | + 'property' => 'height', | |
| 54 | + 'device' => $device, | |
| 55 | + ]), | |
| 56 | + Range::get_css([ | |
| 57 | + 'attributeValue' => $attributes['positionX'], | |
| 58 | + 'attribute_object_key' => 'value', | |
| 59 | + 'isResponsive' => true, | |
| 60 | + 'defaultValue' => 0, | |
| 61 | + 'property' => 'left', | |
| 62 | + 'unitDefaultValue' => '%', | |
| 63 | + 'hasUnit' => true, | |
| 64 | + 'device' => $device, | |
| 65 | + ]), | |
| 66 | + $css | |
| 67 | + ); | |
| 68 | + } | |
| 69 | +} | |