| 1 |
<?php |
| 2 |
|
| 3 |
namespace ABlocks\Blocks\Modal; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
use ABlocks\Classes\BlockBaseAbstract; |
| 10 |
use ABlocks\Classes\CssGenerator; |
| 11 |
use ABlocks\Controls\Range; |
| 12 |
use ABlocks\Controls\Dimensions; |
| 13 |
use ABlocks\Controls\Background; |
| 14 |
use ABlocks\Controls\BoxShadow; |
| 15 |
use ABlocks\Controls\Border; |
| 16 |
|
| 17 |
|
| 18 |
class Block extends BlockBaseAbstract { |
| 19 |
|
| 20 |
protected $block_name = 'modal'; |
| 21 |
|
| 22 |
public function build_css( $attributes ) { |
| 23 |
$css_generator = new CssGenerator( $attributes ); |
| 24 |
if ( ! empty( $attributes['popupPosition'] ) && 'popup' === $attributes['popupPosition'] && ! empty( $attributes['popupTopOffset'] ) ) { |
| 25 |
$css_generator->add_class_styles( |
| 26 |
'{{WRAPPER}}.ablocks-block-modal-position--popup .ablocks-block-modal---panel-wrap .ablocks-modal-popup-content-wrap', |
| 27 |
[ 'margin-top' => $attributes['popupTopOffset'] . 'px' ] |
| 28 |
); |
| 29 |
} |
| 30 |
$css_generator->add_class_styles( |
| 31 |
'{{WRAPPER}} .ablocks-block-modal---panel-wrap.ablocks-block-modal---panel-wrap', |
| 32 |
$this->get_panel_main_wrapper_css( $attributes ), |
| 33 |
$this->get_panel_main_wrapper_css( $attributes, 'Tablet' ), |
| 34 |
$this->get_panel_main_wrapper_css( $attributes, 'Mobile' ) |
| 35 |
); |
| 36 |
$css_generator->add_class_styles( |
| 37 |
'{{WRAPPER}} .ablocks-block-modal---panel-wrap.ablocks-block-modal---panel-wrap .ablocks-modal-popup-content-wrap', |
| 38 |
$this->get_panel_content_wrap_css( $attributes ), |
| 39 |
$this->get_panel_content_wrap_css( $attributes, 'Tablet' ), |
| 40 |
$this->get_panel_content_wrap_css( $attributes, 'Mobile' ) |
| 41 |
); |
| 42 |
$css_generator->add_class_styles( |
| 43 |
'{{WRAPPER}} .ablocks-block-modal---panel-wrap.ablocks-block-modal---panel-wrap .ablocks-modal-popup-content-wrap:hover', |
| 44 |
$this->get_panel_content_wrap_hover_css( $attributes ), |
| 45 |
$this->get_panel_content_wrap_hover_css( $attributes, 'Tablet' ), |
| 46 |
$this->get_panel_content_wrap_hover_css( $attributes, 'Mobile' ) |
| 47 |
); |
| 48 |
if ( empty( $attributes['disableCloseButton'] ) ) { |
| 49 |
$css_generator->add_class_styles( |
| 50 |
'{{WRAPPER}} .ablocks-block-modal---panel-wrap.ablocks-block-modal---panel-wrap.ablocks-block-modal---panel-wrap.ablocks-block-modal---panel-wrap.ablocks-block-modal---panel-wrap .ablocks-modal-popup-close', |
| 51 |
$this->get_panel_close_button_css( $attributes ), |
| 52 |
$this->get_panel_close_button_css( $attributes, 'Tablet' ), |
| 53 |
$this->get_panel_close_button_css( $attributes, 'Mobile' ) |
| 54 |
); |
| 55 |
|
| 56 |
if ( ! empty( $attributes['closeBtnColor'] ) ) { |
| 57 |
$css_generator->add_class_styles( |
| 58 |
'{{WRAPPER}} .ablocks-block-modal---panel-wrap.ablocks-block-modal---panel-wrap .ablocks-modal-popup-close svg', |
| 59 |
[ 'fill' => $attributes['closeBtnColor'] ] |
| 60 |
); |
| 61 |
} |
| 62 |
} |
| 63 |
return $css_generator->generate_css(); |
| 64 |
} |
| 65 |
|
| 66 |
public function get_panel_main_wrapper_css( $attributes, $device = '' ) { |
| 67 |
if ( ! empty( $device ) ) { |
| 68 |
return []; |
| 69 |
} |
| 70 |
$css = []; |
| 71 |
$backdrop_color = ! empty( $attributes['backdropColor'] ) ? $attributes['backdropColor'] : ''; |
| 72 |
if ( $backdrop_color ) { |
| 73 |
$css['background-color'] = $backdrop_color; |
| 74 |
} |
| 75 |
return $css; |
| 76 |
} |
| 77 |
|
| 78 |
public function get_panel_content_wrap_css( $attributes, $device = '' ) { |
| 79 |
$css = []; |
| 80 |
|
| 81 |
if ( empty( $device ) && ! empty( $attributes['panelContentPosition'] ) ) { |
| 82 |
$css['align-items'] = $attributes['panelContentPosition']; |
| 83 |
} |
| 84 |
|
| 85 |
$Background_css = Background::get_css( $attributes['panelBackground'], 'background', $device ); |
| 86 |
$Border_css = Border::get_css( $attributes['panelBorder'], '', $device ); |
| 87 |
$BoxShadow_css = BoxShadow::get_css( $attributes['panelShadow'], 'box-shadow' ); |
| 88 |
|
| 89 |
$transition_css = []; |
| 90 |
if ( ! $device ) { |
| 91 |
$transition_value = 'all 1s'; |
| 92 |
if ( ! empty( $Background_css['transition'] ) ) { |
| 93 |
$transition_value = $transition_value . ',' . $Background_css['transition']; |
| 94 |
} |
| 95 |
if ( ! empty( $Border_css['transition'] ) ) { |
| 96 |
$transition_value = $transition_value . ',' . $Border_css['transition']; |
| 97 |
} |
| 98 |
if ( ! empty( $BoxShadow_css['transition'] ) ) { |
| 99 |
$transition_value = $transition_value . ',' . $BoxShadow_css['transition']; |
| 100 |
} |
| 101 |
$transition_css['transition'] = $transition_value; |
| 102 |
} |
| 103 |
|
| 104 |
return array_merge( |
| 105 |
Range::get_css([ |
| 106 |
'attributeValue' => $attributes['panelWidth'], |
| 107 |
'attribute_object_key' => 'value', |
| 108 |
'isResponsive' => true, |
| 109 |
'hasUnit' => true, |
| 110 |
'defaultValue' => '', |
| 111 |
'hasUnit' => true, |
| 112 |
'unitDefaultValue' => 'px', |
| 113 |
'property' => 'width', |
| 114 |
'device' => $device, |
| 115 |
]), |
| 116 |
Range::get_css([ |
| 117 |
'attributeValue' => $attributes['panelHeight'], |
| 118 |
'attribute_object_key' => 'value', |
| 119 |
'isResponsive' => true, |
| 120 |
'hasUnit' => true, |
| 121 |
'defaultValue' => '', |
| 122 |
'hasUnit' => true, |
| 123 |
'unitDefaultValue' => 'px', |
| 124 |
'property' => 'min-height', |
| 125 |
'device' => $device, |
| 126 |
]), |
| 127 |
isset( $attributes['barBorder'] ) ? Border::get_css( $attributes['barBorder'], '', $device ) : [], |
| 128 |
$css, |
| 129 |
$css, |
| 130 |
Dimensions::get_css( $attributes['panelPadding'], 'padding', $device ), |
| 131 |
$Background_css, |
| 132 |
$Border_css, |
| 133 |
$BoxShadow_css, |
| 134 |
$transition_css, |
| 135 |
); |
| 136 |
} |
| 137 |
|
| 138 |
public function get_panel_content_wrap_hover_css( $attributes, $device = '' ) { |
| 139 |
$css = []; |
| 140 |
return array_merge( |
| 141 |
$css, |
| 142 |
Dimensions::get_css( $attributes['panelPadding'], 'padding', $device ), |
| 143 |
Background::get_hover_css( $attributes['panelBackground'], 'background', $device ), |
| 144 |
Border::get_hover_css( $attributes['panelBorder'], $device ), |
| 145 |
BoxShadow::get_hover_css( $attributes['panelShadow'] ), |
| 146 |
); |
| 147 |
} |
| 148 |
|
| 149 |
public function get_panel_close_button_css( $attributes, $device = '' ) { |
| 150 |
$css = []; |
| 151 |
if ( empty( $device ) ) { |
| 152 |
if ( ! empty( $attributes['closeBtnBackgroundColor'] ) ) { |
| 153 |
$css['background-color'] = $attributes['closeBtnBackgroundColor']; |
| 154 |
} |
| 155 |
if ( ! empty( $attributes['closeBtnTop'] ) || 0 === $attributes['closeBtnTop'] ) { |
| 156 |
$css['top'] = $attributes['closeBtnTop'] . 'px'; |
| 157 |
} |
| 158 |
if ( ! empty( $attributes['closeBtnSide'] ) || 0 === $attributes['closeBtnSide'] ) { |
| 159 |
if ( 'left' === $attributes['closePosition'] ) { |
| 160 |
$css['left'] = $attributes['closeBtnSide'] . 'px'; |
| 161 |
$css['right'] = 'unset'; |
| 162 |
} else { |
| 163 |
$css['right'] = $attributes['closeBtnSide'] . 'px'; |
| 164 |
$css['left'] = 'unset'; |
| 165 |
} |
| 166 |
} |
| 167 |
} |
| 168 |
return $css; |
| 169 |
} |
| 170 |
} |
| 171 |
|