| @@ -1,7 +1,11 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace ABlocks\Blocks\ImageScroll; |
| 3 | 3 | |
| 4 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 5 | + exit; | |
| 6 | +} | |
| 7 | + | |
| 4 | 8 | use ABlocks\Classes\BlockBaseAbstract; |
| 5 | 9 | use ABlocks\Classes\CssGenerator; |
| 6 | 10 | use ABlocks\Controls\Alignment; |
| 7 | 11 | use ABlocks\Controls\Border; |
| @@ -9,9 +13,9 @@ | ||
| 9 | 13 | use ABlocks\Controls\Typography; |
| 10 | 14 | use ABlocks\Controls\CssFilter; |
| 11 | 15 | use ABlocks\Controls\BoxShadow; |
| 12 | 16 | use ABlocks\Controls\Range; |
| 13 | - | |
| 17 | +use ABlocks\Controls\Color; | |
| 14 | 18 | class Block extends BlockBaseAbstract { |
| 15 | 19 | protected $block_name = 'image-scroll'; |
| 16 | 20 | |
| 17 | 21 | public function build_css( $attributes ) { |
| @@ -84,8 +88,10 @@ | ||
| 84 | 88 | ); |
| 85 | 89 | $css_generator->add_class_styles( |
| 86 | 90 | '{{WRAPPER}} .ablocks-icon-wrap', |
| 87 | 91 | $this->get_icon_wrapper_css( $attributes ), |
| 92 | + $this->get_icon_wrapper_css( $attributes, 'Tablet' ), | |
| 93 | + $this->get_icon_wrapper_css( $attributes, 'Mobile' ), | |
| 88 | 94 | ); |
| 89 | 95 | $css_generator->add_class_styles( |
| 90 | 96 | '{{WRAPPER}}.ablocks-block--image-scroll:hover .ablocks-icon-wrap', |
| 91 | 97 | $this->get_icon_wrapper_hover_css( $attributes ), |
| @@ -98,14 +104,23 @@ | ||
| 98 | 104 | return array_merge( |
| 99 | 105 | $css, |
| 100 | 106 | Range::get_css([ |
| 101 | 107 | 'attributeValue' => $attributes['scrollHeight'], |
| 102 | - 'isResponsive' => false, | |
| 103 | - 'hasUnit' => false, | |
| 104 | - 'defaultValue' => 300, | |
| 108 | + 'isResponsive' => true, | |
| 109 | + 'defaultValue' => 200, | |
| 105 | 110 | 'property' => 'height', |
| 106 | 111 | 'device' => $device, |
| 107 | 112 | ]), |
| 113 | + Range::get_css([ | |
| 114 | + 'attributeValue' => $attributes['scrollWidth'], | |
| 115 | + 'attributeObjectKey' => 'value', | |
| 116 | + 'isResponsive' => true, | |
| 117 | + 'defaultValue' => 100, | |
| 118 | + 'hasUnit' => true, | |
| 119 | + 'unitDefaultValue' => '%', | |
| 120 | + 'property' => 'width', | |
| 121 | + 'device' => $device, | |
| 122 | + ]), | |
| 108 | 123 | ); |
| 109 | 124 | } |
| 110 | 125 | public function get_scroll_option_css( $attributes, $device = '' ) { |
| 111 | 126 | $css = []; |
| @@ -137,14 +152,11 @@ | ||
| 137 | 152 | return $css; |
| 138 | 153 | } |
| 139 | 154 | public function get_image_overlay_css( $attributes ) { |
| 140 | 155 | $css = []; |
| 156 | + $css['background-color'] = Color::get_css( | |
| 157 | + isset( $attributes['overlayColor'] ) ? $attributes['overlayColor'] : ''); | |
| 141 | 158 | |
| 142 | - // Handle overlay color if provided | |
| 143 | - if ( ! empty( $attributes['overlayColor'] ) ) { | |
| 144 | - $css['background-color'] = $attributes['overlayColor']; | |
| 145 | - } | |
| 146 | - | |
| 147 | 159 | // Set common positioning and display properties |
| 148 | 160 | $css['position'] = 'absolute'; |
| 149 | 161 | $css['top'] = '0'; |
| 150 | 162 | $css['left'] = '0'; |
| @@ -153,18 +165,19 @@ | ||
| 153 | 165 | $css['z-index'] = 4; |
| 154 | 166 | $css['display'] = 'block'; |
| 155 | 167 | |
| 156 | 168 | // Border calculations |
| 157 | - $topDiff = ! empty( $attributes['border']['commonWidth'] ) ? (int) $attributes['border']['commonWidth'] : (int) $attributes['border']['topWidth']; | |
| 158 | - $bottomDiff = ! empty( $attributes['border']['commonWidth'] ) ? (int) $attributes['border']['commonWidth'] : (int) $attributes['border']['bottomWidth']; | |
| 159 | - $leftDiff = ! empty( $attributes['border']['commonWidth'] ) ? (int) $attributes['border']['commonWidth'] : (int) $attributes['border']['leftWidth']; | |
| 160 | - $rightDiff = ! empty( $attributes['border']['commonWidth'] ) ? (int) $attributes['border']['commonWidth'] : (int) $attributes['border']['rightWidth']; | |
| 169 | + $border = $attributes['border'] ?? []; | |
| 170 | + $topDiff = ! empty( $border['commonWidth'] ) ? (int) $border['commonWidth'] : (int) ( $border['topWidth'] ?? 0 ); | |
| 171 | + $bottomDiff = ! empty( $border['commonWidth'] ) ? (int) $border['commonWidth'] : (int) ( $border['bottomWidth'] ?? 0 ); | |
| 172 | + $leftDiff = ! empty( $border['commonWidth'] ) ? (int) $border['commonWidth'] : (int) ( $border['leftWidth'] ?? 0 ); | |
| 173 | + $rightDiff = ! empty( $border['commonWidth'] ) ? (int) $border['commonWidth'] : (int) ( $border['rightWidth'] ?? 0 ); | |
| 161 | 174 | |
| 162 | 175 | // Border radius calculations |
| 163 | - $topRadiusValue = ! empty( $attributes['border']['commonRadius'] ) ? (int) $attributes['border']['commonRadius'] : (int) $attributes['border']['topRadius']; | |
| 164 | - $leftRadiusValue = ! empty( $attributes['border']['commonRadius'] ) ? (int) $attributes['border']['commonRadius'] : (int) $attributes['border']['leftRadius']; | |
| 165 | - $rightRadiusValue = ! empty( $attributes['border']['commonRadius'] ) ? (int) $attributes['border']['commonRadius'] : (int) $attributes['border']['rightRadius']; | |
| 166 | - $bottomRadiusValue = ! empty( $attributes['border']['commonRadius'] ) ? (int) $attributes['border']['commonRadius'] : (int) $attributes['border']['bottomRadius']; | |
| 176 | + $topRadiusValue = ! empty( $border['commonRadius'] ) ? (int) $border['commonRadius'] : (int) ( $border['topRadius'] ?? 0 ); | |
| 177 | + $leftRadiusValue = ! empty( $border['commonRadius'] ) ? (int) $border['commonRadius'] : (int) ( $border['leftRadius'] ?? 0 ); | |
| 178 | + $rightRadiusValue = ! empty( $border['commonRadius'] ) ? (int) $border['commonRadius'] : (int) ( $border['rightRadius'] ?? 0 ); | |
| 179 | + $bottomRadiusValue = ! empty( $border['commonRadius'] ) ? (int) $border['commonRadius'] : (int) ( $border['bottomRadius'] ?? 0 ); | |
| 167 | 180 | |
| 168 | 181 | // Apply border radius with differences taken into account |
| 169 | 182 | $css['border-top-left-radius'] = ( $topRadiusValue - $topDiff ) . 'px'; |
| 170 | 183 | $css['border-top-right-radius'] = ( $rightRadiusValue - $rightDiff ) . 'px'; |
| @@ -310,18 +323,19 @@ | ||
| 310 | 323 | public function get_image_container_css( $attributes, $device = '' ) { |
| 311 | 324 | $alignment_value = $attributes['alignment'][ 'value' . $device ] ?? ''; |
| 312 | 325 | |
| 313 | 326 | $css = []; |
| 314 | - $topDiff = ! empty( $attributes['border']['commonWidth'] ) ? (int) $attributes['border']['commonWidth'] : (int) $attributes['border']['topWidth']; | |
| 315 | - $bottomDiff = ! empty( $attributes['border']['commonWidth'] ) ? (int) $attributes['border']['commonWidth'] : (int) $attributes['border']['bottomWidth']; | |
| 316 | - $leftDiff = ! empty( $attributes['border']['commonWidth'] ) ? (int) $attributes['border']['commonWidth'] : (int) $attributes['border']['leftWidth']; | |
| 317 | - $rightDiff = ! empty( $attributes['border']['commonWidth'] ) ? (int) $attributes['border']['commonWidth'] : (int) $attributes['border']['rightWidth']; | |
| 327 | + $border = $attributes['border'] ?? []; | |
| 328 | + $topDiff = ! empty( $border['commonWidth'] ) ? (int) $border['commonWidth'] : (int) ( $border['topWidth'] ?? 0 ); | |
| 329 | + $bottomDiff = ! empty( $border['commonWidth'] ) ? (int) $border['commonWidth'] : (int) ( $border['bottomWidth'] ?? 0 ); | |
| 330 | + $leftDiff = ! empty( $border['commonWidth'] ) ? (int) $border['commonWidth'] : (int) ( $border['leftWidth'] ?? 0 ); | |
| 331 | + $rightDiff = ! empty( $border['commonWidth'] ) ? (int) $border['commonWidth'] : (int) ( $border['rightWidth'] ?? 0 ); | |
| 318 | 332 | |
| 319 | 333 | // Border radius calculations |
| 320 | - $topRadiusValue = ! empty( $attributes['border']['commonRadius'] ) ? (int) $attributes['border']['commonRadius'] : (int) $attributes['border']['topRadius']; | |
| 321 | - $leftRadiusValue = ! empty( $attributes['border']['commonRadius'] ) ? (int) $attributes['border']['commonRadius'] : (int) $attributes['border']['leftRadius']; | |
| 322 | - $rightRadiusValue = ! empty( $attributes['border']['commonRadius'] ) ? (int) $attributes['border']['commonRadius'] : (int) $attributes['border']['rightRadius']; | |
| 323 | - $bottomRadiusValue = ! empty( $attributes['border']['commonRadius'] ) ? (int) $attributes['border']['commonRadius'] : (int) $attributes['border']['bottomRadius']; | |
| 334 | + $topRadiusValue = ! empty( $border['commonRadius'] ) ? (int) $border['commonRadius'] : (int) ( $border['topRadius'] ?? 0 ); | |
| 335 | + $leftRadiusValue = ! empty( $border['commonRadius'] ) ? (int) $border['commonRadius'] : (int) ( $border['leftRadius'] ?? 0 ); | |
| 336 | + $rightRadiusValue = ! empty( $border['commonRadius'] ) ? (int) $border['commonRadius'] : (int) ( $border['rightRadius'] ?? 0 ); | |
| 337 | + $bottomRadiusValue = ! empty( $border['commonRadius'] ) ? (int) $border['commonRadius'] : (int) ( $border['bottomRadius'] ?? 0 ); | |
| 324 | 338 | |
| 325 | 339 | // Apply border radius with differences taken into account |
| 326 | 340 | $css['border-top-left-radius'] = ( $topRadiusValue - $topDiff ) . 'px'; |
| 327 | 341 | $css['border-top-right-radius'] = ( $rightRadiusValue - $rightDiff ) . 'px'; |
| @@ -340,16 +354,16 @@ | ||
| 340 | 354 | 'left' => '50%', |
| 341 | 355 | 'z-index' => '5', |
| 342 | 356 | 'opacity' => '1', |
| 343 | 357 | ]; |
| 344 | - if ( ! empty( $attributes['iconColor'] ) ) { | |
| 345 | - $css['color'] = $attributes['iconColor']; | |
| 346 | - } | |
| 347 | 358 | return array_merge( |
| 359 | + [ 'color' => Color::get_css( isset( $attributes['iconColor'] ) ? $attributes['iconColor'] : 'black' ) ], | |
| 348 | 360 | $css, |
| 349 | 361 | Range::get_css([ |
| 350 | 362 | 'attributeValue' => $attributes['iconFontSize'], |
| 351 | - 'defaultValue' => 0, | |
| 363 | + 'isResponsive' => true, | |
| 364 | + 'hasUnit' => true, | |
| 365 | + 'defaultValue' => 36, | |
| 352 | 366 | 'property' => 'font-size', |
| 353 | 367 | ]) |
| 354 | 368 | ); |
| 355 | 369 | } |