| 1 |
<?php |
| 2 |
namespace ABlocks\Blocks\ImageComparison; |
| 3 |
|
| 4 |
use ABlocks\Classes\BlockBaseAbstract; |
| 5 |
use ABlocks\Classes\CssGenerator; |
| 6 |
use ABlocks\Controls\Alignment; |
| 7 |
use ABlocks\Controls\Border; |
| 8 |
use ABlocks\Controls\Range; |
| 9 |
|
| 10 |
class Block extends BlockBaseAbstract { |
| 11 |
protected $block_name = 'image-comparison'; |
| 12 |
|
| 13 |
public function build_css( $attributes ) { |
| 14 |
$css_generator = new CssGenerator( $attributes ); |
| 15 |
|
| 16 |
$css_generator->add_class_styles( |
| 17 |
'{{WRAPPER}} .ablocks-image-comparison__images-container .ablocks-image-comparison__before-image', |
| 18 |
$this->get_before_image_width_css( $attributes ) |
| 19 |
); |
| 20 |
|
| 21 |
$css_generator->add_class_styles( |
| 22 |
'{{WRAPPER}} .ablocks-image-comparison__images-container-vertical .ablocks-image-comparison__before-image', |
| 23 |
$this->get_before_image_height_css( $attributes ) |
| 24 |
); |
| 25 |
|
| 26 |
$css_generator->add_class_styles( |
| 27 |
'{{WRAPPER}} .ablocks-image-comparison__images-container .ablocks-image-comparison__slider-line', |
| 28 |
$this->get_slider_line_horizontal_css( $attributes ), |
| 29 |
$this->get_slider_line_horizontal_css( $attributes, 'Tablet' ), |
| 30 |
$this->get_slider_line_horizontal_css( $attributes, 'Mobile' ) |
| 31 |
); |
| 32 |
|
| 33 |
$css_generator->add_class_styles( |
| 34 |
'{{WRAPPER}} .ablocks-image-comparison__images-container-vertical .ablocks-image-comparison__slider-line', |
| 35 |
$this->get_slider_line_vertical_css( $attributes ), |
| 36 |
$this->get_slider_line_vertical_css( $attributes, 'Tablet' ), |
| 37 |
$this->get_slider_line_vertical_css( $attributes, 'Mobile' ) |
| 38 |
); |
| 39 |
|
| 40 |
$css_generator->add_class_styles( |
| 41 |
'{{WRAPPER}} .ablocks-image-comparison__images-container .ablocks-image-comparison__slider-icon', |
| 42 |
$this->get_horizontal_slider_icon_css( $attributes ), |
| 43 |
$this->get_horizontal_slider_icon_css( $attributes, 'Tablet' ), |
| 44 |
$this->get_horizontal_slider_icon_css( $attributes, 'Mobile' ) |
| 45 |
); |
| 46 |
|
| 47 |
$css_generator->add_class_styles( |
| 48 |
'{{WRAPPER}} .ablocks-image-comparison__images-container-vertical .ablocks-image-comparison__slider-icon', |
| 49 |
$this->get_vertical_slider_icon_css( $attributes ), |
| 50 |
$this->get_vertical_slider_icon_css( $attributes, 'Tablet' ), |
| 51 |
$this->get_vertical_slider_icon_css( $attributes, 'Mobile' ) |
| 52 |
); |
| 53 |
|
| 54 |
$css_generator->add_class_styles( |
| 55 |
'{{WRAPPER}} .ablocks-image-comparison__beforeImage-label', |
| 56 |
$this->get_image_overlay_css( $attributes ), |
| 57 |
$this->get_image_overlay_css( $attributes, 'Tablet' ), |
| 58 |
$this->get_image_overlay_css( $attributes, 'Mobile' ) |
| 59 |
); |
| 60 |
|
| 61 |
$css_generator->add_class_styles( |
| 62 |
'{{WRAPPER}} .ablocks-image-comparison__beforeImage-label:hover', |
| 63 |
$this->get_image_overlay_hover_css( $attributes ), |
| 64 |
$this->get_image_overlay_hover_css( $attributes, 'Tablet' ), |
| 65 |
$this->get_image_overlay_hover_css( $attributes, 'Mobile' ) |
| 66 |
); |
| 67 |
|
| 68 |
$css_generator->add_class_styles( |
| 69 |
'{{WRAPPER}} .ablocks-image-comparison__afterImage-label', |
| 70 |
$this->get_image_overlay_css( $attributes ), |
| 71 |
$this->get_image_overlay_css( $attributes, 'Tablet' ), |
| 72 |
$this->get_image_overlay_css( $attributes, 'Mobile' ) |
| 73 |
); |
| 74 |
|
| 75 |
$css_generator->add_class_styles( |
| 76 |
'{{WRAPPER}} .ablocks-image-comparison__afterImage-label:hover', |
| 77 |
$this->get_image_overlay_hover_css( $attributes ), |
| 78 |
$this->get_image_overlay_hover_css( $attributes, 'Tablet' ), |
| 79 |
$this->get_image_overlay_hover_css( $attributes, 'Mobile' ) |
| 80 |
); |
| 81 |
|
| 82 |
$css_generator->add_class_styles( |
| 83 |
'{{WRAPPER}} .ablocks-image-comparison__overlay', |
| 84 |
$this->get_overlay_css( $attributes ), |
| 85 |
); |
| 86 |
|
| 87 |
$css_generator->add_class_styles( |
| 88 |
'{{WRAPPER}} .ablocks-image-comparison__overlay--hover', |
| 89 |
$this->get_overlay_css( $attributes ), |
| 90 |
); |
| 91 |
|
| 92 |
$css_generator->add_class_styles( |
| 93 |
'{{WRAPPER}} .ablocks-image-comparison__beforeImage-label--horizontal', |
| 94 |
$this->get_before_image_overlay_horizontal_css( $attributes ) |
| 95 |
); |
| 96 |
$css_generator->add_class_styles( |
| 97 |
'{{WRAPPER}} .ablocks-image-comparison__beforeImage-label--vertical', |
| 98 |
$this->get_before_image_overlay_vertical_css( $attributes ) |
| 99 |
); |
| 100 |
$css_generator->add_class_styles( |
| 101 |
'{{WRAPPER}} .ablocks-image-comparison__afterImage-label--horizontal', |
| 102 |
$this->get_after_image_overlay_horizontal_css( $attributes ) |
| 103 |
); |
| 104 |
$css_generator->add_class_styles( |
| 105 |
'{{WRAPPER}} .ablocks-image-comparison__afterImage-label--vertical', |
| 106 |
$this->get_after_image_overlay_vertical_css( $attributes ) |
| 107 |
); |
| 108 |
|
| 109 |
return $css_generator->generate_css(); |
| 110 |
} |
| 111 |
|
| 112 |
public function get_before_image_width_css( $attributes ) { |
| 113 |
$slider_position = isset( $attributes['sliderPosition'] ) ? $attributes['sliderPosition'] : 50; |
| 114 |
return [ 'width' => $slider_position . '%' ]; |
| 115 |
} |
| 116 |
|
| 117 |
public function get_before_image_height_css( $attributes ) { |
| 118 |
$slider_position = isset( $attributes['sliderPosition'] ) ? $attributes['sliderPosition'] : 50; |
| 119 |
return [ 'height' => $slider_position . '%' ]; |
| 120 |
} |
| 121 |
|
| 122 |
public function get_slider_line_horizontal_css( $attributes, $device = '' ) { |
| 123 |
$slider_position = isset( $attributes['sliderPosition'] ) ? $attributes['sliderPosition'] : 50; |
| 124 |
$handle_color = isset( $attributes['handleColor'] ) ? $attributes['handleColor'] : ''; |
| 125 |
$css = []; |
| 126 |
$css['left'] = $slider_position . '%'; |
| 127 |
$css['background'] = $handle_color; |
| 128 |
return array_merge( |
| 129 |
Range::get_css([ |
| 130 |
'attributeValue' => $attributes['sliderBarSize'], |
| 131 |
'attribute_object_key' => 'value', |
| 132 |
'isResponsive' => true, |
| 133 |
'defaultValue' => 4, |
| 134 |
'unitDefaultValue' => 'px', |
| 135 |
'property' => 'width', |
| 136 |
'device' => $device, |
| 137 |
]), |
| 138 |
$css |
| 139 |
); |
| 140 |
|
| 141 |
} |
| 142 |
|
| 143 |
public function get_slider_line_vertical_css( $attributes, $device = '' ) { |
| 144 |
$slider_top = isset( $attributes['sliderPosition'] ) ? $attributes['sliderPosition'] : 50; |
| 145 |
$slider_background = isset( $attributes['handleColor'] ) ? $attributes['handleColor'] : ''; |
| 146 |
|
| 147 |
$css = []; |
| 148 |
$css['top'] = $slider_top . '%'; |
| 149 |
$css['background'] = $slider_background; |
| 150 |
return array_merge( |
| 151 |
Range::get_css([ |
| 152 |
'attributeValue' => $attributes['sliderBarSize'], |
| 153 |
'attribute_object_key' => 'value', |
| 154 |
'isResponsive' => true, |
| 155 |
'defaultValue' => 4, |
| 156 |
'unitDefaultValue' => 'px', |
| 157 |
'property' => 'height', |
| 158 |
'device' => $device, |
| 159 |
]), |
| 160 |
$css, |
| 161 |
); |
| 162 |
} |
| 163 |
|
| 164 |
public function get_horizontal_slider_icon_css( $attributes, $device = '' ) { |
| 165 |
$slider_position = isset( $attributes['sliderPosition'] ) ? $attributes['sliderPosition'] : 50; |
| 166 |
$slider_icon_border_size = isset( $attributes['sliderIconBorderSize'][ 'value' . $device ] ) ? $attributes['sliderIconBorderSize'][ 'value' . $device ] : [ 'value' => 2 ]; |
| 167 |
$handle_color = isset( $attributes['handleColor'] ) ? $attributes['handleColor'] : ''; |
| 168 |
|
| 169 |
$border_size = is_array( $slider_icon_border_size ) && isset( $slider_icon_border_size[ 'value' . $device ] ) |
| 170 |
? $slider_icon_border_size[ 'value' . $device ] |
| 171 |
: ( is_array( $slider_icon_border_size ) ? $slider_icon_border_size['value'] : $slider_icon_border_size ); |
| 172 |
$css = []; |
| 173 |
$css['left'] = $slider_position . '%'; |
| 174 |
$css['border-weight'] = 'solid'; |
| 175 |
$css['border-color'] = $handle_color; |
| 176 |
$css['color'] = $handle_color; |
| 177 |
|
| 178 |
return array_merge( |
| 179 |
Range::get_css([ |
| 180 |
'attributeValue' => $attributes['sliderIconSize'], |
| 181 |
'attribute_object_key' => 'value', |
| 182 |
'isResponsive' => true, |
| 183 |
'defaultValue' => 50, |
| 184 |
'unitDefaultValue' => 'px', |
| 185 |
'property' => 'width', |
| 186 |
'device' => $device, |
| 187 |
]), |
| 188 |
Range::get_css([ |
| 189 |
'attributeValue' => $attributes['sliderIconSize'], |
| 190 |
'attribute_object_key' => 'value', |
| 191 |
'isResponsive' => true, |
| 192 |
'defaultValue' => 50, |
| 193 |
'unitDefaultValue' => 'px', |
| 194 |
'property' => 'height', |
| 195 |
'device' => $device, |
| 196 |
]), |
| 197 |
Range::get_css([ |
| 198 |
'attributeValue' => $attributes['sliderIconBorderSize'], |
| 199 |
'attribute_object_key' => 'value', |
| 200 |
'isResponsive' => true, |
| 201 |
'defaultValue' => 2, |
| 202 |
'unitDefaultValue' => 'px', |
| 203 |
'property' => 'border-width', |
| 204 |
'device' => $device, |
| 205 |
]), |
| 206 |
$css |
| 207 |
); |
| 208 |
} |
| 209 |
|
| 210 |
public function get_vertical_slider_icon_css( $attributes, $device = '' ) { |
| 211 |
$slider_position = isset( $attributes['sliderPosition'] ) ? $attributes['sliderPosition'] : 50; |
| 212 |
$handle_color = isset( $attributes['handleColor'] ) ? $attributes['handleColor'] : ''; |
| 213 |
|
| 214 |
$css = []; |
| 215 |
$css['left'] = $slider_position . '%'; |
| 216 |
$css['border-weight'] = 'solid'; |
| 217 |
$css['border-color'] = $handle_color; |
| 218 |
$css['color'] = $handle_color; |
| 219 |
return array_merge( |
| 220 |
Range::get_css([ |
| 221 |
'attributeValue' => $attributes['sliderIconSize'], |
| 222 |
'attribute_object_key' => 'value', |
| 223 |
'isResponsive' => true, |
| 224 |
'defaultValue' => 50, |
| 225 |
'unitDefaultValue' => 'px', |
| 226 |
'property' => 'width', |
| 227 |
'device' => $device, |
| 228 |
]), |
| 229 |
Range::get_css([ |
| 230 |
'attributeValue' => $attributes['sliderIconSize'], |
| 231 |
'attribute_object_key' => 'value', |
| 232 |
'isResponsive' => true, |
| 233 |
'defaultValue' => 50, |
| 234 |
'unitDefaultValue' => 'px', |
| 235 |
'property' => 'height', |
| 236 |
'device' => $device, |
| 237 |
]), |
| 238 |
Range::get_css([ |
| 239 |
'attributeValue' => $attributes['sliderIconBorderSize'], |
| 240 |
'attribute_object_key' => 'value', |
| 241 |
'isResponsive' => true, |
| 242 |
'defaultValue' => 2, |
| 243 |
'unitDefaultValue' => 'px', |
| 244 |
'property' => 'border-width', |
| 245 |
'device' => $device, |
| 246 |
]), |
| 247 |
$css |
| 248 |
); |
| 249 |
} |
| 250 |
|
| 251 |
public function get_overlay_css( $attributes, $device = '' ) { |
| 252 |
$overlay_color = isset( $attributes['labelOverlayColor'] ) ? $attributes['labelOverlayColor'] : ''; |
| 253 |
|
| 254 |
return [ |
| 255 |
'background' => $overlay_color |
| 256 |
]; |
| 257 |
} |
| 258 |
|
| 259 |
public function get_image_overlay_css( $attributes, $device = '' ) { |
| 260 |
$label_bg_color = isset( $attributes['labelBgColor'] ) ? $attributes['labelBgColor'] : ''; |
| 261 |
$label_text_color = isset( $attributes['labelTextColor'] ) ? $attributes['labelTextColor'] : ''; |
| 262 |
$label_border = isset( $attributes['labelBorder'] ) ? $attributes['labelBorder'] : []; |
| 263 |
$slider_orientation = isset( $attributes['sliderOrientation'] ) ? $attributes['sliderOrientation'] : ''; |
| 264 |
$label_position = isset( $attributes['labelPosition'] ) ? $attributes['labelPosition'] : ''; |
| 265 |
|
| 266 |
// Determine transform value based on the conditions |
| 267 |
$transform = 'none'; |
| 268 |
if ( $label_position === 45 && $slider_orientation === 'vertical' ) { |
| 269 |
$transform = 'translateX(-50%)'; |
| 270 |
} elseif ( $label_position === 95 && $slider_orientation === 'vertical' ) { |
| 271 |
$transform = 'translateX(-100%)'; |
| 272 |
} elseif ( $label_position === 90 && $slider_orientation === 'horizontal' ) { |
| 273 |
$transform = 'translateY(-100%)'; |
| 274 |
} |
| 275 |
|
| 276 |
return array_merge( |
| 277 |
Border::get_css( $label_border, '', $device ), |
| 278 |
[ |
| 279 |
'background' => $label_bg_color, |
| 280 |
'color' => $label_text_color, |
| 281 |
'transform' => $transform, // Add transform to the CSS array |
| 282 |
'max-width' => '30%' |
| 283 |
] |
| 284 |
); |
| 285 |
} |
| 286 |
|
| 287 |
|
| 288 |
public function get_image_overlay_hover_css( $attributes, $device = '' ) { |
| 289 |
$label_hover_bg_color = isset( $attributes['labelHoverBgColor'] ) ? $attributes['labelHoverBgColor'] : ''; |
| 290 |
$label_hover_text_color = isset( $attributes['labelHoverTextColor'] ) ? $attributes['labelHoverTextColor'] : ''; |
| 291 |
$label_border_hover = isset( $attributes['labelBorderHover'] ) ? $attributes['labelBorderHover'] : []; |
| 292 |
|
| 293 |
return array_merge( |
| 294 |
Border::get_hover_css( $attributes['labelBorder'], '', $device ), |
| 295 |
[ |
| 296 |
'background' => $label_hover_bg_color, |
| 297 |
'color' => $label_hover_text_color, |
| 298 |
] |
| 299 |
); |
| 300 |
} |
| 301 |
|
| 302 |
public function get_before_image_overlay_horizontal_css( $attributes ) { |
| 303 |
$label_position = isset( $attributes['labelPosition'] ) ? $attributes['labelPosition'] : 45; |
| 304 |
|
| 305 |
return [ |
| 306 |
'top' => $label_position . '%', |
| 307 |
'left' => '10px' |
| 308 |
]; |
| 309 |
} |
| 310 |
|
| 311 |
public function get_before_image_overlay_vertical_css( $attributes ) { |
| 312 |
$label_position = isset( $attributes['labelPosition'] ) ? $attributes['labelPosition'] : 45; |
| 313 |
|
| 314 |
return [ |
| 315 |
'left' => $label_position . '%', |
| 316 |
'top' => '10px' |
| 317 |
]; |
| 318 |
} |
| 319 |
|
| 320 |
public function get_after_image_overlay_horizontal_css( $attributes ) { |
| 321 |
$label_position = isset( $attributes['labelPosition'] ) ? $attributes['labelPosition'] : 45; |
| 322 |
|
| 323 |
return [ |
| 324 |
'top' => $label_position . '%', |
| 325 |
'right' => '10px', |
| 326 |
]; |
| 327 |
} |
| 328 |
|
| 329 |
public function get_after_image_overlay_vertical_css( $attributes ) { |
| 330 |
$label_position = isset( $attributes['labelPosition'] ) ? $attributes['labelPosition'] : 45; |
| 331 |
|
| 332 |
return [ |
| 333 |
'bottom' => '10px', |
| 334 |
'left' => $label_position . '%', |
| 335 |
]; |
| 336 |
} |
| 337 |
} |
| 338 |
|