| 1 |
<?php |
| 2 |
namespace ABlocks\Controls; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
use ABlocks\Classes\ControlBaseAbstract; |
| 9 |
|
| 10 |
class Dimensions extends ControlBaseAbstract { |
| 11 |
public static function get_attribute_default_value( $is_responsive = false ) { |
| 12 |
if ( $is_responsive ) { |
| 13 |
return [ |
| 14 |
'isLinked' => true, |
| 15 |
'isLinkedTablet' => true, |
| 16 |
'isLinkedMobile' => true, |
| 17 |
'common' => '', |
| 18 |
'top' => '', |
| 19 |
'right' => '', |
| 20 |
'bottom' => '', |
| 21 |
'left' => '', |
| 22 |
'unit' => 'px', |
| 23 |
'commonTablet' => '', |
| 24 |
'topTablet' => '', |
| 25 |
'rightTablet' => '', |
| 26 |
'bottomTablet' => '', |
| 27 |
'leftTablet' => '', |
| 28 |
'unitTablet' => '', |
| 29 |
'commonMobile' => '', |
| 30 |
'topMobile' => '', |
| 31 |
'rightMobile' => '', |
| 32 |
'bottomMobile' => '', |
| 33 |
'leftMobile' => '', |
| 34 |
'unitMobile' => '', |
| 35 |
]; |
| 36 |
}//end if |
| 37 |
return [ |
| 38 |
'isLinked' => true, |
| 39 |
'common' => '', |
| 40 |
'top' => '', |
| 41 |
'right' => '', |
| 42 |
'bottom' => '', |
| 43 |
'left' => '', |
| 44 |
'unit' => 'px', |
| 45 |
]; |
| 46 |
} |
| 47 |
|
| 48 |
public static function get_attribute( $attributeName, $isResponsive = false ) { |
| 49 |
$attribute_value = self::get_attribute_default_value( $isResponsive ); |
| 50 |
if ( $isResponsive ) { |
| 51 |
return [ |
| 52 |
$attributeName => [ |
| 53 |
'type' => 'object', |
| 54 |
'default' => $attribute_value |
| 55 |
] |
| 56 |
]; |
| 57 |
} |
| 58 |
return [ |
| 59 |
$attributeName => [ |
| 60 |
'type' => 'object', |
| 61 |
'default' => $attribute_value |
| 62 |
] |
| 63 |
]; |
| 64 |
} |
| 65 |
public static function get_css( $attribute_value, $property = '', $device = '' ) { |
| 66 |
$attribute_value = wp_parse_args( $attribute_value, self::get_attribute_default_value( (bool) $device ) ); |
| 67 |
$css = []; |
| 68 |
$unit = self::get_unit( $attribute_value, $device ); |
| 69 |
|
| 70 |
if ( (bool) $attribute_value[ 'isLinked' . $device ] ) { |
| 71 |
if ( '' !== $attribute_value[ 'common' . $device ] ) { |
| 72 |
$css[ $property ] = $attribute_value[ 'common' . $device ] . $unit; |
| 73 |
} |
| 74 |
} else { |
| 75 |
if ( '' !== $attribute_value[ 'top' . $device ] ) { |
| 76 |
$css[ $property . '-top' ] = $attribute_value[ 'top' . $device ] . $unit; |
| 77 |
} |
| 78 |
if ( '' !== $attribute_value[ 'right' . $device ] ) { |
| 79 |
$css[ $property . '-right' ] = $attribute_value[ 'right' . $device ] . $unit; |
| 80 |
} |
| 81 |
if ( '' !== $attribute_value[ 'bottom' . $device ] ) { |
| 82 |
$css[ $property . '-bottom' ] = $attribute_value[ 'bottom' . $device ] . $unit; |
| 83 |
} |
| 84 |
if ( '' !== $attribute_value[ 'left' . $device ] ) { |
| 85 |
$css[ $property . '-left' ] = $attribute_value[ 'left' . $device ] . $unit; |
| 86 |
} |
| 87 |
} |
| 88 |
return $css; |
| 89 |
} |
| 90 |
|
| 91 |
} |
| 92 |
|