| 1 |
<?php |
| 2 |
namespace ABlocks\Blocks\ImageHotspotChild; |
| 3 |
|
| 4 |
use ABlocks\Controls\Border; |
| 5 |
use ABlocks\Controls\Dimensions; |
| 6 |
use ABlocks\Controls\Range; |
| 7 |
use ABlocks\Classes\BlockBaseAbstract; |
| 8 |
use ABlocks\Classes\CssGenerator; |
| 9 |
|
| 10 |
class Block extends BlockBaseAbstract { |
| 11 |
protected $parent_block_name = 'image-hotspot'; |
| 12 |
protected $block_name = 'image-hotspot-child'; |
| 13 |
|
| 14 |
public function build_css( $attributes ) { |
| 15 |
$css_generator = new CssGenerator( $attributes ); |
| 16 |
|
| 17 |
$css_generator->add_class_styles( |
| 18 |
'{{WRAPPER}} .ablocks-image-hotspot__tooltip--active', |
| 19 |
$this->get_active_content_css( $attributes ), |
| 20 |
$this->get_active_content_css( $attributes, 'Tablet' ), |
| 21 |
$this->get_active_content_css( $attributes, 'Mobile' ) |
| 22 |
); |
| 23 |
|
| 24 |
$css_generator->add_class_styles( |
| 25 |
'{{WRAPPER}} .ablocks-image-hotspot__tooltip--active:hover', |
| 26 |
$this->get_active_content_hover_css( $attributes ), |
| 27 |
$this->get_active_content_hover_css( $attributes, 'Tablet' ), |
| 28 |
$this->get_active_content_hover_css( $attributes, 'Mobile' ) |
| 29 |
); |
| 30 |
|
| 31 |
return $css_generator->generate_css(); |
| 32 |
} |
| 33 |
|
| 34 |
public function get_active_content_css( $attributes, $device = '' ) { |
| 35 |
$css = array(); |
| 36 |
|
| 37 |
// Set background color |
| 38 |
if ( ! empty( $attributes['backgroundColor'] ) ) { |
| 39 |
$css['background-color'] = $attributes['backgroundColor']; |
| 40 |
} |
| 41 |
|
| 42 |
// Add border and padding styles |
| 43 |
$border_css = isset( $attributes['contentBorder'] ) ? Border::get_css( $attributes['contentBorder'], '', $device ) : []; |
| 44 |
$padding_css = isset( $attributes['contentPadding'] ) ? Dimensions::get_css( $attributes['contentPadding'], 'padding', $device ) : []; |
| 45 |
|
| 46 |
// Merge border and padding styles with the main CSS |
| 47 |
$css = array_merge( $css, $border_css, $padding_css, |
| 48 |
Range::get_css( |
| 49 |
[ |
| 50 |
'attributeValue' => $attributes['contentWidth'], |
| 51 |
'attribute_object_key' => 'value', |
| 52 |
'isResponsive' => true, |
| 53 |
'defaultValue' => '', |
| 54 |
'hasUnit' => true, |
| 55 |
'unitDefaultValue' => 'px', |
| 56 |
'property' => 'width', |
| 57 |
'device' => $device, |
| 58 |
] |
| 59 |
) |
| 60 |
); |
| 61 |
|
| 62 |
return $css; |
| 63 |
} |
| 64 |
|
| 65 |
public function get_active_content_hover_css( $attributes, $device = '' ) { |
| 66 |
$css = []; |
| 67 |
|
| 68 |
$border_hover_css = isset( $attributes['contentBorder'] ) ? Border::get_hover_css( $attributes['contentBorder'], $device ) : []; |
| 69 |
|
| 70 |
$css = array_merge( $css, $border_hover_css ); |
| 71 |
|
| 72 |
return $css; |
| 73 |
} |
| 74 |
} |
| 75 |
|