| 1 |
<?php |
| 2 |
|
| 3 |
namespace ABlocks\Blocks\ContentTimeline; |
| 4 |
|
| 5 |
use ABlocks\Controls\Range; |
| 6 |
|
| 7 |
if ( ! defined( 'ABSPATH' ) ) { |
| 8 |
exit; |
| 9 |
} |
| 10 |
use ABlocks\Classes\BlockBaseAbstract; |
| 11 |
use ABlocks\Classes\CssGenerator; |
| 12 |
use ABlocks\Classes\CssGeneratorV2; |
| 13 |
use ABlocks\Controls\Dimensions; |
| 14 |
use ABlocks\Controls\Typography; |
| 15 |
use ABlocks\Controls\Border; |
| 16 |
use ABlocks\Controls\Color; |
| 17 |
|
| 18 |
|
| 19 |
class Block extends BlockBaseAbstract { |
| 20 |
|
| 21 |
protected $block_name = 'content-timeline'; |
| 22 |
|
| 23 |
public function build_css_v1( $attributes ) { |
| 24 |
$css_generator = new CssGenerator( $attributes ); |
| 25 |
|
| 26 |
// Generate and add CSS styles for different parts of the block |
| 27 |
$css_generator->add_class_styles( |
| 28 |
'{{WRAPPER}} .ablocks-block-content-timeline--outer-wrap .ablocks-icon-maker svg', |
| 29 |
$this->get_content_timeline_icon_css( $attributes ), |
| 30 |
$this->get_content_timeline_icon_css( $attributes, 'Tablet' ), |
| 31 |
$this->get_content_timeline_icon_css( $attributes, 'Mobile' ), |
| 32 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_timeline_icon_css( $attributes, $device ); } ) |
| 33 |
); |
| 34 |
$css_generator->add_class_styles( |
| 35 |
'{{WRAPPER}} .ablocks-block-content-timeline--outer-wrap .ablocks__in-view-icon .ablocks-icon-wrap', |
| 36 |
$this->get_content_timeline_icon_background_css( $attributes ), |
| 37 |
$this->get_content_timeline_icon_background_css( $attributes, 'Tablet' ), |
| 38 |
$this->get_content_timeline_icon_background_css( $attributes, 'Mobile' ), |
| 39 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_timeline_icon_background_css( $attributes, $device ); } ) |
| 40 |
); |
| 41 |
$css_generator->add_class_styles( |
| 42 |
'{{WRAPPER}} .ablocks-block-content-timeline .ablocks-block-content-timeline__line', |
| 43 |
$this->get_content_timeline_connector_css( $attributes ), |
| 44 |
$this->get_content_timeline_connector_css( $attributes, 'Tablet' ), |
| 45 |
$this->get_content_timeline_connector_css( $attributes, 'Mobile' ), |
| 46 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_timeline_connector_css( $attributes, $device ); } ) |
| 47 |
); |
| 48 |
$css_generator->add_class_styles( |
| 49 |
'{{WRAPPER}} .ablocks-block-content-timeline--outer-wrap .ablocks-block-content-timeline-child--field', |
| 50 |
$this->get_content_timeline_item_gap_css( $attributes ), |
| 51 |
$this->get_content_timeline_item_gap_css( $attributes, 'Tablet' ), |
| 52 |
$this->get_content_timeline_item_gap_css( $attributes, 'Mobile' ), |
| 53 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_timeline_item_gap_css( $attributes, $device ); } ) |
| 54 |
); |
| 55 |
$css_generator->add_class_styles( |
| 56 |
'{{WRAPPER}} .ablocks-block-content-timeline--outer-wrap', |
| 57 |
$this->get_content_timeline_horizontal_gap_css( $attributes ), |
| 58 |
$this->get_content_timeline_horizontal_gap_css( $attributes, 'Tablet' ), |
| 59 |
$this->get_content_timeline_horizontal_gap_css( $attributes, 'Mobile' ), |
| 60 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_timeline_horizontal_gap_css( $attributes, $device ); } ) |
| 61 |
); |
| 62 |
$css_generator->add_class_styles( |
| 63 |
'{{WRAPPER}} .ablocks-block-content-timeline--outer-wrap .ablocks-block-content-timeline-child--field .ablocks-block-content-timeline-child__content-part', |
| 64 |
$this->get_content_timeline_content_css( $attributes ), |
| 65 |
$this->get_content_timeline_content_css( $attributes, 'Tablet' ), |
| 66 |
$this->get_content_timeline_content_css( $attributes, 'Mobile' ), |
| 67 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_timeline_content_css( $attributes, $device ); } ) |
| 68 |
); |
| 69 |
$css_generator->add_class_styles( |
| 70 |
'{{WRAPPER}} .ablocks-block-content-timeline-child__content-part .ablocks-block-content-timeline-child__arrow::after', |
| 71 |
$this->get_content_timeline_content_background_css( $attributes ), |
| 72 |
$this->get_content_timeline_content_background_css( $attributes, 'Tablet' ), |
| 73 |
$this->get_content_timeline_content_background_css( $attributes, 'Mobile' ), |
| 74 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_timeline_content_background_css( $attributes, $device ); } ) |
| 75 |
); |
| 76 |
$css_generator->add_class_styles( |
| 77 |
'{{WRAPPER}} .ablocks-block-content-timeline--outer-wrap .ablocks__in-view-icon', |
| 78 |
$this->get_content_timeline_connector_alignment_css( $attributes ), |
| 79 |
$this->get_content_timeline_connector_alignment_css( $attributes, 'Tablet' ), |
| 80 |
$this->get_content_timeline_connector_alignment_css( $attributes, 'Mobile' ), |
| 81 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_timeline_connector_alignment_css( $attributes, $device ); } ) |
| 82 |
); |
| 83 |
$css_generator->add_class_styles( |
| 84 |
'{{WRAPPER}} .ablocks-block-content-timeline-child__date', |
| 85 |
$this->get_content_timeline_date_alignment_css( $attributes ), |
| 86 |
$this->get_content_timeline_date_alignment_css( $attributes, 'Tablet' ), |
| 87 |
$this->get_content_timeline_date_alignment_css( $attributes, 'Mobile' ), |
| 88 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_timeline_date_alignment_css( $attributes, $device ); } ) |
| 89 |
); |
| 90 |
// Conditional CSS generation based on arrowAlignment |
| 91 |
|
| 92 |
$css_generator->add_class_styles( |
| 93 |
'{{WRAPPER}} .ablocks-block-content-timeline-child--line-center .ablocks-block-content-timeline-child__arrow', |
| 94 |
$this->get_content_timeline_arrow_css( $attributes ), |
| 95 |
$this->get_content_timeline_arrow_css( $attributes, 'Tablet' ), |
| 96 |
$this->get_content_timeline_arrow_css( $attributes, 'Mobile' ), |
| 97 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_timeline_arrow_css( $attributes, $device ); } ) |
| 98 |
); |
| 99 |
$css_generator->add_class_styles( |
| 100 |
'{{WRAPPER}} .ablocks-block-content-timeline-child__date,.ablocks-block-content-timeline-child__inner-content-date', |
| 101 |
$this->get_content_timeline_date_css( $attributes ), |
| 102 |
$this->get_content_timeline_date_css( $attributes, 'Tablet' ), |
| 103 |
$this->get_content_timeline_date_css( $attributes, 'Mobile' ), |
| 104 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_timeline_date_css( $attributes, $device ); } ) |
| 105 |
); |
| 106 |
$css_generator->add_class_styles( |
| 107 |
'{{WRAPPER}} .ablocks-block-content-timeline-child__inner-content-date', |
| 108 |
$this->get_content_timeline_date_mobile_css( $attributes, 'Mobile' ) |
| 109 |
); |
| 110 |
$css_generator->add_class_styles( |
| 111 |
'{{WRAPPER}} .ablocks-block-content-timeline-child__inner-content-date:hover', |
| 112 |
$this->get_content_timeline_date_hover_mobile_css( $attributes, 'Mobile' ) |
| 113 |
); |
| 114 |
$css_generator->add_class_styles( |
| 115 |
'{{WRAPPER}} .ablocks-block-content-timeline-child__date-inner', |
| 116 |
$this->get_content_timeline_show_date_center_css( $attributes, '' ), |
| 117 |
$this->get_content_timeline_show_date_center_css( $attributes, 'Tablet' ), |
| 118 |
$this->get_content_timeline_show_date_center_css( $attributes, 'Mobile' ), |
| 119 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_timeline_show_date_center_css( $attributes, $device ); } ) |
| 120 |
); |
| 121 |
$css_generator->add_class_styles( |
| 122 |
'{{WRAPPER}} .ablocks-block-content-timeline-child__date', |
| 123 |
$this->get_content_timeline_show_date_left_right_css( $attributes, '' ), |
| 124 |
$this->get_content_timeline_show_date_left_right_css( $attributes, 'Tablet' ), |
| 125 |
$this->get_content_timeline_show_date_left_right_css( $attributes, 'Mobile' ), |
| 126 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_timeline_show_date_left_right_css( $attributes, $device ); } ) |
| 127 |
); |
| 128 |
$css_generator->add_class_styles( |
| 129 |
'{{WRAPPER}} .ablocks-block-content-timeline--left .ablocks-block-content-timeline__line,.ablocks-block-content-timeline--right .ablocks-block-content-timeline__line', |
| 130 |
$this->get_content_timeline_show_date_left_right_line_css( $attributes, '' ), |
| 131 |
$this->get_content_timeline_show_date_left_right_line_css( $attributes, 'Tablet' ), |
| 132 |
$this->get_content_timeline_show_date_left_right_line_css( $attributes, 'Mobile' ), |
| 133 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_timeline_show_date_left_right_line_css( $attributes, $device ); } ) |
| 134 |
); |
| 135 |
$css_generator->add_class_styles( |
| 136 |
'{{WRAPPER}} .ablocks-block-content-timeline-child__inner-content-date', |
| 137 |
$this->get_content_timeline_show_date_mobile_css( $attributes, '' ), |
| 138 |
$this->get_content_timeline_show_date_mobile_css( $attributes, 'Tablet' ), |
| 139 |
$this->get_content_timeline_show_date_mobile_css( $attributes, 'Mobile' ), |
| 140 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_timeline_show_date_mobile_css( $attributes, $device ); } ) |
| 141 |
); |
| 142 |
|
| 143 |
return $css_generator->generate_css(); |
| 144 |
} |
| 145 |
public function build_css_v2( $attributes ) { |
| 146 |
$css_generator = new CssGeneratorV2( $attributes, $this->block_name ); |
| 147 |
|
| 148 |
// Generate and add CSS styles for different parts of the block |
| 149 |
$css_generator->add_class_styles( |
| 150 |
'{{WRAPPER}} .ablocks-icon-maker svg', |
| 151 |
$this->get_content_timeline_icon_css( $attributes ), |
| 152 |
$this->get_content_timeline_icon_css( $attributes, 'Tablet' ), |
| 153 |
$this->get_content_timeline_icon_css( $attributes, 'Mobile' ), |
| 154 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_timeline_icon_css( $attributes, $device ); } ) |
| 155 |
); |
| 156 |
$css_generator->add_class_styles( |
| 157 |
'{{WRAPPER}} .ablocks-block-content-timeline--outer-wrap .ablocks__in-view-icon', |
| 158 |
$this->get_content_timeline_icon_background_css( $attributes ), |
| 159 |
$this->get_content_timeline_icon_background_css( $attributes, 'Tablet' ), |
| 160 |
$this->get_content_timeline_icon_background_css( $attributes, 'Mobile' ), |
| 161 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_timeline_icon_background_css( $attributes, $device ); } ) |
| 162 |
); |
| 163 |
$css_generator->add_class_styles( |
| 164 |
'{{WRAPPER}} .ablocks-block-content-timeline .ablocks-block-content-timeline__line', |
| 165 |
$this->get_content_timeline_connector_css( $attributes ), |
| 166 |
$this->get_content_timeline_connector_css( $attributes, 'Tablet' ), |
| 167 |
$this->get_content_timeline_connector_css( $attributes, 'Mobile' ), |
| 168 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_timeline_connector_css( $attributes, $device ); } ) |
| 169 |
); |
| 170 |
$css_generator->add_class_styles( |
| 171 |
'{{WRAPPER}} .ablocks-block-content-timeline--outer-wrap .ablocks-block-content-timeline-child--field', |
| 172 |
$this->get_content_timeline_item_gap_css( $attributes ), |
| 173 |
$this->get_content_timeline_item_gap_css( $attributes, 'Tablet' ), |
| 174 |
$this->get_content_timeline_item_gap_css( $attributes, 'Mobile' ), |
| 175 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_timeline_item_gap_css( $attributes, $device ); } ) |
| 176 |
); |
| 177 |
$css_generator->add_class_styles( |
| 178 |
'{{WRAPPER}} .ablocks-block-content-timeline--outer-wrap', |
| 179 |
$this->get_content_timeline_horizontal_gap_css( $attributes ), |
| 180 |
$this->get_content_timeline_horizontal_gap_css( $attributes, 'Tablet' ), |
| 181 |
$this->get_content_timeline_horizontal_gap_css( $attributes, 'Mobile' ), |
| 182 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_timeline_horizontal_gap_css( $attributes, $device ); } ) |
| 183 |
); |
| 184 |
$css_generator->add_class_styles( |
| 185 |
'{{WRAPPER}} .ablocks-block-content-timeline--outer-wrap .ablocks-block-content-timeline-child--field .ablocks-block-content-timeline-child__content-part', |
| 186 |
$this->get_content_timeline_content_css( $attributes ), |
| 187 |
$this->get_content_timeline_content_css( $attributes, 'Tablet' ), |
| 188 |
$this->get_content_timeline_content_css( $attributes, 'Mobile' ), |
| 189 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_timeline_content_css( $attributes, $device ); } ) |
| 190 |
); |
| 191 |
$css_generator->add_class_styles( |
| 192 |
'{{WRAPPER}} .ablocks-block-content-timeline-child__content-part .ablocks-block-content-timeline-child__arrow::after', |
| 193 |
$this->get_content_timeline_content_background_css( $attributes ), |
| 194 |
$this->get_content_timeline_content_background_css( $attributes, 'Tablet' ), |
| 195 |
$this->get_content_timeline_content_background_css( $attributes, 'Mobile' ), |
| 196 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_timeline_content_background_css( $attributes, $device ); } ) |
| 197 |
); |
| 198 |
$css_generator->add_class_styles( |
| 199 |
'{{WRAPPER}} .ablocks-block-content-timeline--outer-wrap .ablocks__in-view-icon', |
| 200 |
$this->get_content_timeline_connector_alignment_css( $attributes ), |
| 201 |
$this->get_content_timeline_connector_alignment_css( $attributes, 'Tablet' ), |
| 202 |
$this->get_content_timeline_connector_alignment_css( $attributes, 'Mobile' ), |
| 203 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_timeline_connector_alignment_css( $attributes, $device ); } ) |
| 204 |
); |
| 205 |
$css_generator->add_class_styles( |
| 206 |
'{{WRAPPER}} .ablocks-block-content-timeline-child__date', |
| 207 |
$this->get_content_timeline_date_alignment_css( $attributes ), |
| 208 |
$this->get_content_timeline_date_alignment_css( $attributes, 'Tablet' ), |
| 209 |
$this->get_content_timeline_date_alignment_css( $attributes, 'Mobile' ), |
| 210 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_timeline_date_alignment_css( $attributes, $device ); } ) |
| 211 |
); |
| 212 |
// Conditional CSS generation based on arrowAlignment |
| 213 |
|
| 214 |
$css_generator->add_class_styles( |
| 215 |
'{{WRAPPER}} .ablocks-block-content-timeline-child--line-center .ablocks-block-content-timeline-child__arrow', |
| 216 |
$this->get_content_timeline_arrow_css( $attributes ), |
| 217 |
$this->get_content_timeline_arrow_css( $attributes, 'Tablet' ), |
| 218 |
$this->get_content_timeline_arrow_css( $attributes, 'Mobile' ), |
| 219 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_timeline_arrow_css( $attributes, $device ); } ) |
| 220 |
); |
| 221 |
$css_generator->add_class_styles( |
| 222 |
'{{WRAPPER}} .ablocks-block-content-timeline-child__date,.ablocks-block-content-timeline-child__inner-content-date', |
| 223 |
$this->get_content_timeline_date_css( $attributes ), |
| 224 |
$this->get_content_timeline_date_css( $attributes, 'Tablet' ), |
| 225 |
$this->get_content_timeline_date_css( $attributes, 'Mobile' ), |
| 226 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_timeline_date_css( $attributes, $device ); } ) |
| 227 |
); |
| 228 |
$css_generator->add_class_styles( |
| 229 |
'{{WRAPPER}} .ablocks-block-content-timeline-child__inner-content-date', |
| 230 |
$this->get_content_timeline_date_mobile_css( $attributes, 'Mobile' ) |
| 231 |
); |
| 232 |
$css_generator->add_class_styles( |
| 233 |
'{{WRAPPER}} .ablocks-block-content-timeline-child__inner-content-date:hover', |
| 234 |
$this->get_content_timeline_date_hover_mobile_css( $attributes, 'Mobile' ) |
| 235 |
); |
| 236 |
$css_generator->add_class_styles( |
| 237 |
'{{WRAPPER}} .ablocks-block-content-timeline-child__date-inner', |
| 238 |
$this->get_content_timeline_show_date_center_css( $attributes, '' ), |
| 239 |
$this->get_content_timeline_show_date_center_css( $attributes, 'Tablet' ), |
| 240 |
$this->get_content_timeline_show_date_center_css( $attributes, 'Mobile' ), |
| 241 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_timeline_show_date_center_css( $attributes, $device ); } ) |
| 242 |
); |
| 243 |
$css_generator->add_class_styles( |
| 244 |
'{{WRAPPER}} .ablocks-block-content-timeline-child__date', |
| 245 |
$this->get_content_timeline_show_date_left_right_css( $attributes, '' ), |
| 246 |
$this->get_content_timeline_show_date_left_right_css( $attributes, 'Tablet' ), |
| 247 |
$this->get_content_timeline_show_date_left_right_css( $attributes, 'Mobile' ), |
| 248 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_timeline_show_date_left_right_css( $attributes, $device ); } ) |
| 249 |
); |
| 250 |
$css_generator->add_class_styles( |
| 251 |
'{{WRAPPER}} .ablocks-block-content-timeline--left .ablocks-block-content-timeline__line,.ablocks-block-content-timeline--right .ablocks-block-content-timeline__line', |
| 252 |
$this->get_content_timeline_show_date_left_right_line_css( $attributes, '' ), |
| 253 |
$this->get_content_timeline_show_date_left_right_line_css( $attributes, 'Tablet' ), |
| 254 |
$this->get_content_timeline_show_date_left_right_line_css( $attributes, 'Mobile' ), |
| 255 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_timeline_show_date_left_right_line_css( $attributes, $device ); } ) |
| 256 |
); |
| 257 |
$css_generator->add_class_styles( |
| 258 |
'{{WRAPPER}} .ablocks-block-content-timeline-child__inner-content-date', |
| 259 |
$this->get_content_timeline_show_date_mobile_css( $attributes, '' ), |
| 260 |
$this->get_content_timeline_show_date_mobile_css( $attributes, 'Tablet' ), |
| 261 |
$this->get_content_timeline_show_date_mobile_css( $attributes, 'Mobile' ), |
| 262 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_timeline_show_date_mobile_css( $attributes, $device ); } ) |
| 263 |
); |
| 264 |
|
| 265 |
return $css_generator->generate_css(); |
| 266 |
} |
| 267 |
public function build_css( $attributes ) { |
| 268 |
if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) { |
| 269 |
return $this->build_css_v2( $attributes ); |
| 270 |
} |
| 271 |
return $this->build_css_v1( $attributes ); |
| 272 |
} |
| 273 |
// Top / Bottom content positions lay the timeline out horizontally. |
| 274 |
public function is_horizontal_timeline( $attributes ) { |
| 275 |
return in_array( $attributes['contentPosition'] ?? '', [ 'top', 'bottom' ], true ); |
| 276 |
} |
| 277 |
|
| 278 |
public function get_content_timeline_horizontal_gap_css( $attributes, $device = '' ) { |
| 279 |
if ( ! $this->is_horizontal_timeline( $attributes ) ) { |
| 280 |
return []; |
| 281 |
} |
| 282 |
return Range::get_css([ |
| 283 |
'attributeValue' => $attributes['itemGap'], |
| 284 |
'attribute_object_key' => 'value', |
| 285 |
'defaultValue' => 10, |
| 286 |
'isResponsive' => true, |
| 287 |
'hasUnit' => true, |
| 288 |
'unitDefaultValue' => 'px', |
| 289 |
'property' => 'gap', |
| 290 |
'device' => $device, |
| 291 |
]); |
| 292 |
} |
| 293 |
|
| 294 |
public function get_content_timeline_show_date_mobile_css( $attributes, $device = '' ) { |
| 295 |
$css = []; |
| 296 |
if ( $device === '' || $device === 'Tablet' ) { |
| 297 |
$css['display'] = 'none'; |
| 298 |
} |
| 299 |
if ( $device === 'Mobile' ) { |
| 300 |
if ( isset( $attributes[ "showDate{$device}" ] ) && $attributes[ "showDate{$device}" ] === false ) { |
| 301 |
$css['display'] = 'none'; |
| 302 |
} elseif ( isset( $attributes[ "showDate{$device}" ] ) && $attributes[ "showDate{$device}" ] === true ) { |
| 303 |
$css['display'] = 'block'; |
| 304 |
} |
| 305 |
} |
| 306 |
|
| 307 |
return $css; |
| 308 |
} |
| 309 |
public function get_content_timeline_show_date_center_css( $attribute, $device ) { |
| 310 |
$css = []; |
| 311 |
$showDateKey = $device ? "showDate{$device}" : 'showDate'; |
| 312 |
$showDate = $attribute[ $showDateKey ] ?? null; |
| 313 |
$isCentered = $attribute['contentPosition'] === 'center'; |
| 314 |
|
| 315 |
if ( $isCentered ) { |
| 316 |
$css['display'] = $showDate ? 'block' : 'none'; |
| 317 |
} |
| 318 |
|
| 319 |
return $css; |
| 320 |
} |
| 321 |
|
| 322 |
public function get_content_timeline_show_date_left_right_css( $attribute, $device ) { |
| 323 |
$css = []; |
| 324 |
$showDateKey = $device ? "showDate{$device}" : 'showDate'; |
| 325 |
$showDate = $attribute[ $showDateKey ] ?? null; |
| 326 |
$isLeftOrRight = in_array( $attribute['contentPosition'], [ 'left', 'right', 'top', 'bottom' ], true ); |
| 327 |
|
| 328 |
if ( $isLeftOrRight ) { |
| 329 |
if ( $device !== 'Mobile' ) { |
| 330 |
$css['display'] = $showDate ? 'block !important' : 'none !important'; |
| 331 |
} elseif ( $device === 'Mobile' ) { |
| 332 |
$css['display'] = 'none !important'; |
| 333 |
|
| 334 |
} |
| 335 |
} |
| 336 |
if ( $attribute['contentPosition'] === 'center' ) { |
| 337 |
$css['display'] = 'block'; |
| 338 |
} |
| 339 |
|
| 340 |
return $css; |
| 341 |
} |
| 342 |
public function get_content_timeline_show_date_left_right_line_css( $attribute, $device ) { |
| 343 |
$css = []; |
| 344 |
$showDate = $attribute[ "showDate{$device}" ] ?? null; |
| 345 |
if ( $device === 'Mobile' ) { |
| 346 |
// Specific case for mobile content position left/right without date |
| 347 |
if ( $attribute['contentPosition'] === 'left' ) { |
| 348 |
$css['left'] = 'calc(35px / 2) !important'; // fallback for left without date |
| 349 |
} elseif ( $attribute['contentPosition'] === 'right' ) { |
| 350 |
$css['right'] = 'calc(35px / 2) !important'; // fallback for right without date |
| 351 |
} |
| 352 |
} elseif ( $device ) { |
| 353 |
// Non-mobile styles (if needed) |
| 354 |
if ( $attribute['contentPosition'] === 'left' ) { |
| 355 |
$css['left'] = $showDate ? 'calc(30% / 2) !important' : 'calc(61px / 2) !important'; |
| 356 |
$css['right'] = 'auto !important'; |
| 357 |
} elseif ( $attribute['contentPosition'] === 'right' ) { |
| 358 |
$css['right'] = $showDate ? 'calc(30% / 2) !important' : 'calc(61px / 2) !important'; |
| 359 |
$css['left'] = 'auto !important'; |
| 360 |
} |
| 361 |
} else { |
| 362 |
if ( $attribute['contentPosition'] === 'left' ) { |
| 363 |
$css['left'] = $showDate ? 'calc(30% / 2) !important' : 'calc(61px / 2) !important'; |
| 364 |
$css['right'] = 'auto !important'; |
| 365 |
} elseif ( $attribute['contentPosition'] === 'right' ) { |
| 366 |
$css['right'] = $showDate ? 'calc(30% / 2) !important' : 'calc(61px / 2) !important'; |
| 367 |
$css['left'] = 'auto !important'; |
| 368 |
} |
| 369 |
}//end if |
| 370 |
|
| 371 |
return $css; |
| 372 |
} |
| 373 |
public function get_content_timeline_icon_css( $attributes, $device = '' ) { |
| 374 |
$css = []; |
| 375 |
return array_merge( |
| 376 |
[ 'fill' => Color::get_css( isset( $attributes['iconColor'] ) ? $attributes['iconColor'] : '' ) ], |
| 377 |
Range::get_css([ |
| 378 |
'attributeValue' => $attributes['iconSize'], |
| 379 |
'attribute_object_key' => 'value', |
| 380 |
'isResponsive' => true, |
| 381 |
'hasUnit' => true, |
| 382 |
'defaultValue' => 18, |
| 383 |
'unitDefaultValue' => 'px', |
| 384 |
'property' => 'width', |
| 385 |
'device' => $device, |
| 386 |
]), |
| 387 |
Range::get_css([ |
| 388 |
'attributeValue' => $attributes['iconSize'], |
| 389 |
'attribute_object_key' => 'value', |
| 390 |
'isResponsive' => true, |
| 391 |
'hasUnit' => true, |
| 392 |
'defaultValue' => 18, |
| 393 |
'unitDefaultValue' => 'px', |
| 394 |
'property' => 'height', |
| 395 |
'device' => $device, |
| 396 |
]), |
| 397 |
$css, |
| 398 |
); |
| 399 |
} |
| 400 |
|
| 401 |
public function get_content_timeline_icon_background_css( $attributes, $device = '' ) { |
| 402 |
return array_merge( |
| 403 |
[ 'background' => Color::get_css( isset( $attributes['iconBackgroundColor'] ) ? $attributes['iconBackgroundColor'] : '' ) ], |
| 404 |
Range::get_css([ |
| 405 |
'attributeValue' => $attributes['iconBackgroundSize'], |
| 406 |
'attribute_object_key' => 'value', |
| 407 |
'defaultValue' => 48, |
| 408 |
'property' => 'width', |
| 409 |
]), |
| 410 |
Range::get_css([ |
| 411 |
'attributeValue' => $attributes['iconBackgroundSize'], |
| 412 |
'attribute_object_key' => 'value', |
| 413 |
'defaultValue' => 48, |
| 414 |
'property' => 'height', |
| 415 |
]), |
| 416 |
); |
| 417 |
} |
| 418 |
|
| 419 |
public function get_content_timeline_connector_css( $attributes, $device = '' ) { |
| 420 |
return array_merge( |
| 421 |
[ 'background' => Color::get_css( isset( $attributes['thicknessColor'] ) ? $attributes['thicknessColor'] : '' ) ], |
| 422 |
Range::get_css([ |
| 423 |
'attributeValue' => $attributes['thickness'], |
| 424 |
'attribute_object_key' => 'value', |
| 425 |
'defaultValue' => 3, |
| 426 |
'property' => 'width', |
| 427 |
]), |
| 428 |
Range::get_css([ |
| 429 |
'attributeValue' => $attributes['lineLeft'], |
| 430 |
'attribute_object_key' => 'value', |
| 431 |
'isResponsive' => true, |
| 432 |
'hasUnit' => true, |
| 433 |
'defaultValue' => 0, |
| 434 |
'unitDefaultValue' => 'px', |
| 435 |
'property' => 'margin-left', |
| 436 |
'device' => $device, |
| 437 |
]), |
| 438 |
Range::get_css([ |
| 439 |
'attributeValue' => $attributes['lineRight'], |
| 440 |
'attribute_object_key' => 'value', |
| 441 |
'isResponsive' => true, |
| 442 |
'hasUnit' => true, |
| 443 |
'defaultValue' => 0, |
| 444 |
'unitDefaultValue' => 'px', |
| 445 |
'property' => 'margin-right', |
| 446 |
'device' => $device, |
| 447 |
]), |
| 448 |
); |
| 449 |
} |
| 450 |
|
| 451 |
public function get_content_timeline_item_gap_css( $attributes, $device = '' ) { |
| 452 |
if ( $this->is_horizontal_timeline( $attributes ) ) { |
| 453 |
return [ '--ablocks-content-timeline-icon-size' => ( ! empty( $attributes['iconBackgroundSize'] ) ? $attributes['iconBackgroundSize'] : 48 ) . 'px' ]; |
| 454 |
} |
| 455 |
$css = []; |
| 456 |
return array_merge( |
| 457 |
Range::get_css([ |
| 458 |
'attributeValue' => $attributes['itemGap'], |
| 459 |
'attribute_object_key' => 'value', |
| 460 |
'defaultValue' => 10, |
| 461 |
'isResponsive' => true, |
| 462 |
'hasUnit' => true, |
| 463 |
'unitDefaultValue' => 'px', |
| 464 |
'property' => 'margin-top', |
| 465 |
'device' => $device, |
| 466 |
]), |
| 467 |
$css, |
| 468 |
); |
| 469 |
} |
| 470 |
|
| 471 |
public function get_content_timeline_content_css( $attributes, $device = '' ) { |
| 472 |
$css = []; |
| 473 |
$css['padding'] = '15px'; |
| 474 |
return array_merge( |
| 475 |
[ 'background' => Color::get_css( isset( $attributes['contentBackgroundColor'] ) ? $attributes['contentBackgroundColor'] : '' ) ], |
| 476 |
$css, |
| 477 |
Dimensions::get_css( $attributes['contentPadding'] ?? [], 'padding', $device ) |
| 478 |
); |
| 479 |
} |
| 480 |
|
| 481 |
public function get_content_timeline_content_background_css( $attributes, $device = '' ) { |
| 482 |
$css = []; |
| 483 |
if ( ! empty( $attributes['contentBackgroundColor'] ) ) { |
| 484 |
$css['border-left-color'] = Color::get_css( |
| 485 |
isset( $attributes['contentBackgroundColor'] ) ? $attributes['contentBackgroundColor'] : ''); |
| 486 |
$css['border-right-color'] = Color::get_css( |
| 487 |
isset( $attributes['contentBackgroundColor'] ) ? $attributes['contentBackgroundColor'] : ''); |
| 488 |
} |
| 489 |
return $css; |
| 490 |
} |
| 491 |
// public function get_content_timeline_arrow_css( $attributes, $device = '' ) { |
| 492 |
// $css = []; |
| 493 |
// $arrowAlignment = $attributes['arrowAlignment'] ?? ''; |
| 494 |
// $iconBackgroundSize = $attributes['iconBackgroundSize'] ?? ''; |
| 495 |
|
| 496 |
// if ( $arrowAlignment === 'top' ) { |
| 497 |
// $css['height'] = '0px'; |
| 498 |
// $css['top'] = $iconBackgroundSize ? ( $iconBackgroundSize / 2 ) . 'px' : '0'; |
| 499 |
// } elseif ( $arrowAlignment === 'bottom' ) { |
| 500 |
// $css['height'] = $iconBackgroundSize ? ( $iconBackgroundSize / 2 ) . 'px' : '0'; |
| 501 |
// $css['bottom'] = '0'; |
| 502 |
// } |
| 503 |
|
| 504 |
// return $css; |
| 505 |
// } |
| 506 |
|
| 507 |
public function get_content_timeline_arrow_css( $attributes, $device = '' ) { |
| 508 |
$css = []; |
| 509 |
if ( $this->is_horizontal_timeline( $attributes ) ) { |
| 510 |
return $css; |
| 511 |
} |
| 512 |
$arrowAlignment = $attributes['arrowAlignment'] ?? ''; |
| 513 |
$iconBackgroundSize = $attributes['iconBackgroundSize'] ?? ''; |
| 514 |
|
| 515 |
// Existing logic + updated styles |
| 516 |
if ( $arrowAlignment === 'top' ) { |
| 517 |
$css['height'] = '35px'; |
| 518 |
$css['top'] = '10%'; |
| 519 |
$css['transform'] = 'translateY(-50%)'; |
| 520 |
$css['-webkit-transform'] = 'translateY(-50%)'; |
| 521 |
|
| 522 |
} elseif ( $arrowAlignment === 'bottom' ) { |
| 523 |
$css['height'] = '35px'; |
| 524 |
$css['top'] = '90%'; |
| 525 |
$css['transform'] = 'translateY(-50%)'; |
| 526 |
$css['-webkit-transform'] = 'translateY(-50%)'; |
| 527 |
|
| 528 |
} elseif ( $arrowAlignment === 'centre' ) { |
| 529 |
$css['height'] = '35px'; |
| 530 |
$css['top'] = '50%'; |
| 531 |
$css['transform'] = 'translateY(-50%)'; |
| 532 |
$css['-webkit-transform'] = 'translateY(-50%)'; |
| 533 |
} |
| 534 |
|
| 535 |
return $css; |
| 536 |
} |
| 537 |
public function get_content_timeline_connector_alignment_css( $attributes, $device = '' ) { |
| 538 |
$css = []; |
| 539 |
$arrowAlignment = $attributes['arrowAlignment'] ?? ''; |
| 540 |
|
| 541 |
if ( $arrowAlignment === 'top' ) { |
| 542 |
$css['align-self'] = 'flex-start'; |
| 543 |
} elseif ( $arrowAlignment === 'bottom' ) { |
| 544 |
$css['align-self'] = 'flex-end'; |
| 545 |
} else { |
| 546 |
$css['align-self'] = 'center'; |
| 547 |
} |
| 548 |
|
| 549 |
return $css; |
| 550 |
} |
| 551 |
public function get_content_timeline_date_alignment_css( $attributes, $device = '' ) { |
| 552 |
$css = []; |
| 553 |
if ( $this->is_horizontal_timeline( $attributes ) ) { |
| 554 |
return [ |
| 555 |
'align-self' => 'stretch', |
| 556 |
'text-align' => ! empty( $attributes['dateAlign'] ) ? $attributes['dateAlign'] : 'left', |
| 557 |
]; |
| 558 |
} |
| 559 |
|
| 560 |
$arrowAlignment = $attributes['arrowAlignment'] ?? ''; |
| 561 |
$iconBackgroundSize = $attributes['iconBackgroundSize'] ?? ''; |
| 562 |
|
| 563 |
if ( $arrowAlignment === 'top' ) { |
| 564 |
$css['align-self'] = 'flex-start'; |
| 565 |
} elseif ( $arrowAlignment === 'bottom' ) { |
| 566 |
$css['align-self'] = 'flex-end'; |
| 567 |
} else { |
| 568 |
$css['align-self'] = 'center'; |
| 569 |
} |
| 570 |
|
| 571 |
if ( $arrowAlignment === 'top' ) { |
| 572 |
$css['margin-top'] = $iconBackgroundSize ? ( $iconBackgroundSize / 4 ) . 'px' : '0'; |
| 573 |
} elseif ( $arrowAlignment === 'bottom' ) { |
| 574 |
$css['margin-bottom'] = $iconBackgroundSize ? ( $iconBackgroundSize / 4 ) . 'px' : '0'; |
| 575 |
} |
| 576 |
|
| 577 |
return $css; |
| 578 |
} |
| 579 |
|
| 580 |
public function get_content_timeline_date_css( $attributes, $device = '' ) { |
| 581 |
$typographyValueGlobal = $attributes['dateTypographyGlobal'] ? $attributes['dateTypographyGlobal'] : []; |
| 582 |
return array_merge( |
| 583 |
[ 'color' => Color::get_css( isset( $attributes['dateColor'] ) ? $attributes['dateColor'] : '' ) ], |
| 584 |
Typography::get_css( $attributes['dateTypography'] ?? [], '', $device, $typographyValueGlobal ) |
| 585 |
); |
| 586 |
} |
| 587 |
public function get_content_timeline_date_mobile_css( $attributes, $device = '' ) { |
| 588 |
$css = []; |
| 589 |
if ( ! empty( $attributes['dateAlign'] ) ) { |
| 590 |
$css['text-align'] = $attributes['dateAlign']; |
| 591 |
} |
| 592 |
return array_merge( |
| 593 |
[ 'background' => Color::get_css( isset( $attributes['dateBackground'] ) ? $attributes['dateBackground'] : '' ) ], |
| 594 |
$css, |
| 595 |
Dimensions::get_css( $attributes['datePadding'] ?? [], 'padding', $device ), |
| 596 |
Border::get_css( $attributes['dateBorder'] ?? [], '', $device ) |
| 597 |
); |
| 598 |
} |
| 599 |
public function get_content_timeline_date_hover_mobile_css( $attributes, $device = '' ) { |
| 600 |
return array_merge( |
| 601 |
Border::get_hover_css( $attributes['dateBorder'] ?? [], '', $device ) |
| 602 |
); |
| 603 |
} |
| 604 |
} |
| 605 |
|