| 1 |
<?php |
| 2 |
namespace ABlocks\Controls; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit(); |
| 6 |
} |
| 7 |
|
| 8 |
use ABlocks\Classes\ControlBaseAbstract; |
| 9 |
|
| 10 |
class Width extends ControlBaseAbstract { |
| 11 |
|
| 12 |
public static function get_attribute_default_value( $is_responsive = false ) { |
| 13 |
if ( $is_responsive ) { |
| 14 |
return [ |
| 15 |
'widthType' => 'default', |
| 16 |
'widthTypeTablet' => '', |
| 17 |
'widthTypeMobile' => '', |
| 18 |
'customWidth' => '', |
| 19 |
'customWidthTablet' => '', |
| 20 |
'customWidthMobile' => '', |
| 21 |
'customWidthUnit' => '%', |
| 22 |
'customWidthUnitTablet' => '', |
| 23 |
'customWidthUnitMobile' => '', |
| 24 |
]; |
| 25 |
} |
| 26 |
return [ |
| 27 |
'widthType' => 'default', |
| 28 |
'customWidth' => '', |
| 29 |
'customWidthUnit' => '%', |
| 30 |
]; |
| 31 |
} |
| 32 |
|
| 33 |
public static function get_attribute( $attributeName, $isResponsive = false ) { |
| 34 |
if ( $isResponsive ) { |
| 35 |
return [ |
| 36 |
$attributeName => [ |
| 37 |
'type' => 'object', |
| 38 |
'default' => self::get_attribute_default_value( |
| 39 |
$isResponsive |
| 40 |
), |
| 41 |
], |
| 42 |
]; |
| 43 |
} |
| 44 |
return [ |
| 45 |
$attributeName => [ |
| 46 |
'type' => 'object', |
| 47 |
'default' => self::get_attribute_default_value( $isResponsive ), |
| 48 |
], |
| 49 |
]; |
| 50 |
} |
| 51 |
public static function get_css( |
| 52 |
$attribute_value, |
| 53 |
$property = '', |
| 54 |
$device = '' |
| 55 |
) { |
| 56 |
$attribute_value = wp_parse_args( |
| 57 |
$attribute_value, |
| 58 |
self::get_attribute_default_value( (bool) $device ) |
| 59 |
); |
| 60 |
$css = []; |
| 61 |
if ( ! empty( $attribute_value[ 'widthType' . $device ] ) ) { |
| 62 |
if ( $attribute_value[ 'widthType' . $device ] === 'full' ) { |
| 63 |
$css[ $property ] = '100%'; |
| 64 |
} elseif ( $attribute_value[ 'widthType' . $device ] === 'auto' ) { |
| 65 |
$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'; |
| 90 |
}//end if |
| 91 |
}//end if |
| 92 |
return $css; |
| 93 |
} |
| 94 |
} |
| 95 |
|