| @@ -5,8 +5,9 @@ | ||
| 5 | 5 | exit(); |
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | use ABlocks\Classes\ControlBaseAbstract; |
| 9 | +use ABlocks\Helper; | |
| 9 | 10 | |
| 10 | 11 | class Width extends ControlBaseAbstract { |
| 11 | 12 | |
| 12 | 13 | public static function get_attribute_default_value( $is_responsive = false ) { |
| @@ -56,39 +57,48 @@ | ||
| 56 | 57 | $attribute_value = wp_parse_args( |
| 57 | 58 | $attribute_value, |
| 58 | 59 | self::get_attribute_default_value( (bool) $device ) |
| 59 | 60 | ); |
| 61 | + | |
| 60 | 62 | $css = []; |
| 61 | - if ( ! empty( $attribute_value[ 'widthType' . $device ] ) ) { | |
| 62 | - if ( $attribute_value[ 'widthType' . $device ] === 'full' ) { | |
| 63 | + | |
| 64 | + // Width type (uses responsive fallback) | |
| 65 | + $width_type = Helper::get_responsive_value( | |
| 66 | + $attribute_value, | |
| 67 | + 'widthType', | |
| 68 | + $device, | |
| 69 | + self::get_attribute_default_value() | |
| 70 | + ); | |
| 71 | + | |
| 72 | + if ( ! empty( $width_type ) ) { | |
| 73 | + if ( $width_type === 'full' ) { | |
| 63 | 74 | $css[ $property ] = '100%'; |
| 64 | - } elseif ( $attribute_value[ 'widthType' . $device ] === 'auto' ) { | |
| 75 | + } elseif ( $width_type === 'auto' ) { | |
| 65 | 76 | $css[ $property ] = 'auto'; |
| 66 | - $css['display'] = 'inline-block'; | |
| 67 | - } elseif ( $attribute_value[ 'widthType' . $device ] === 'custom' ) { | |
| 68 | - $css[ $property ] = | |
| 69 | - $attribute_value[ 'customWidth' . $device ] . | |
| 70 | - self::get_unit( | |
| 71 | - [ | |
| 72 | - 'unit' => ! empty( | |
| 73 | - $attribute_value['customWidthUnit'] | |
| 74 | - ) | |
| 75 | - ? $attribute_value['customWidthUnit'] | |
| 76 | - : '', | |
| 77 | - 'unitTablet' => ! empty( | |
| 78 | - $attribute_value['customWidthUnitTablet'] | |
| 79 | - ) | |
| 80 | - ? $attribute_value['customWidthUnitTablet'] | |
| 81 | - : '', | |
| 82 | - 'unitMobile' => ! empty( | |
| 83 | - $attribute_value['customWidthUnitTablet'] | |
| 84 | - ) | |
| 85 | - ? $attribute_value['customWidthUnitTablet'] | |
| 86 | - : '', | |
| 87 | - ], | |
| 88 | - $device | |
| 89 | - ) . '!important'; | |
| 77 | + $css['display'] = 'inline-block'; | |
| 78 | + } elseif ( $width_type === 'custom' ) { | |
| 79 | + // Get custom width with responsive fallback | |
| 80 | + $custom_width = Helper::get_responsive_value( | |
| 81 | + $attribute_value, | |
| 82 | + 'customWidth', | |
| 83 | + $device, | |
| 84 | + self::get_attribute_default_value() | |
| 85 | + ); | |
| 86 | + | |
| 87 | + // Get responsive unit (delegates to your get_unit function) | |
| 88 | + $unit = self::get_unit( | |
| 89 | + [ | |
| 90 | + 'unit' => Helper::get_responsive_value( $attribute_value, 'customWidthUnit', 'Desktop' ), | |
| 91 | + 'unitTablet' => Helper::get_responsive_value( $attribute_value, 'customWidthUnit', 'Tablet' ), | |
| 92 | + 'unitMobile' => Helper::get_responsive_value( $attribute_value, 'customWidthUnit', 'Mobile' ), | |
| 93 | + ], | |
| 94 | + $device | |
| 95 | + ); | |
| 96 | + | |
| 97 | + $css[ $property ] = $custom_width . $unit; | |
| 90 | 98 | }//end if |
| 91 | 99 | }//end if |
| 100 | + | |
| 92 | 101 | return $css; |
| 93 | 102 | } |
| 103 | + | |
| 94 | 104 | } |