| 1 |
<?php |
| 2 |
namespace ABlocks\Blocks\Carousel; |
| 3 |
|
| 4 |
use ABlocks\Classes\BlockBaseAbstract; |
| 5 |
use ABlocks\Classes\CssGenerator; |
| 6 |
use ABlocks\Controls\Alignment; |
| 7 |
use ABlocks\Controls\Range; |
| 8 |
use ABlocks\Controls\Dimensions; |
| 9 |
use ABlocks\Controls\Border; |
| 10 |
|
| 11 |
|
| 12 |
class Block extends BlockBaseAbstract { |
| 13 |
protected $block_name = 'carousel'; |
| 14 |
protected $style_depends = [ 'ablocks-swiper-style' ]; |
| 15 |
protected $script_depends = [ 'ablocks-swiper-script' ]; |
| 16 |
|
| 17 |
public function build_css( $attributes ) { |
| 18 |
|
| 19 |
$css_generator = new CssGenerator( $attributes ); |
| 20 |
|
| 21 |
$css_generator->add_class_styles( |
| 22 |
'{{WRAPPER}} .ablocks-carousel-swiper .swiper-wrapper', |
| 23 |
$this->get_carousel_css( $attributes ), |
| 24 |
$this->get_carousel_css( $attributes, 'Tablet' ), |
| 25 |
$this->get_carousel_css( $attributes, 'Mobile' ), |
| 26 |
); |
| 27 |
$css_generator->add_class_styles( |
| 28 |
'{{WRAPPER}} .ablocks-carousel-navigation__button', |
| 29 |
$this->get_navigation_button_css( $attributes ), |
| 30 |
$this->get_navigation_button_css( $attributes, 'Tablet' ), |
| 31 |
$this->get_navigation_button_css( $attributes, 'Mobile' ), |
| 32 |
); |
| 33 |
$css_generator->add_class_styles( |
| 34 |
'{{WRAPPER}} .ablocks-carousel-navigation__button--next', |
| 35 |
$this->get_navigation_next_button_css( $attributes ), |
| 36 |
$this->get_navigation_next_button_css( $attributes, 'Tablet' ), |
| 37 |
$this->get_navigation_next_button_css( $attributes, 'Mobile' ), |
| 38 |
); |
| 39 |
$css_generator->add_class_styles( |
| 40 |
'{{WRAPPER}} .ablocks-carousel-navigation__button--prev', |
| 41 |
$this->get_navigation_prev_button_css( $attributes ), |
| 42 |
$this->get_navigation_prev_button_css( $attributes, 'Tablet' ), |
| 43 |
$this->get_navigation_prev_button_css( $attributes, 'Mobile' ), |
| 44 |
); |
| 45 |
$css_generator->add_class_styles( |
| 46 |
'{{WRAPPER}} .ablocks-carousel-navigation__button .ablocks-icon-wrap', |
| 47 |
$this->get_navigation_icon_css( $attributes ), |
| 48 |
$this->get_navigation_icon_css( $attributes, 'Tablet' ), |
| 49 |
$this->get_navigation_icon_css( $attributes, 'Mobile' ), |
| 50 |
); |
| 51 |
$css_generator->add_class_styles( |
| 52 |
'{{WRAPPER}} .swiper-pagination-bullet', |
| 53 |
$this->get_pagination_color_css( $attributes ), |
| 54 |
$this->get_pagination_color_css( $attributes, 'Tablet' ), |
| 55 |
$this->get_pagination_color_css( $attributes, 'Mobile' ) |
| 56 |
); |
| 57 |
|
| 58 |
$css_generator->add_class_styles( |
| 59 |
'{{WRAPPER}} .swiper-pagination-bullet.swiper-pagination-bullet-active', |
| 60 |
$this->get_pagination_active_color_css( $attributes ), |
| 61 |
$this->get_pagination_active_color_css( $attributes, 'Tablet' ), |
| 62 |
$this->get_pagination_active_color_css( $attributes, 'Mobile' ) |
| 63 |
); |
| 64 |
|
| 65 |
$css_generator->add_class_styles( |
| 66 |
'{{WRAPPER}} .ablocks-carousel-navigation__button .ablocks-svg-icon', |
| 67 |
$this->get_navigation_icon_svg_css( $attributes ), |
| 68 |
$this->get_navigation_icon_svg_css( $attributes, 'Tablet' ), |
| 69 |
$this->get_navigation_icon_svg_css( $attributes, 'Mobile' ) |
| 70 |
); |
| 71 |
$css_generator->add_class_styles( |
| 72 |
'{{WRAPPER}} .ablocks-carousel-navigation__button .ablocks-svg-icon:hover', |
| 73 |
$this->get_navigation_icon_svg_hover_css( $attributes ), |
| 74 |
$this->get_navigation_icon_svg_hover_css( $attributes, 'Tablet' ), |
| 75 |
$this->get_navigation_icon_svg_hover_css( $attributes, 'Mobile' ) |
| 76 |
); |
| 77 |
return $css_generator->generate_css(); |
| 78 |
} |
| 79 |
|
| 80 |
public function get_carousel_css( $attributes, $device = '' ) { |
| 81 |
$carousel_css = []; |
| 82 |
if ( ! empty( $attributes['verticalAlignment'] ) ) { |
| 83 |
$carousel_css['align-items'] = $attributes['verticalAlignment']; |
| 84 |
} |
| 85 |
|
| 86 |
return array_merge( |
| 87 |
Range::get_css([ |
| 88 |
'attributeValue' => $attributes['carouselHeight'], |
| 89 |
'attribute_object_key' => 'value', |
| 90 |
'isResponsive' => true, |
| 91 |
'defaultValue' => 300, |
| 92 |
'hasUnit' => true, |
| 93 |
'unitDefaultValue' => 'px', |
| 94 |
'property' => 'min-height', |
| 95 |
'device' => $device, |
| 96 |
]), |
| 97 |
$carousel_css, |
| 98 |
); |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
public function get_navigation_button_css( $attributes, $device = '' ) { |
| 103 |
$navigation_button_css = []; |
| 104 |
|
| 105 |
return array_merge( |
| 106 |
Range::get_css([ |
| 107 |
'attributeValue' => $attributes['navigationIconPositionY'], |
| 108 |
'attribute_object_key' => 'value', |
| 109 |
'defaultValue' => 50, |
| 110 |
'isResponsive' => false, |
| 111 |
'hasUnit' => true, |
| 112 |
'unitDefaultValue' => '%', |
| 113 |
'property' => 'top', |
| 114 |
'device' => $device, |
| 115 |
]), |
| 116 |
$navigation_button_css, |
| 117 |
); |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
public function get_navigation_prev_button_css( $attributes, $device = '' ) { |
| 122 |
$navigation_prev_button_css = []; |
| 123 |
|
| 124 |
return array_merge( |
| 125 |
Range::get_css([ |
| 126 |
'attributeValue' => $attributes['navigationIconPositionPrevX'], |
| 127 |
'attribute_object_key' => 'value', |
| 128 |
'defaultValue' => -3, |
| 129 |
'hasUnit' => true, |
| 130 |
'isResponsive' => false, |
| 131 |
'unitDefaultValue' => '%', |
| 132 |
'property' => 'left', |
| 133 |
'device' => $device, |
| 134 |
]), |
| 135 |
$navigation_prev_button_css, |
| 136 |
); |
| 137 |
} |
| 138 |
|
| 139 |
public function get_navigation_next_button_css( $attributes, $device = '' ) { |
| 140 |
$navigation_next_button_css = []; |
| 141 |
|
| 142 |
return array_merge( |
| 143 |
Range::get_css([ |
| 144 |
'attributeValue' => $attributes['navigationIconPositionNextX'], |
| 145 |
'attribute_object_key' => 'value', |
| 146 |
'defaultValue' => -3, |
| 147 |
'isResponsive' => false, |
| 148 |
'hasUnit' => true, |
| 149 |
'unitDefaultValue' => '%', |
| 150 |
'property' => 'right', |
| 151 |
'device' => $device, |
| 152 |
]), |
| 153 |
$navigation_next_button_css, |
| 154 |
); |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
public function get_navigation_icon_css( $attributes, $device = '' ) { |
| 159 |
$navigation_icon_css = []; |
| 160 |
|
| 161 |
if ( isset( $attributes['navigationIconSize'][ 'value' . $device ] ) ) { |
| 162 |
$unit = isset( $attributes['navigationIconSize'][ 'valueUnit' . $device ] ) ? $attributes['navigationIconSize'][ 'valueUnit' . $device ] : 'px'; |
| 163 |
$navigation_icon_css['font-size'] = $attributes['navigationIconSize'][ 'value' . $device ] . $unit; |
| 164 |
} |
| 165 |
|
| 166 |
return array_merge( |
| 167 |
Range::get_css([ |
| 168 |
'attributeValue' => $attributes['navigationIconSize'], |
| 169 |
'attribute_object_key' => 'value', |
| 170 |
'defaultValue' => 35, |
| 171 |
'isResponsive' => true, |
| 172 |
'hasUnit' => true, |
| 173 |
'unitDefaultValue' => 'px', |
| 174 |
'property' => 'font-size', |
| 175 |
]), |
| 176 |
$navigation_icon_css, |
| 177 |
); |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
public function get_navigation_icon_svg_css( $attributes, $device = '' ) { |
| 182 |
$navigation_icon_svg_css = []; |
| 183 |
if ( isset( $attributes['navigationIconColor'] ) ) { |
| 184 |
$navigation_icon_svg_css['fill'] = $attributes['navigationIconColor']; |
| 185 |
}; |
| 186 |
if ( isset( $attributes['navigationIconBgColor'] ) ) { |
| 187 |
$navigation_icon_svg_css['background-color'] = $attributes['navigationIconBgColor']; |
| 188 |
}; |
| 189 |
return array_merge( |
| 190 |
$navigation_icon_svg_css, |
| 191 |
Dimensions::get_css( $attributes['navigationIconPadding'], 'padding', $device ), |
| 192 |
Border::get_css( $attributes['navigationIconBorder'], '', $device ), |
| 193 |
); |
| 194 |
} |
| 195 |
public function get_navigation_icon_svg_hover_css( $attributes, $device = '' ) { |
| 196 |
$navigation_icon_svg_hover_css = []; |
| 197 |
if ( isset( $attributes['navigationIconColorH'] ) ) { |
| 198 |
$navigation_icon_svg_hover_css['fill'] = $attributes['navigationIconColorH']; |
| 199 |
}; |
| 200 |
if ( isset( $attributes['navigationIconBgColorH'] ) ) { |
| 201 |
$navigation_icon_svg_hover_css['background-color'] = $attributes['navigationIconBgColorH']; |
| 202 |
}; |
| 203 |
return array_merge( |
| 204 |
Range::get_css([ |
| 205 |
'attributeValue' => $attributes['navigationIconTransition'], |
| 206 |
'attribute_object_key' => 'value', |
| 207 |
'defaultValue' => 10, |
| 208 |
'unitDefaultValue' => 's', |
| 209 |
'property' => 'transition-duration', |
| 210 |
'device' => $device, |
| 211 |
]), |
| 212 |
$navigation_icon_svg_hover_css, |
| 213 |
Border::get_hover_css( $attributes['navigationIconBorder'], '', $device ), |
| 214 |
); |
| 215 |
} |
| 216 |
|
| 217 |
public function get_pagination_color_css( $attributes ) { |
| 218 |
$pagination_color_css = []; |
| 219 |
if ( isset( $attributes['paginationColor'] ) ) { |
| 220 |
$pagination_color_css['background-color'] = $attributes['paginationColor']; |
| 221 |
}; |
| 222 |
return $pagination_color_css; |
| 223 |
} |
| 224 |
|
| 225 |
public function get_pagination_active_color_css( $attributes ) { |
| 226 |
$pagination_active_color_css = []; |
| 227 |
if ( isset( $attributes['paginationActiveColor'] ) ) { |
| 228 |
$pagination_active_color_css['background-color'] = $attributes['paginationActiveColor']; |
| 229 |
}; |
| 230 |
return $pagination_active_color_css; |
| 231 |
} |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
} |
| 236 |
|