| 1 |
<?php |
| 2 |
namespace ABlocks\Blocks\AdvanceLists; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
use ABlocks\Classes\BlockBaseAbstract; |
| 9 |
use ABlocks\Classes\CssGenerator; |
| 10 |
use ABlocks\Controls\Alignment; |
| 11 |
use ABlocks\Controls\Dimensions; |
| 12 |
use ABlocks\Controls\Typography; |
| 13 |
use ABlocks\Controls\TextShadow; |
| 14 |
use ABlocks\Controls\TextStroke; |
| 15 |
use ABlocks\Controls\Width; |
| 16 |
use ABlocks\Controls\Border; |
| 17 |
use ABlocks\Controls\Range; |
| 18 |
use ABlocks\Controls\Color; |
| 19 |
|
| 20 |
class Block extends BlockBaseAbstract { |
| 21 |
|
| 22 |
protected $block_name = 'advance-lists'; |
| 23 |
|
| 24 |
public function build_css( $attributes ) { |
| 25 |
// Generate CSS |
| 26 |
$css_generator = new CssGenerator( $attributes ); |
| 27 |
|
| 28 |
$css_generator->add_class_styles( |
| 29 |
'{{WRAPPER}}.ablocks-block--advance-lists > .ablocks-block-container', |
| 30 |
$this->get_container_css( $attributes, '' ), |
| 31 |
$this->get_container_css( $attributes, 'Tablet' ), |
| 32 |
$this->get_container_css( $attributes, 'Mobile' ), |
| 33 |
); |
| 34 |
|
| 35 |
// text |
| 36 |
$css_generator->add_class_styles( |
| 37 |
'{{WRAPPER}} .ablocks-block-container .ablocks-advance-list-item-text', |
| 38 |
$this->get_paragraph_text_css( $attributes ), |
| 39 |
$this->get_paragraph_text_css( $attributes, 'Tablet' ), |
| 40 |
$this->get_paragraph_text_css( $attributes, 'Mobile' ), |
| 41 |
); |
| 42 |
$css_generator->add_class_styles( |
| 43 |
'{{WRAPPER}} .ablocks-block-container .ablocks-advance-list-item-text-drop-caps::first-letter', |
| 44 |
$this->get_paragraph_drop_text_css( $attributes ), |
| 45 |
$this->get_paragraph_drop_text_css( $attributes, 'Tablet' ), |
| 46 |
$this->get_paragraph_drop_text_css( $attributes, 'Mobile' ), |
| 47 |
); |
| 48 |
|
| 49 |
// Divider CSS |
| 50 |
$css_generator->add_class_styles( |
| 51 |
'{{WRAPPER}} .ablocks-advance-list-item-divider__pattern-' . ( $attributes['dividerType'] === 'mask-style' ? 'mask' : 'css' ), |
| 52 |
$this->get_divider_css( $attributes, '' ), |
| 53 |
$this->get_divider_css( $attributes, 'Tablet' ), |
| 54 |
$this->get_divider_css( $attributes, 'Mobile' ), |
| 55 |
); |
| 56 |
return $css_generator->generate_css(); |
| 57 |
} |
| 58 |
|
| 59 |
public function get_container_css( $attributes, $device = '' ) { |
| 60 |
$css = []; |
| 61 |
if ( ! empty( $attributes['listsDirection'][ 'value' . $device ] ) ) { |
| 62 |
$css['flex-direction'] = $attributes['listsDirection'][ 'value' . $device ]; |
| 63 |
} |
| 64 |
$listsDirection = ! empty( $attributes['listsDirection'][ 'value' . $device ] ) && $attributes['listsDirection'][ 'value' . $device ]; |
| 65 |
$alignment = isset( $attributes['alignment'] ) ? $attributes['alignment'] : ''; |
| 66 |
return array_merge( |
| 67 |
$css, |
| 68 |
Alignment::get_css( $alignment, 'text-align', $device ), |
| 69 |
Alignment::get_css( $alignment, ( $listsDirection && $attributes['listsDirection'][ 'value' . $device ] === 'row' ) ? 'justify-content' : 'align-items', $device ), |
| 70 |
Range::get_css([ |
| 71 |
'attributeValue' => $attributes['columnGap'], |
| 72 |
'attribute_object_key' => 'value', |
| 73 |
'isResponsive' => true, |
| 74 |
'defaultValue' => null, |
| 75 |
'hasUnit' => true, |
| 76 |
'unitDefaultValue' => 'px', |
| 77 |
'property' => 'gap', |
| 78 |
'device' => $device, |
| 79 |
]), |
| 80 |
); |
| 81 |
} |
| 82 |
|
| 83 |
public function get_paragraph_text_css( $attributes, $device = '' ) { |
| 84 |
$typographyValueGlobal = ! empty( $attributes['listTypographyGlobal'] ) ? $attributes['listTypographyGlobal'] : ''; |
| 85 |
$typography_value = isset( $attributes['listTypography'] ) ? $attributes['listTypography'] : []; |
| 86 |
return array_merge( |
| 87 |
[ 'color' => Color::get_css( isset( $attributes['textColor'] ) ? $attributes['textColor'] : '' ) ], |
| 88 |
Typography::get_css( $typography_value, '', $device, $typographyValueGlobal ), |
| 89 |
isset( $attributes['listTextStroke'] ) ? TextStroke::get_css( $attributes['listTextStroke'], '', $device ) : [], |
| 90 |
isset( $attributes['listTextShadow'] ) ? TextShadow::get_css( $attributes['listTextShadow'] ) : [], |
| 91 |
); |
| 92 |
} |
| 93 |
public function get_paragraph_drop_text_css( $attributes, $device = '' ) { |
| 94 |
return [ 'color' => Color::get_css( isset( $attributes['dropCapsTextColor'] ) ? $attributes['dropCapsTextColor'] : '' ) ]; |
| 95 |
} |
| 96 |
|
| 97 |
public function get_divider_css( $attributes, $device = '' ) { |
| 98 |
$css = []; |
| 99 |
$divider_width = isset( $attributes['width'][ 'value' . $device ] ) ? $attributes['width'][ 'value' . $device ] : 60; |
| 100 |
$default_Unit = '%'; |
| 101 |
|
| 102 |
if ( ! empty( $attributes['color'] ) ) { |
| 103 |
$css['--ablocks-divider-pattern-color'] = Color::get_css( isset( $attributes['color'] ) ? $attributes['color'] : '#000000' ); |
| 104 |
} |
| 105 |
|
| 106 |
$moreRangeCSS = []; |
| 107 |
if ( isset( $attributes['dividerType'] ) && $attributes['dividerType'] === 'mask-style' && isset( $attributes['size'] ) && ! empty( $attributes['size'] ) ) { |
| 108 |
$moreRangeCSS = Range::get_css([ |
| 109 |
'attributeValue' => $attributes['size'], |
| 110 |
'attribute_object_key' => 'value', |
| 111 |
'isResponsive' => false, |
| 112 |
'defaultValue' => null, |
| 113 |
'hasUnit' => false, |
| 114 |
'unitDefaultValue' => 'px', |
| 115 |
'property' => '--ablocks-divider-pattern-height', |
| 116 |
]); |
| 117 |
} elseif ( isset( $attributes['weight'] ) && ! empty( $attributes['weight'] ) ) { |
| 118 |
$moreRangeCSS = Range::get_css([ |
| 119 |
'attributeValue' => $attributes['weight'], |
| 120 |
'attribute_object_key' => 'value', |
| 121 |
'isResponsive' => false, |
| 122 |
'defaultValue' => null, |
| 123 |
'hasUnit' => false, |
| 124 |
'unitDefaultValue' => 'px', |
| 125 |
'property' => '--ablocks-divider-pattern-weight', |
| 126 |
]); |
| 127 |
}//end if |
| 128 |
|
| 129 |
if ( ! empty( $attributes['dividerPatternUrl'] ) ) { |
| 130 |
if ( $attributes['dividerType'] === 'mask-style' ) { |
| 131 |
$css['--ablocks-divider-pattern-url'] = 'url(' . $attributes['dividerPatternUrl'] . ')'; |
| 132 |
} else { |
| 133 |
$css['--ablocks-divider-pattern-style'] = $attributes['dividerPatternUrl']; |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
return array_merge( |
| 138 |
$css, |
| 139 |
Range::get_css([ |
| 140 |
'attributeValue' => $attributes['width'], |
| 141 |
'attribute_object_key' => 'value', |
| 142 |
'isResponsive' => true, |
| 143 |
'defaultValue' => 100, |
| 144 |
'hasUnit' => false, |
| 145 |
'unitDefaultValue' => '%', |
| 146 |
'property' => 'width', |
| 147 |
'device' => $device, |
| 148 |
]), |
| 149 |
$moreRangeCSS, |
| 150 |
); |
| 151 |
} |
| 152 |
|
| 153 |
} |
| 154 |
|