| 1 |
<?php |
| 2 |
namespace ABlocks\Blocks\Carousel; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
use ABlocks\Classes\BlockBaseAbstract; |
| 9 |
use ABlocks\Classes\CssGenerator; |
| 10 |
use ABlocks\Classes\CssGeneratorV2; |
| 11 |
use ABlocks\Controls\Alignment; |
| 12 |
use ABlocks\Controls\Range; |
| 13 |
use ABlocks\Controls\Dimensions; |
| 14 |
use ABlocks\Controls\Border; |
| 15 |
use ABlocks\Controls\Color; |
| 16 |
use ABlocks\Controls\BoxShadow; |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
class Block extends BlockBaseAbstract { |
| 21 |
protected $block_name = 'carousel'; |
| 22 |
protected $style_depends = [ 'ablocks-swiper-style' ]; |
| 23 |
protected $script_depends = [ 'ablocks-swiper-script' ]; |
| 24 |
|
| 25 |
public function build_css_v1( $attributes ) { |
| 26 |
|
| 27 |
$css_generator = new CssGenerator( $attributes ); |
| 28 |
|
| 29 |
$css_generator->add_class_styles( |
| 30 |
'{{WRAPPER}} .ablocks-carousel-swiper .swiper-wrapper', |
| 31 |
$this->get_carousel_css( $attributes ), |
| 32 |
$this->get_carousel_css( $attributes, 'Tablet' ), |
| 33 |
$this->get_carousel_css( $attributes, 'Mobile' ), |
| 34 |
); |
| 35 |
$css_generator->add_class_styles( |
| 36 |
'{{WRAPPER}} .ablocks-carousel-navigation__button', |
| 37 |
$this->get_navigation_button_css( $attributes ), |
| 38 |
$this->get_navigation_button_css( $attributes, 'Tablet' ), |
| 39 |
$this->get_navigation_button_css( $attributes, 'Mobile' ), |
| 40 |
); |
| 41 |
$css_generator->add_class_styles( |
| 42 |
'{{WRAPPER}} .ablocks-carousel-navigation__button--next', |
| 43 |
$this->get_navigation_next_button_css( $attributes ), |
| 44 |
$this->get_navigation_next_button_css( $attributes, 'Tablet' ), |
| 45 |
$this->get_navigation_next_button_css( $attributes, 'Mobile' ), |
| 46 |
); |
| 47 |
$css_generator->add_class_styles( |
| 48 |
'{{WRAPPER}} .ablocks-carousel-navigation__button--prev', |
| 49 |
$this->get_navigation_prev_button_css( $attributes ), |
| 50 |
$this->get_navigation_prev_button_css( $attributes, 'Tablet' ), |
| 51 |
$this->get_navigation_prev_button_css( $attributes, 'Mobile' ), |
| 52 |
); |
| 53 |
$css_generator->add_class_styles( |
| 54 |
'{{WRAPPER}} .ablocks-carousel-navigation__button .ablocks-icon-wrap', |
| 55 |
$this->get_navigation_icon_css( $attributes ), |
| 56 |
$this->get_navigation_icon_css( $attributes, 'Tablet' ), |
| 57 |
$this->get_navigation_icon_css( $attributes, 'Mobile' ), |
| 58 |
); |
| 59 |
|
| 60 |
$css_generator->add_class_styles( |
| 61 |
'{{WRAPPER}} .ablocks-carousel-pagination', |
| 62 |
$this->get_pagination_parent_css( $attributes ), |
| 63 |
$this->get_pagination_parent_css( $attributes, 'Tablet' ), |
| 64 |
$this->get_pagination_parent_css( $attributes, 'Mobile' ) |
| 65 |
); |
| 66 |
$css_generator->add_class_styles( |
| 67 |
'{{WRAPPER}} .swiper-pagination-bullet', |
| 68 |
$this->get_pagination_color_css( $attributes ), |
| 69 |
$this->get_pagination_color_css( $attributes, 'Tablet' ), |
| 70 |
$this->get_pagination_color_css( $attributes, 'Mobile' ) |
| 71 |
); |
| 72 |
$css_generator->add_class_styles( |
| 73 |
'{{WRAPPER}} .swiper-pagination-bullet:hover', |
| 74 |
$this->get_pagination_color_hover_css( $attributes ), |
| 75 |
$this->get_pagination_color_hover_css( $attributes, 'Tablet' ), |
| 76 |
$this->get_pagination_color_hover_css( $attributes, 'Mobile' ) |
| 77 |
); |
| 78 |
|
| 79 |
$css_generator->add_class_styles( |
| 80 |
'{{WRAPPER}} .swiper-pagination-bullet.swiper-pagination-bullet-active', |
| 81 |
$this->get_pagination_active_color_css( $attributes ), |
| 82 |
$this->get_pagination_active_color_css( $attributes, 'Tablet' ), |
| 83 |
$this->get_pagination_active_color_css( $attributes, 'Mobile' ) |
| 84 |
); |
| 85 |
$css_generator->add_class_styles( |
| 86 |
'{{WRAPPER}} .swiper-pagination-bullet.swiper-pagination-bullet-active:hover', |
| 87 |
$this->get_pagination_active_color_hover_css( $attributes ), |
| 88 |
$this->get_pagination_active_color_hover_css( $attributes, 'Tablet' ), |
| 89 |
$this->get_pagination_active_color_hover_css( $attributes, 'Mobile' ) |
| 90 |
); |
| 91 |
|
| 92 |
$css_generator->add_class_styles( |
| 93 |
'{{WRAPPER}} .ablocks-carousel-navigation__button .ablocks-svg-icon', |
| 94 |
$this->get_navigation_icon_svg_css( $attributes ), |
| 95 |
$this->get_navigation_icon_svg_css( $attributes, 'Tablet' ), |
| 96 |
$this->get_navigation_icon_svg_css( $attributes, 'Mobile' ) |
| 97 |
); |
| 98 |
$css_generator->add_class_styles( |
| 99 |
'{{WRAPPER}} .ablocks-carousel-navigation__button .ablocks-svg-icon:hover', |
| 100 |
$this->get_navigation_icon_svg_hover_css( $attributes ), |
| 101 |
$this->get_navigation_icon_svg_hover_css( $attributes, 'Tablet' ), |
| 102 |
$this->get_navigation_icon_svg_hover_css( $attributes, 'Mobile' ) |
| 103 |
); |
| 104 |
return $css_generator->generate_css(); |
| 105 |
} |
| 106 |
|
| 107 |
public function build_css_v2( $attributes ) { |
| 108 |
|
| 109 |
$css_generator = new CssGeneratorV2( $attributes, $this->block_name ); |
| 110 |
|
| 111 |
$css_generator->add_class_styles( |
| 112 |
'{{WRAPPER}} .ablocks-carousel-swiper .swiper-wrapper', |
| 113 |
$this->get_carousel_css( $attributes ), |
| 114 |
$this->get_carousel_css( $attributes, 'Tablet' ), |
| 115 |
$this->get_carousel_css( $attributes, 'Mobile' ), |
| 116 |
); |
| 117 |
$css_generator->add_class_styles( |
| 118 |
'{{WRAPPER}} .ablocks-carousel-navigation__button', |
| 119 |
$this->get_navigation_button_css( $attributes ), |
| 120 |
$this->get_navigation_button_css( $attributes, 'Tablet' ), |
| 121 |
$this->get_navigation_button_css( $attributes, 'Mobile' ), |
| 122 |
); |
| 123 |
$css_generator->add_class_styles( |
| 124 |
'{{WRAPPER}} .ablocks-carousel-navigation__button--next', |
| 125 |
$this->get_navigation_next_button_css( $attributes ), |
| 126 |
$this->get_navigation_next_button_css( $attributes, 'Tablet' ), |
| 127 |
$this->get_navigation_next_button_css( $attributes, 'Mobile' ), |
| 128 |
); |
| 129 |
$css_generator->add_class_styles( |
| 130 |
'{{WRAPPER}} .ablocks-carousel-navigation__button--prev', |
| 131 |
$this->get_navigation_prev_button_css( $attributes ), |
| 132 |
$this->get_navigation_prev_button_css( $attributes, 'Tablet' ), |
| 133 |
$this->get_navigation_prev_button_css( $attributes, 'Mobile' ), |
| 134 |
); |
| 135 |
$css_generator->add_class_styles( |
| 136 |
'{{WRAPPER}} .ablocks-carousel-navigation__button .ablocks-icon-wrap', |
| 137 |
$this->get_navigation_icon_css( $attributes ), |
| 138 |
$this->get_navigation_icon_css( $attributes, 'Tablet' ), |
| 139 |
$this->get_navigation_icon_css( $attributes, 'Mobile' ), |
| 140 |
); |
| 141 |
|
| 142 |
$css_generator->add_class_styles( |
| 143 |
'{{WRAPPER}} .ablocks-carousel-pagination', |
| 144 |
$this->get_pagination_parent_css( $attributes ), |
| 145 |
$this->get_pagination_parent_css( $attributes, 'Tablet' ), |
| 146 |
$this->get_pagination_parent_css( $attributes, 'Mobile' ) |
| 147 |
); |
| 148 |
$css_generator->add_class_styles( |
| 149 |
'{{WRAPPER}} .swiper-pagination-bullet', |
| 150 |
$this->get_pagination_color_css( $attributes ), |
| 151 |
$this->get_pagination_color_css( $attributes, 'Tablet' ), |
| 152 |
$this->get_pagination_color_css( $attributes, 'Mobile' ) |
| 153 |
); |
| 154 |
$css_generator->add_class_styles( |
| 155 |
'{{WRAPPER}} .swiper-pagination-bullet:hover', |
| 156 |
$this->get_pagination_color_hover_css( $attributes ), |
| 157 |
$this->get_pagination_color_hover_css( $attributes, 'Tablet' ), |
| 158 |
$this->get_pagination_color_hover_css( $attributes, 'Mobile' ) |
| 159 |
); |
| 160 |
|
| 161 |
$css_generator->add_class_styles( |
| 162 |
'{{WRAPPER}} .swiper-pagination-bullet.swiper-pagination-bullet-active', |
| 163 |
$this->get_pagination_active_color_css( $attributes ), |
| 164 |
$this->get_pagination_active_color_css( $attributes, 'Tablet' ), |
| 165 |
$this->get_pagination_active_color_css( $attributes, 'Mobile' ) |
| 166 |
); |
| 167 |
$css_generator->add_class_styles( |
| 168 |
'{{WRAPPER}} .swiper-pagination-bullet.swiper-pagination-bullet-active:hover', |
| 169 |
$this->get_pagination_active_color_hover_css( $attributes ), |
| 170 |
$this->get_pagination_active_color_hover_css( $attributes, 'Tablet' ), |
| 171 |
$this->get_pagination_active_color_hover_css( $attributes, 'Mobile' ) |
| 172 |
); |
| 173 |
|
| 174 |
$css_generator->add_class_styles( |
| 175 |
'{{WRAPPER}} .ablocks-carousel-navigation__button .ablocks-svg-icon', |
| 176 |
$this->get_navigation_icon_svg_css( $attributes ), |
| 177 |
$this->get_navigation_icon_svg_css( $attributes, 'Tablet' ), |
| 178 |
$this->get_navigation_icon_svg_css( $attributes, 'Mobile' ) |
| 179 |
); |
| 180 |
$css_generator->add_class_styles( |
| 181 |
'{{WRAPPER}} .ablocks-carousel-navigation__button .ablocks-svg-icon:hover', |
| 182 |
$this->get_navigation_icon_svg_hover_css( $attributes ), |
| 183 |
$this->get_navigation_icon_svg_hover_css( $attributes, 'Tablet' ), |
| 184 |
$this->get_navigation_icon_svg_hover_css( $attributes, 'Mobile' ) |
| 185 |
); |
| 186 |
return $css_generator->generate_css(); |
| 187 |
} |
| 188 |
public function build_css( $attributes ) { |
| 189 |
if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) { |
| 190 |
return $this->build_css_v2( $attributes ); |
| 191 |
} |
| 192 |
return $this->build_css_v1( $attributes ); |
| 193 |
} |
| 194 |
|
| 195 |
public function get_carousel_css( $attributes, $device = '' ) { |
| 196 |
$carousel_css = []; |
| 197 |
// Temporary approch instead of attribute migration. Might remove it in future |
| 198 |
$verticalAlign = isset( $attributes['verticalAlign'][ 'value' . $device ] ) ? $attributes['verticalAlign'][ 'value' . $device ] : ''; |
| 199 |
if ( |
| 200 |
! isset( $attributes['verticalAlign'] ) |
| 201 |
|| ( |
| 202 |
$attributes['verticalAlignment'] !== '' && $attributes['verticalAlignment'] !== 'center' |
| 203 |
) |
| 204 |
) { |
| 205 |
$attributes['verticalAlign'][ 'value' . $device ] = $attributes['verticalAlignment']; |
| 206 |
$attributes['verticalAlignment'] = ''; |
| 207 |
} elseif ( |
| 208 |
$attributes['verticalAlignment'] !== '' && $attributes['verticalAlignment'] === 'center' |
| 209 |
) { |
| 210 |
$attributes['verticalAlignment'] = ''; |
| 211 |
} |
| 212 |
// Temporary approch instead of attribute migration. Might remove it in future |
| 213 |
|
| 214 |
if ( ! empty( $attributes['verticalAlign'][ 'value' . $device ] ) ) { |
| 215 |
$carousel_css['align-items'] = $attributes['verticalAlign'][ 'value' . $device ]; |
| 216 |
} |
| 217 |
|
| 218 |
return array_merge( |
| 219 |
Range::get_css([ |
| 220 |
'attributeValue' => $attributes['carouselHeight'], |
| 221 |
'attribute_object_key' => 'value', |
| 222 |
'isResponsive' => true, |
| 223 |
'defaultValue' => 300, |
| 224 |
'hasUnit' => true, |
| 225 |
'unitDefaultValue' => 'px', |
| 226 |
'property' => 'min-height', |
| 227 |
'device' => $device, |
| 228 |
]), |
| 229 |
$carousel_css, |
| 230 |
); |
| 231 |
} |
| 232 |
|
| 233 |
|
| 234 |
public function get_navigation_button_css( $attributes, $device = '' ) { |
| 235 |
$navigation_button_css = []; |
| 236 |
|
| 237 |
return array_merge( |
| 238 |
Range::get_css([ |
| 239 |
'attributeValue' => $attributes['navigationIconPositionY'], |
| 240 |
'attribute_object_key' => 'value', |
| 241 |
'defaultValue' => 50, |
| 242 |
'isResponsive' => true, |
| 243 |
'hasUnit' => true, |
| 244 |
'unitDefaultValue' => '%', |
| 245 |
'property' => 'top', |
| 246 |
'device' => $device, |
| 247 |
]), |
| 248 |
$navigation_button_css, |
| 249 |
); |
| 250 |
} |
| 251 |
|
| 252 |
|
| 253 |
public function get_navigation_prev_button_css( $attributes, $device = '' ) { |
| 254 |
$navigation_prev_button_css = []; |
| 255 |
|
| 256 |
return array_merge( |
| 257 |
Range::get_css([ |
| 258 |
'attributeValue' => $attributes['navigationIconPositionPrevX'], |
| 259 |
'attribute_object_key' => 'value', |
| 260 |
'defaultValue' => -3, |
| 261 |
'hasUnit' => true, |
| 262 |
'isResponsive' => true, |
| 263 |
'unitDefaultValue' => '%', |
| 264 |
'property' => 'left', |
| 265 |
'device' => $device, |
| 266 |
]), |
| 267 |
$navigation_prev_button_css, |
| 268 |
); |
| 269 |
} |
| 270 |
|
| 271 |
public function get_navigation_next_button_css( $attributes, $device = '' ) { |
| 272 |
$navigation_next_button_css = []; |
| 273 |
|
| 274 |
return array_merge( |
| 275 |
Range::get_css([ |
| 276 |
'attributeValue' => $attributes['navigationIconPositionNextX'], |
| 277 |
'attribute_object_key' => 'value', |
| 278 |
'defaultValue' => -3, |
| 279 |
'isResponsive' => true, |
| 280 |
'hasUnit' => true, |
| 281 |
'unitDefaultValue' => '%', |
| 282 |
'property' => 'right', |
| 283 |
'device' => $device, |
| 284 |
]), |
| 285 |
$navigation_next_button_css, |
| 286 |
); |
| 287 |
} |
| 288 |
|
| 289 |
|
| 290 |
public function get_navigation_icon_css( $attributes, $device = '' ) { |
| 291 |
$navigation_icon_css = []; |
| 292 |
|
| 293 |
return array_merge( |
| 294 |
Range::get_css([ |
| 295 |
'attributeValue' => $attributes['navigationIconSize'], |
| 296 |
'attribute_object_key' => 'value', |
| 297 |
'defaultValue' => 35, |
| 298 |
'isResponsive' => true, |
| 299 |
'hasUnit' => true, |
| 300 |
'unitDefaultValue' => 'px', |
| 301 |
'property' => 'font-size', |
| 302 |
'device' => $device, |
| 303 |
]), |
| 304 |
$navigation_icon_css, |
| 305 |
); |
| 306 |
} |
| 307 |
|
| 308 |
|
| 309 |
public function get_navigation_icon_svg_css( $attributes, $device = '' ) { |
| 310 |
$navigation_icon_svg_css = []; |
| 311 |
if ( isset( $attributes['navigationIconColor'] ) ) { |
| 312 |
$navigation_icon_svg_css['fill'] = Color::get_css( isset( $attributes['navigationIconColor'] ) ? $attributes['navigationIconColor'] : '' ); |
| 313 |
}; |
| 314 |
if ( isset( $attributes['navigationIconBgColor'] ) ) { |
| 315 |
$navigation_icon_svg_css['background-color'] = Color::get_css( isset( $attributes['navigationIconBgColor'] ) ? $attributes['navigationIconBgColor'] : '' ); |
| 316 |
}; |
| 317 |
return array_merge( |
| 318 |
$navigation_icon_svg_css, |
| 319 |
Dimensions::get_css( $attributes['navigationIconPadding'], 'padding', $device ), |
| 320 |
Border::get_css( $attributes['navigationIconBorder'], '', $device ), |
| 321 |
BoxShadow::get_css( $attributes['navigationIconBoxShadow'], $device ), |
| 322 |
); |
| 323 |
} |
| 324 |
public function get_navigation_icon_svg_hover_css( $attributes, $device = '' ) { |
| 325 |
$navigation_icon_svg_hover_css = []; |
| 326 |
if ( isset( $attributes['navigationIconColorH'] ) ) { |
| 327 |
$navigation_icon_svg_hover_css['fill'] = Color::get_css( isset( $attributes['navigationIconColorH'] ) ? $attributes['navigationIconColorH'] : '' ); |
| 328 |
}; |
| 329 |
if ( isset( $attributes['navigationIconBgColorH'] ) ) { |
| 330 |
$navigation_icon_svg_hover_css['background-color'] = Color::get_css( isset( $attributes['navigationIconBgColorH'] ) ? $attributes['navigationIconBgColorH'] : '' ); |
| 331 |
}; |
| 332 |
return array_merge( |
| 333 |
Range::get_css([ |
| 334 |
'attributeValue' => $attributes['navigationIconTransition'], |
| 335 |
'attribute_object_key' => 'value', |
| 336 |
'defaultValue' => 10, |
| 337 |
'unitDefaultValue' => 's', |
| 338 |
'property' => 'transition-duration', |
| 339 |
'device' => $device, |
| 340 |
]), |
| 341 |
$navigation_icon_svg_hover_css, |
| 342 |
Border::get_hover_css( $attributes['navigationIconBorder'], '', $device ), |
| 343 |
BoxShadow::get_hover_css( $attributes['navigationIconBoxShadow'], '', $device ), |
| 344 |
); |
| 345 |
} |
| 346 |
|
| 347 |
public function get_pagination_parent_css( $attributes, $device = '' ) { |
| 348 |
return array_merge( |
| 349 |
Range::get_css([ |
| 350 |
'attributeValue' => $attributes['paginationPositionX'], |
| 351 |
'attribute_object_key' => 'value', |
| 352 |
'defaultValue' => 47, |
| 353 |
'isResponsive' => true, |
| 354 |
'hasUnit' => true, |
| 355 |
'unitDefaultValue' => '%', |
| 356 |
'property' => 'left', |
| 357 |
'device' => $device, |
| 358 |
]), |
| 359 |
Range::get_css([ |
| 360 |
'attributeValue' => $attributes['paginationPositionY'], |
| 361 |
'attribute_object_key' => 'value', |
| 362 |
'defaultValue' => 100, |
| 363 |
'isResponsive' => true, |
| 364 |
'hasUnit' => true, |
| 365 |
'unitDefaultValue' => '%', |
| 366 |
'property' => 'top', |
| 367 |
'device' => $device, |
| 368 |
]), |
| 369 |
); |
| 370 |
} |
| 371 |
public function get_pagination_color_css( $attributes, $device = '' ) { |
| 372 |
$pagination_color_css = []; |
| 373 |
$type = isset( $attributes['paginationType'] ) ? $attributes['paginationType'] : 'default'; |
| 374 |
$pagination_color_css = []; |
| 375 |
if ( isset( $attributes['paginationColor'] ) ) { |
| 376 |
$color = Color::get_css( $attributes['paginationColor'] ); |
| 377 |
if ( $type === 'default' ) { |
| 378 |
$pagination_color_css['background-color'] = $color; |
| 379 |
} elseif ( $type === 'border1' || $type === 'border3' ) { |
| 380 |
$pagination_color_css['border-color'] = $color; |
| 381 |
$pagination_color_css['background-color'] = 'transparent'; |
| 382 |
} elseif ( $type === 'border2' ) { |
| 383 |
$pagination_color_css['background-color'] = $color; |
| 384 |
$pagination_color_css['border-color'] = $color; |
| 385 |
} |
| 386 |
} |
| 387 |
if ( $type === 'border3' ) { |
| 388 |
$dims = $this->get_ellipse_dims( $attributes['paginationSize'], $device ); |
| 389 |
$pagination_color_css['width'] = $dims['width']; |
| 390 |
$pagination_color_css['height'] = $dims['height']; |
| 391 |
$pagination_color_css['border-radius'] = '9999px'; |
| 392 |
} |
| 393 |
return array_merge( |
| 394 |
$pagination_color_css, |
| 395 |
( $type === 'border3' ? [] : Range::get_css([ |
| 396 |
'attributeValue' => $attributes['paginationSize'], |
| 397 |
'attribute_object_key' => 'value', |
| 398 |
'defaultValue' => 8, |
| 399 |
'isResponsive' => true, |
| 400 |
'hasUnit' => true, |
| 401 |
'unitDefaultValue' => 'px', |
| 402 |
'property' => 'width', |
| 403 |
'device' => $device, |
| 404 |
]) ), |
| 405 |
( $type === 'border3' ? [] : Range::get_css([ |
| 406 |
'attributeValue' => $attributes['paginationSize'], |
| 407 |
'attribute_object_key' => 'value', |
| 408 |
'defaultValue' => 8, |
| 409 |
'isResponsive' => true, |
| 410 |
'hasUnit' => true, |
| 411 |
'unitDefaultValue' => 'px', |
| 412 |
'property' => 'height', |
| 413 |
'device' => $device, |
| 414 |
]) ), |
| 415 |
Border::get_css( $attributes['paginationBorder'], '', $device ), |
| 416 |
); |
| 417 |
} |
| 418 |
public function get_pagination_color_hover_css( $attributes, $device = '' ) { |
| 419 |
$pagination_color_css = []; |
| 420 |
if ( isset( $attributes['paginationHoverColor'] ) ) { |
| 421 |
$pagination_color_css['background-color'] = $attributes['paginationHoverColor']; |
| 422 |
}; |
| 423 |
$type = isset( $attributes['paginationType'] ) ? $attributes['paginationType'] : 'default'; |
| 424 |
$pagination_color_css = []; |
| 425 |
if ( isset( $attributes['paginationHoverColor'] ) ) { |
| 426 |
$color = Color::get_css( $attributes['paginationHoverColor'] ); |
| 427 |
if ( $type === 'default' ) { |
| 428 |
$pagination_color_css['background-color'] = $color; |
| 429 |
} elseif ( $type === 'border1' || $type === 'border3' ) { |
| 430 |
$pagination_color_css['border-color'] = $color; |
| 431 |
$pagination_color_css['background-color'] = $color; |
| 432 |
} elseif ( $type === 'border2' ) { |
| 433 |
$pagination_color_css['background-color'] = 'transparent'; |
| 434 |
$pagination_color_css['border-color'] = $color; |
| 435 |
} |
| 436 |
} |
| 437 |
if ( $type === 'border3' ) { |
| 438 |
$dims = $this->get_ellipse_dims( $attributes['paginationHoverSize'], $device ); |
| 439 |
$pagination_color_css['width'] = $dims['width']; |
| 440 |
$pagination_color_css['height'] = $dims['height']; |
| 441 |
$pagination_color_css['border-radius'] = '9999px'; |
| 442 |
} |
| 443 |
return array_merge( |
| 444 |
$pagination_color_css, |
| 445 |
( $type === 'border3' ? [] : Range::get_css([ |
| 446 |
'attributeValue' => $attributes['paginationHoverSize'], |
| 447 |
'attribute_object_key' => 'value', |
| 448 |
'defaultValue' => 8, |
| 449 |
'isResponsive' => true, |
| 450 |
'hasUnit' => true, |
| 451 |
'unitDefaultValue' => 'px', |
| 452 |
'property' => 'width', |
| 453 |
'device' => $device, |
| 454 |
]) ), |
| 455 |
( $type === 'border3' ? [] : Range::get_css([ |
| 456 |
'attributeValue' => $attributes['paginationHoverSize'], |
| 457 |
'attribute_object_key' => 'value', |
| 458 |
'defaultValue' => 8, |
| 459 |
'isResponsive' => true, |
| 460 |
'hasUnit' => true, |
| 461 |
'unitDefaultValue' => 'px', |
| 462 |
'property' => 'height', |
| 463 |
'device' => $device, |
| 464 |
]) ), |
| 465 |
Border::get_hover_css( $attributes['paginationBorder'], '', $device ), |
| 466 |
); |
| 467 |
} |
| 468 |
|
| 469 |
public function get_pagination_active_color_css( $attributes, $device = '' ) { |
| 470 |
$pagination_active_color_css = []; |
| 471 |
$type = isset( $attributes['paginationType'] ) ? $attributes['paginationType'] : 'default'; |
| 472 |
$pagination_active_color_css = []; |
| 473 |
if ( isset( $attributes['paginationActiveColor'] ) ) { |
| 474 |
$color = Color::get_css( $attributes['paginationActiveColor'] ); |
| 475 |
if ( $type === 'default' ) { |
| 476 |
$pagination_active_color_css['background-color'] = $color; |
| 477 |
} elseif ( $type === 'border1' || $type === 'border3' ) { |
| 478 |
$pagination_active_color_css['background-color'] = $color; |
| 479 |
$pagination_active_color_css['border-color'] = $color; |
| 480 |
} elseif ( $type === 'border2' ) { |
| 481 |
$pagination_active_color_css['border-color'] = $color; |
| 482 |
$pagination_active_color_css['background-color'] = 'transparent'; |
| 483 |
} |
| 484 |
} |
| 485 |
if ( $type === 'border3' ) { |
| 486 |
$dims = $this->get_ellipse_dims( $attributes['paginationActiveSize'], $device ); |
| 487 |
$pagination_active_color_css['width'] = $dims['width']; |
| 488 |
$pagination_active_color_css['height'] = $dims['height']; |
| 489 |
$pagination_active_color_css['border-radius'] = '9999px'; |
| 490 |
} |
| 491 |
return array_merge( |
| 492 |
$pagination_active_color_css, |
| 493 |
( $type === 'border3' ? [] : Range::get_css([ |
| 494 |
'attributeValue' => $attributes['paginationActiveSize'], |
| 495 |
'attribute_object_key' => 'value', |
| 496 |
'defaultValue' => 8, |
| 497 |
'isResponsive' => true, |
| 498 |
'hasUnit' => true, |
| 499 |
'unitDefaultValue' => 'px', |
| 500 |
'property' => 'width', |
| 501 |
'device' => $device, |
| 502 |
]) ), |
| 503 |
( $type === 'border3' ? [] : Range::get_css([ |
| 504 |
'attributeValue' => $attributes['paginationActiveSize'], |
| 505 |
'attribute_object_key' => 'value', |
| 506 |
'defaultValue' => 8, |
| 507 |
'isResponsive' => true, |
| 508 |
'hasUnit' => true, |
| 509 |
'unitDefaultValue' => 'px', |
| 510 |
'property' => 'height', |
| 511 |
'device' => $device, |
| 512 |
]) ), |
| 513 |
Border::get_css( $attributes['activePaginationBorder'], '', $device ), |
| 514 |
); |
| 515 |
} |
| 516 |
public function get_pagination_active_color_hover_css( $attributes, $device = '' ) { |
| 517 |
$pagination_active_color_css = []; |
| 518 |
$type = isset( $attributes['paginationType'] ) ? $attributes['paginationType'] : 'default'; |
| 519 |
$pagination_active_color_css = []; |
| 520 |
if ( isset( $attributes['paginationActiveHoverColor'] ) ) { |
| 521 |
$color = Color::get_css( $attributes['paginationActiveHoverColor'] ); |
| 522 |
if ( $type === 'default' ) { |
| 523 |
$pagination_active_color_css['background-color'] = $color; |
| 524 |
} elseif ( $type === 'border1' || $type === 'border3' ) { |
| 525 |
$pagination_active_color_css['border-color'] = $color; |
| 526 |
$pagination_active_color_css['background-color'] = 'transparent'; |
| 527 |
} elseif ( $type === 'border2' ) { |
| 528 |
$pagination_active_color_css['background-color'] = $color; |
| 529 |
$pagination_active_color_css['border-color'] = $color; |
| 530 |
} |
| 531 |
} |
| 532 |
if ( $type === 'border3' ) { |
| 533 |
$dims = $this->get_ellipse_dims( $attributes['paginationActiveHoverSize'], $device ); |
| 534 |
$pagination_active_color_css['width'] = $dims['width']; |
| 535 |
$pagination_active_color_css['height'] = $dims['height']; |
| 536 |
$pagination_active_color_css['border-radius'] = '9999px'; |
| 537 |
} |
| 538 |
|
| 539 |
return array_merge( |
| 540 |
$pagination_active_color_css, |
| 541 |
( $type === 'border3' ? [] : Range::get_css([ |
| 542 |
'attributeValue' => $attributes['paginationActiveHoverSize'], |
| 543 |
'attribute_object_key' => 'value', |
| 544 |
'defaultValue' => 8, |
| 545 |
'isResponsive' => true, |
| 546 |
'hasUnit' => true, |
| 547 |
'unitDefaultValue' => 'px', |
| 548 |
'property' => 'width', |
| 549 |
'device' => $device, |
| 550 |
]) ), |
| 551 |
( $type === 'border3' ? [] : Range::get_css([ |
| 552 |
'attributeValue' => $attributes['paginationActiveHoverSize'], |
| 553 |
'attribute_object_key' => 'value', |
| 554 |
'defaultValue' => 8, |
| 555 |
'isResponsive' => true, |
| 556 |
'hasUnit' => true, |
| 557 |
'unitDefaultValue' => 'px', |
| 558 |
'property' => 'height', |
| 559 |
'device' => $device, |
| 560 |
]) ), |
| 561 |
Border::get_hover_css( $attributes['activePaginationBorder'], '', $device ), |
| 562 |
); |
| 563 |
} |
| 564 |
|
| 565 |
private function get_ellipse_dims( $sizeAttr, $device = '', $default = 8, $ratio = 1.8 ) { |
| 566 |
$vKey = 'value' . $device; |
| 567 |
$uKey = 'valueUnit' . $device; |
| 568 |
|
| 569 |
$v = isset( $sizeAttr[ $vKey ] ) ? floatval( $sizeAttr[ $vKey ] ) |
| 570 |
: ( isset( $sizeAttr['value'] ) ? floatval( $sizeAttr['value'] ) : $default ); |
| 571 |
$u = isset( $sizeAttr[ $uKey ] ) ? $sizeAttr[ $uKey ] |
| 572 |
: ( isset( $sizeAttr['valueUnit'] ) ? $sizeAttr['valueUnit'] : 'px' ); |
| 573 |
|
| 574 |
return [ |
| 575 |
'height' => $v . $u, |
| 576 |
'width' => ( $v * $ratio ) . $u, |
| 577 |
]; |
| 578 |
} |
| 579 |
|
| 580 |
|
| 581 |
} |
| 582 |
|