| @@ -6,8 +6,9 @@ | ||
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | use ABlocks\Classes\ControlBaseAbstract; |
| 9 | 9 | use ABlocks\Controls\Color; |
| 10 | +use ABlocks\Helper; | |
| 10 | 11 | |
| 11 | 12 | class BackgroundOverlay extends ControlBaseAbstract { |
| 12 | 13 | |
| 13 | 14 | public static function get_attribute_default_value( $is_responsive = false ) { |
| @@ -150,34 +151,13 @@ | ||
| 150 | 151 | $attribute_value |
| 151 | 152 | ); |
| 152 | 153 | |
| 153 | 154 | // Get the units for X and Y position, and display size width |
| 154 | - $unitX_position_unit = self::get_unit( | |
| 155 | - [ | |
| 156 | - 'unit' => $value['imgXPositionUnit'], | |
| 157 | - 'unitTablet' => $value['imgXPositionUnitTablet'], | |
| 158 | - 'unitMobile' => $value['imgXPositionUnitMobile'], | |
| 159 | - ], | |
| 160 | - $device | |
| 161 | - ); | |
| 155 | + $unitX_position_unit = Helper::get_responsive_value( $value, 'imgXPositionUnit', $device ); | |
| 162 | 156 | |
| 163 | - $unitY_position_unit = self::get_unit( | |
| 164 | - [ | |
| 165 | - 'unit' => $value['imgYPositionUnit'], | |
| 166 | - 'unitTablet' => $value['imgYPositionUnitTablet'], | |
| 167 | - 'unitMobile' => $value['imgYPositionUnitMobile'], | |
| 168 | - ], | |
| 169 | - $device | |
| 170 | - ); | |
| 157 | + $unitY_position_unit = Helper::get_responsive_value( $value, 'imgYPositionUnit', $device ); | |
| 171 | 158 | |
| 172 | - $display_size_width_unit = self::get_unit( | |
| 173 | - [ | |
| 174 | - 'unit' => $value['imgDisplaySizeWidthUnit'], | |
| 175 | - 'unitTablet' => $value['imgDisplaySizeWidthUnitTablet'], | |
| 176 | - 'unitMobile' => $value['imgDisplaySizeWidthUnitMobile'], | |
| 177 | - ], | |
| 178 | - $device | |
| 179 | - ); | |
| 159 | + $display_size_width_unit = Helper::get_responsive_value( $value, 'imgDisplaySizeWidthUnit', $device ); | |
| 180 | 160 | |
| 181 | 161 | $css = []; |
| 182 | 162 | |
| 183 | 163 | $topDiff = ! empty( $extra_border_value['commonWidth'] ) ? intval( $extra_border_value['commonWidth'] ) : intval( $extra_border_value['topWidth'] ?? 0 ); |
| @@ -269,14 +249,13 @@ | ||
| 269 | 249 | } |
| 270 | 250 | } |
| 271 | 251 | |
| 272 | 252 | // Handle opacity |
| 273 | - if ( $device === 'Tablet' && isset( $value['opacityTablet'] ) ) { | |
| 274 | - $css['opacity'] = $value['opacityTablet']; | |
| 275 | - } elseif ( $device === 'Mobile' && isset( $value['opacityMobile'] ) ) { | |
| 276 | - $css['opacity'] = $value['opacityMobile']; | |
| 277 | - } elseif ( isset( $value['opacity'] ) ) { | |
| 278 | - $css['opacity'] = $value['opacity']; | |
| 253 | + // The device's own opacity, else the nearest containing wider | |
| 254 | + // device's (custom breakpoints included). | |
| 255 | + $opacity_value = Helper::get_responsive_value( $value, 'opacity', $device ); | |
| 256 | + if ( false !== $opacity_value ) { | |
| 257 | + $css['opacity'] = $opacity_value; | |
| 279 | 258 | } |
| 280 | 259 | |
| 281 | 260 | // Handle blend mode |
| 282 | 261 | if ( ! empty( $value['blendMode'] ) ) { |
| @@ -304,14 +283,13 @@ | ||
| 304 | 283 | $css[ $property ] = Color::get_css( esc_attr( $value[ $background_color_key ] ) ); |
| 305 | 284 | |
| 306 | 285 | // Handle opacity |
| 307 | 286 | |
| 308 | - if ( $device === 'Tablet' && isset( $value['opacityTablet'] ) ) { | |
| 309 | - $css['opacity'] = $value['opacityTablet']; | |
| 310 | - } elseif ( $device === 'Mobile' && isset( $value['opacityMobile'] ) ) { | |
| 311 | - $css['opacity'] = $value['opacityMobile']; | |
| 312 | - } elseif ( isset( $value['opacity'] ) ) { | |
| 313 | - $css['opacity'] = $value['opacity']; | |
| 287 | + // The device's own opacity, else the nearest containing wider | |
| 288 | + // device's (custom breakpoints included). | |
| 289 | + $opacity_value = Helper::get_responsive_value( $value, 'opacity', $device ); | |
| 290 | + if ( false !== $opacity_value ) { | |
| 291 | + $css['opacity'] = $opacity_value; | |
| 314 | 292 | } |
| 315 | 293 | |
| 316 | 294 | // Handle blend mode |
| 317 | 295 | if ( ! empty( $value['blendMode'] ) ) { |
| @@ -353,34 +331,13 @@ | ||
| 353 | 331 | self::get_attribute_default_value( $device ? true : false ), |
| 354 | 332 | $attribute_value |
| 355 | 333 | ); |
| 356 | 334 | // Get the units for X and Y position hover states and display size hover width |
| 357 | - $unit_x_position_unit_h = self::get_unit( | |
| 358 | - [ | |
| 359 | - 'unit' => $value['imgXPositionUnitH'], | |
| 360 | - 'unitTablet' => $value['imgXPositionUnitHTablet'], | |
| 361 | - 'unitMobile' => $value['imgXPositionUnitHMobile'], | |
| 362 | - ], | |
| 363 | - $device | |
| 364 | - ); | |
| 335 | + $unit_x_position_unit_h = Helper::get_responsive_value( $value, 'imgXPositionUnitH', $device ); | |
| 365 | 336 | |
| 366 | - $unit_y_position_unit_h = self::get_unit( | |
| 367 | - [ | |
| 368 | - 'unit' => $value['imgYPositionUnitH'], | |
| 369 | - 'unitTablet' => $value['imgYPositionUnitHTablet'], | |
| 370 | - 'unitMobile' => $value['imgYPositionUnitHMobile'], | |
| 371 | - ], | |
| 372 | - $device | |
| 373 | - ); | |
| 337 | + $unit_y_position_unit_h = Helper::get_responsive_value( $value, 'imgYPositionUnitH', $device ); | |
| 374 | 338 | |
| 375 | - $img_display_size_width_h_unit = self::get_unit( | |
| 376 | - [ | |
| 377 | - 'unit' => $value['imgDisplaySizeWidthHUnit'], | |
| 378 | - 'unitTablet' => $value['imgDisplaySizeWidthHUnitTablet'], | |
| 379 | - 'unitMobile' => $value['imgDisplaySizeWidthHMobile'], | |
| 380 | - ], | |
| 381 | - $device | |
| 382 | - ); | |
| 339 | + $img_display_size_width_h_unit = Helper::get_responsive_value( $value, 'imgDisplaySizeWidthHUnit', $device ); | |
| 383 | 340 | |
| 384 | 341 | $css = []; |
| 385 | 342 | $topDiffH = ! empty( $extra_border_value['commonWidthH'] ) ? intval( $extra_border_value['commonWidthH'] ) : intval( $extra_border_value['topWidth'] ?? 0 ); |
| 386 | 343 | $bottomDiffH = ! empty( $extra_border_value['commonWidthH'] ) ? intval( $extra_border_value['commonWidthH'] ) : intval( $extra_border_value['bottomWidth'] ?? 0 ); |
| @@ -469,14 +426,13 @@ | ||
| 469 | 426 | ); |
| 470 | 427 | } |
| 471 | 428 | } |
| 472 | 429 | // Handle opacity on hover |
| 473 | - if ( $device === 'Tablet' && isset( $value['opacityHTablet'] ) ) { | |
| 474 | - $css['opacity'] = $value['opacityHTablet']; | |
| 475 | - } elseif ( $device === 'Mobile' && isset( $value['opacityHMobile'] ) ) { | |
| 476 | - $css['opacity'] = $value['opacityHMobile']; | |
| 477 | - } elseif ( isset( $value['opacityH'] ) ) { | |
| 478 | - $css['opacity'] = $value['opacityH']; | |
| 430 | + // The device's own opacity, else the nearest containing wider | |
| 431 | + // device's (custom breakpoints included). | |
| 432 | + $opacity_h_value = Helper::get_responsive_value( $value, 'opacityH', $device ); | |
| 433 | + if ( false !== $opacity_h_value ) { | |
| 434 | + $css['opacity'] = $opacity_h_value; | |
| 479 | 435 | } |
| 480 | 436 | // Handle blend mode on hover |
| 481 | 437 | if ( ! empty( $value['blendModeH'] ) ) { |
| 482 | 438 | $css['mix-blend-mode'] = esc_attr( $value['blendModeH'] ); |
| @@ -496,14 +452,13 @@ | ||
| 496 | 452 | $css['width'] = '100%'; |
| 497 | 453 | $css['height'] = '100%'; |
| 498 | 454 | $css[ $property ] = Color::get_css( esc_attr( $value[ $background_color_h_key ] ) ); |
| 499 | 455 | |
| 500 | - if ( $device === 'Tablet' && isset( $value['opacityHTablet'] ) ) { | |
| 501 | - $css['opacity'] = $value['opacityHTablet']; | |
| 502 | - } elseif ( $device === 'Mobile' && isset( $value['opacityHMobile'] ) ) { | |
| 503 | - $css['opacity'] = $value['opacityHMobile']; | |
| 504 | - } elseif ( isset( $value['opacityH'] ) ) { | |
| 505 | - $css['opacity'] = $value['opacityH']; | |
| 456 | + // The device's own opacity, else the nearest containing wider | |
| 457 | + // device's (custom breakpoints included). | |
| 458 | + $opacity_h_value = Helper::get_responsive_value( $value, 'opacityH', $device ); | |
| 459 | + if ( false !== $opacity_h_value ) { | |
| 460 | + $css['opacity'] = $opacity_h_value; | |
| 506 | 461 | } |
| 507 | 462 | |
| 508 | 463 | // Handle blend mode on hover |
| 509 | 464 | if ( ! empty( $value['blendModeH'] ) ) { |