PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.8.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.8.0
2.13.0 2.13.1 2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 All 80 releases
ablocks / includes / blocks / image-scroll / block.php

block.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.8.0, at includes/blocks/image-scroll/block.php

370 lines 14.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Blocks\ImageScroll;
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\Border;
12 use ABlocks\Controls\Dimensions;
13 use ABlocks\Controls\Typography;
14 use ABlocks\Controls\CssFilter;
15 use ABlocks\Controls\BoxShadow;
16 use ABlocks\Controls\Range;
17 use ABlocks\Controls\Color;
18 class Block extends BlockBaseAbstract {
19 protected $block_name = 'image-scroll';
20
21 public function build_css( $attributes ) {
22
23 // Generate CSS
24 $css_generator = new CssGenerator( $attributes, $this->block_name );
25 // Image Wrapper CSS
26 $css_generator->add_class_styles(
27 '{{WRAPPER}}',
28 $this->get_wrapper_css( $attributes ),
29 $this->get_wrapper_css( $attributes, 'Tablet' ),
30 $this->get_wrapper_css( $attributes, 'Mobile' ),
31 );
32 $css_generator->add_class_styles(
33 '{{WRAPPER}}:hover',
34 $this->get_wrapper_hover_css( $attributes ),
35 $this->get_wrapper_hover_css( $attributes, 'Tablet' ),
36 $this->get_wrapper_hover_css( $attributes, 'Mobile' ),
37 );
38 // Image container css
39 $css_generator->add_class_styles(
40 '{{WRAPPER}} .ablocks-block-container',
41 $this->get_scroll_css( $attributes ),
42 $this->get_scroll_css( $attributes, 'Tablet' ),
43 $this->get_scroll_css( $attributes, 'Mobile' ),
44 );
45 $css_generator->add_class_styles(
46 '{{WRAPPER}} .ablocks-block-container',
47 $this->get_scroll_option_css( $attributes ),
48 $this->get_scroll_option_css( $attributes, 'Tablet' ),
49 $this->get_scroll_option_css( $attributes, 'Mobile' ),
50 );
51
52 $css_generator->add_class_styles(
53 '{{WRAPPER}} .ablocks-block-container .ablocks-image-scroll__figure',
54 $this->get_image_figure_css( $attributes ),
55 $this->get_image_figure_css( $attributes, 'Tablet' ),
56 $this->get_image_figure_css( $attributes, 'Mobile' ),
57 );
58 $css_generator->add_class_styles(
59 '{{WRAPPER}} .ablocks-block-image-overlay',
60 $this->get_image_overlay_css( $attributes ),
61 );
62 $css_generator->add_class_styles(
63 '{{WRAPPER}}.ablocks-block--image-scroll:hover .ablocks-block-image-overlay',
64 $this->get_image_overlay_hover_css( $attributes ),
65 );
66
67 // Image container css
68 $css_generator->add_class_styles(
69 '{{WRAPPER}} .ablocks-block-container',
70 $this->get_image_container_css( $attributes ),
71 $this->get_image_container_css( $attributes, 'Tablet' ),
72 $this->get_image_container_css( $attributes, 'Mobile' ),
73 );
74 // Image css
75 $css_generator->add_class_styles(
76 '{{WRAPPER}} .ablocks-block-container .ablocks-image-scroll__figure img',
77 $this->get_image_css( $attributes ),
78 $this->get_image_css( $attributes, 'Tablet' ),
79 $this->get_image_css( $attributes, 'Mobile' ),
80 );
81
82 // Image hover css
83 $css_generator->add_class_styles(
84 '{{WRAPPER}} .ablocks-block-container .ablocks-image-scroll__figure img:hover',
85 $this->get_image_hover_css( $attributes ),
86 $this->get_image_hover_css( $attributes, 'Tablet' ),
87 $this->get_image_hover_css( $attributes, 'Mobile' ),
88 );
89 $css_generator->add_class_styles(
90 '{{WRAPPER}} .ablocks-icon-wrap',
91 $this->get_icon_wrapper_css( $attributes ),
92 $this->get_icon_wrapper_css( $attributes, 'Tablet' ),
93 $this->get_icon_wrapper_css( $attributes, 'Mobile' ),
94 );
95 $css_generator->add_class_styles(
96 '{{WRAPPER}}.ablocks-block--image-scroll:hover .ablocks-icon-wrap',
97 $this->get_icon_wrapper_hover_css( $attributes ),
98 );
99 return $css_generator->generate_css();
100 }
101 public function get_scroll_css( $attributes, $device = '' ) {
102 $css = [];
103 $css['width'] = '100%';
104 return array_merge(
105 $css,
106 Range::get_css([
107 'attributeValue' => $attributes['scrollHeight'],
108 'isResponsive' => true,
109 'defaultValue' => 200,
110 'property' => 'height',
111 'device' => $device,
112 ]),
113 );
114 }
115 public function get_scroll_option_css( $attributes, $device = '' ) {
116 $css = [];
117
118 if ( ! empty( $attributes['imageScrollOption']['value'] ) ) {
119 if ( $attributes['imageScrollOption']['value'] === 'mouse-scroll' ) {
120 $css['position'] = 'static';
121 $css['overflow-y'] = 'scroll';
122 $css['overflow-x'] = 'hidden';
123 } elseif ( $attributes['imageScrollOption']['value'] === 'top-to-bottom' ) {
124 $css['position'] = 'static';
125 $css['overflow'] = 'hidden';
126 } elseif ( $attributes['imageScrollOption']['value'] === 'bottom-to-top' ) {
127 $css['position'] = 'static';
128 $css['overflow'] = 'hidden';
129 } elseif ( $attributes['imageScrollOption']['value'] === 'left-to-right' ) {
130 $css['position'] = 'static';
131 $css['overflow'] = 'hidden';
132 } elseif ( $attributes['imageScrollOption']['value'] === 'right-to-left' ) {
133 $css['position'] = 'static';
134 $css['overflow'] = 'hidden';
135 } elseif ( $attributes['imageScrollOption']['value'] === 'horizontal-scroll' ) {
136 $css['position'] = 'static';
137 $css['overflow-y'] = 'hidden';
138 $css['overflow-x'] = 'scroll';
139 }//end if
140 }//end if
141
142 return $css;
143 }
144 public function get_image_overlay_css( $attributes ) {
145 $css = [];
146 $css['background-color'] = Color::get_css(
147 isset( $attributes['overlayColor'] ) ? $attributes['overlayColor'] : '');
148
149 // Set common positioning and display properties
150 $css['position'] = 'absolute';
151 $css['top'] = '0';
152 $css['left'] = '0';
153 $css['right'] = '0';
154 $css['bottom'] = '0';
155 $css['z-index'] = 4;
156 $css['display'] = 'block';
157
158 // Border calculations
159 $border = $attributes['border'] ?? [];
160 $topDiff = ! empty( $border['commonWidth'] ) ? (int) $border['commonWidth'] : (int) ( $border['topWidth'] ?? 0 );
161 $bottomDiff = ! empty( $border['commonWidth'] ) ? (int) $border['commonWidth'] : (int) ( $border['bottomWidth'] ?? 0 );
162 $leftDiff = ! empty( $border['commonWidth'] ) ? (int) $border['commonWidth'] : (int) ( $border['leftWidth'] ?? 0 );
163 $rightDiff = ! empty( $border['commonWidth'] ) ? (int) $border['commonWidth'] : (int) ( $border['rightWidth'] ?? 0 );
164
165 // Border radius calculations
166 $topRadiusValue = ! empty( $border['commonRadius'] ) ? (int) $border['commonRadius'] : (int) ( $border['topRadius'] ?? 0 );
167 $leftRadiusValue = ! empty( $border['commonRadius'] ) ? (int) $border['commonRadius'] : (int) ( $border['leftRadius'] ?? 0 );
168 $rightRadiusValue = ! empty( $border['commonRadius'] ) ? (int) $border['commonRadius'] : (int) ( $border['rightRadius'] ?? 0 );
169 $bottomRadiusValue = ! empty( $border['commonRadius'] ) ? (int) $border['commonRadius'] : (int) ( $border['bottomRadius'] ?? 0 );
170
171 // Apply border radius with differences taken into account
172 $css['border-top-left-radius'] = ( $topRadiusValue - $topDiff ) . 'px';
173 $css['border-top-right-radius'] = ( $rightRadiusValue - $rightDiff ) . 'px';
174 $css['border-bottom-left-radius'] = ( $bottomRadiusValue - $bottomDiff ) . 'px';
175 $css['border-bottom-right-radius'] = ( $leftRadiusValue - $leftDiff ) . 'px';
176
177 return $css;
178 }
179
180 public function get_image_overlay_hover_css( $attributes ) {
181 $css = [];
182 $css['display'] = 'none';
183 return $css;
184 }
185 public function get_image_figure_css( $attributes, $device = '' ) {
186 $css = [];
187 $css['width'] = '100% !important';
188 $css['position'] = 'static !important';
189 $css['display'] = 'flex';
190 $css['flex-direction'] = 'column';
191
192 return $css;
193 }
194 public function get_wrapper_css( $attributes, $device = '' ) {
195 return array_merge(
196 isset( $attributes['padding'] ) ? Dimensions::get_css( $attributes['padding'], 'padding', $device ) : [],
197 isset( $attributes['border'] ) ? Border::get_css( $attributes['border'], '', $device ) : [],
198 );
199 }
200 public function get_wrapper_hover_css( $attributes, $device = '' ) {
201 $border_hover_css = Border::get_hover_css( isset( $attributes['border'] ) ? $attributes['border'] : null, $device );
202
203 return array_merge(
204 $border_hover_css,
205 );
206 }
207
208 public function get_image_css( $attributes, $device = '' ) {
209 $css = [];
210 $css['width'] = '100%';
211 if ( ! empty( $attributes['imageScrollOption']['value'] ) ) {
212 $checkHorizontalOption = $attributes['imageScrollOption']['value'] === 'horizontal-scroll' || $attributes['imageScrollOption']['value'] === 'left-to-right' || $attributes['imageScrollOption']['value'] === 'right-to-left';
213
214 if ( $checkHorizontalOption ) {
215 $css['width'] = 'none';
216 $css['max-width'] = 'none';
217 $css['object-fit'] = 'fill';
218 }
219 }
220 $css['height'] = '100%';
221 if ( ! empty( $attributes[ 'imgUrl' . $device ] ) ) {
222 $css['max-width'] = '100%';
223 $css['transition'] = '0.3s ease';
224 }
225
226 if ( isset( $attributes['widthHeightWidget'][ 'width' . $device ] ) ) {
227 $css['width'] = $attributes['widthHeightWidget'][ 'width' . $device ] . 'px';
228 } elseif ( isset( $attributes['widthHeightWidget']['imgNaturalWidth'] ) ) {
229 $css['width'] = $attributes['widthHeightWidget']['imgNaturalWidth'] . 'px';
230 }
231
232 $aspectRatioValue = empty( $attributes['aspectRatio'][ 'value' . $device ] ) ? false : $attributes['aspectRatio'][ 'value' . $device ];
233 $heightValue = empty( $attributes['widthHeightWidget'][ 'height' . $device ] ) ? false : $attributes['widthHeightWidget'][ 'height' . $device ];
234 $showHeight = ! empty( $attributes['widthHeightWidget'][ 'showHeight' . $device ] );
235
236 if ( $showHeight || ( ! $aspectRatioValue && $heightValue ) ) {
237 $css['height'] = $heightValue . 'px';
238 } else {
239 $css['height'] = 'auto';
240 }
241
242 if ( isset( $attributes['objectFit'][ 'value' . $device ] ) && '' !== $attributes['objectFit'][ 'value' . $device ] && 'default' !== $attributes['objectFit'][ 'value' . $device ] ) {
243 $css['object-fit'] = $attributes['objectFit'][ 'value' . $device ];
244 }
245
246 if ( $aspectRatioValue && $aspectRatioValue !== 'original' ) {
247 $css['aspect-ratio'] = $aspectRatioValue;
248 }
249
250 return array_merge(
251 $css,
252 Range::get_css([
253 'attributeValue' => $attributes['opacity'],
254 'defaultValue' => 1,
255 'unitDefaultValue' => '',
256 'property' => 'opacity',
257 'device' => $device,
258 ]),
259 isset( $attributes['cssFilter'] ) ? CssFilter::get_css( $attributes['cssFilter'], '', $device ) : [],
260 isset( $attributes['boxShadow'] ) ? BoxShadow::get_css( $attributes['boxShadow'], $device ) : []
261 );
262 }
263
264 public function get_image_hover_css( $attributes, $device = '' ) {
265 $css = [];
266 $range_css = Range::get_css([
267 'attributeValue' => $attributes['opacityH'],
268 'defaultValue' => 0,
269 'unitDefaultValue' => '',
270 'property' => 'opacity',
271 'device' => $device,
272 ]);
273 $transitionDurationRange = Range::get_css([
274 'attributeValue' => $attributes['transitionDuration'],
275 'defaultValue' => 0.5,
276 'unitDefaultValue' => '',
277 'property' => 'transition',
278 'device' => $device,
279 ]);
280 $filterTransitionDurationRange = Range::get_css([
281 'attributeValue' => $attributes['filterTransitionDuration'],
282 'defaultValue' => 0.5,
283 'unitDefaultValue' => '',
284 'property' => 'filter',
285 'device' => $device,
286 ]);
287
288 if (
289 isset( $attributes['border']['transitionDuration'] ) ||
290 isset( $attributes['boxShadow']['transitionDuration'] ) ||
291 isset( $filterTransitionDurationRange['filter'] ) ||
292 isset( $transitionDurationRange['transition'] )
293 ) {
294 $css['transition'] = sprintf(
295 'border %ss, box-shadow %ss, opacity %ss, filter %ss, transform 0.3s',
296 ! empty( $attributes['border']['transitionDuration'] ) ? $attributes['border']['transitionDuration'] : $transitionDurationRange['transition'],
297 isset( $attributes['boxShadow']['transitionDuration'] ) ? $attributes['boxShadow']['transitionDuration'] : $transitionDurationRange['transition'],
298 $filterTransitionDurationRange['filter'],
299 $filterTransitionDurationRange['filter']
300 );
301 }
302
303 return array_merge(
304 $css,
305 $range_css,
306 ( isset( $attributes['boxShadow'] ) ) ? BoxShadow::get_hover_css( $attributes['boxShadow'], $device ) : [],
307 ( isset( $attributes['cssHoverFilter'] ) ) ? CssFilter::get_css( $attributes['cssHoverFilter'], '', $device ) : [],
308 );
309 }
310
311
312
313 public function get_image_container_css( $attributes, $device = '' ) {
314 $alignment_value = $attributes['alignment'][ 'value' . $device ] ?? '';
315
316 $css = [];
317 $border = $attributes['border'] ?? [];
318 $topDiff = ! empty( $border['commonWidth'] ) ? (int) $border['commonWidth'] : (int) ( $border['topWidth'] ?? 0 );
319 $bottomDiff = ! empty( $border['commonWidth'] ) ? (int) $border['commonWidth'] : (int) ( $border['bottomWidth'] ?? 0 );
320 $leftDiff = ! empty( $border['commonWidth'] ) ? (int) $border['commonWidth'] : (int) ( $border['leftWidth'] ?? 0 );
321 $rightDiff = ! empty( $border['commonWidth'] ) ? (int) $border['commonWidth'] : (int) ( $border['rightWidth'] ?? 0 );
322
323 // Border radius calculations
324 $topRadiusValue = ! empty( $border['commonRadius'] ) ? (int) $border['commonRadius'] : (int) ( $border['topRadius'] ?? 0 );
325 $leftRadiusValue = ! empty( $border['commonRadius'] ) ? (int) $border['commonRadius'] : (int) ( $border['leftRadius'] ?? 0 );
326 $rightRadiusValue = ! empty( $border['commonRadius'] ) ? (int) $border['commonRadius'] : (int) ( $border['rightRadius'] ?? 0 );
327 $bottomRadiusValue = ! empty( $border['commonRadius'] ) ? (int) $border['commonRadius'] : (int) ( $border['bottomRadius'] ?? 0 );
328
329 // Apply border radius with differences taken into account
330 $css['border-top-left-radius'] = ( $topRadiusValue - $topDiff ) . 'px';
331 $css['border-top-right-radius'] = ( $rightRadiusValue - $rightDiff ) . 'px';
332 $css['border-bottom-left-radius'] = ( $bottomRadiusValue - $bottomDiff ) . 'px';
333 $css['border-bottom-right-radius'] = ( $leftRadiusValue - $leftDiff ) . 'px';
334 if ( ! empty( $alignment_value ) ) {
335 $css['display'] = 'flex';
336 $css['justify-content'] = $alignment_value;
337 }
338 return $css;
339 }
340 public function get_icon_wrapper_css( $attributes, $device = '' ) {
341 $css = [
342 'position' => 'absolute',
343 'top' => '45%',
344 'left' => '50%',
345 'z-index' => '5',
346 'opacity' => '1',
347 ];
348 return array_merge(
349 [ 'color' => Color::get_css( isset( $attributes['iconColor'] ) ? $attributes['iconColor'] : 'black' ) ],
350 $css,
351 Range::get_css([
352 'attributeValue' => $attributes['iconFontSize'],
353 'isResponsive' => true,
354 'hasUnit' => true,
355 'defaultValue' => 36,
356 'property' => 'font-size',
357 ])
358 );
359 }
360 public function get_icon_wrapper_hover_css( $attributes, $device = '' ) {
361 $css = [
362 'opacity' => '0'
363 ];
364 return array_merge(
365 $css,
366 );
367 }
368
369 }
370