PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / trunk
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder vtrunk
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 1.2.0 1.2.1 All 78 releases
ablocks / includes / blocks / image-scroll / block.php

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

380 lines 14.2 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 Range::get_css([
114 'attributeValue' => $attributes['scrollWidth'],
115 'attributeObjectKey' => 'value',
116 'isResponsive' => true,
117 'defaultValue' => 100,
118 'hasUnit' => true,
119 'unitDefaultValue' => '%',
120 'property' => 'width',
121 'device' => $device,
122 ]),
123 );
124 }
125 public function get_scroll_option_css( $attributes, $device = '' ) {
126 $css = [];
127
128 if ( ! empty( $attributes['imageScrollOption']['value'] ) ) {
129 if ( $attributes['imageScrollOption']['value'] === 'mouse-scroll' ) {
130 $css['position'] = 'static';
131 $css['overflow-y'] = 'scroll';
132 $css['overflow-x'] = 'hidden';
133 } elseif ( $attributes['imageScrollOption']['value'] === 'top-to-bottom' ) {
134 $css['position'] = 'static';
135 $css['overflow'] = 'hidden';
136 } elseif ( $attributes['imageScrollOption']['value'] === 'bottom-to-top' ) {
137 $css['position'] = 'static';
138 $css['overflow'] = 'hidden';
139 } elseif ( $attributes['imageScrollOption']['value'] === 'left-to-right' ) {
140 $css['position'] = 'static';
141 $css['overflow'] = 'hidden';
142 } elseif ( $attributes['imageScrollOption']['value'] === 'right-to-left' ) {
143 $css['position'] = 'static';
144 $css['overflow'] = 'hidden';
145 } elseif ( $attributes['imageScrollOption']['value'] === 'horizontal-scroll' ) {
146 $css['position'] = 'static';
147 $css['overflow-y'] = 'hidden';
148 $css['overflow-x'] = 'scroll';
149 }//end if
150 }//end if
151
152 return $css;
153 }
154 public function get_image_overlay_css( $attributes ) {
155 $css = [];
156 $css['background-color'] = Color::get_css(
157 isset( $attributes['overlayColor'] ) ? $attributes['overlayColor'] : '');
158
159 // Set common positioning and display properties
160 $css['position'] = 'absolute';
161 $css['top'] = '0';
162 $css['left'] = '0';
163 $css['right'] = '0';
164 $css['bottom'] = '0';
165 $css['z-index'] = 4;
166 $css['display'] = 'block';
167
168 // Border calculations
169 $border = $attributes['border'] ?? [];
170 $topDiff = ! empty( $border['commonWidth'] ) ? (int) $border['commonWidth'] : (int) ( $border['topWidth'] ?? 0 );
171 $bottomDiff = ! empty( $border['commonWidth'] ) ? (int) $border['commonWidth'] : (int) ( $border['bottomWidth'] ?? 0 );
172 $leftDiff = ! empty( $border['commonWidth'] ) ? (int) $border['commonWidth'] : (int) ( $border['leftWidth'] ?? 0 );
173 $rightDiff = ! empty( $border['commonWidth'] ) ? (int) $border['commonWidth'] : (int) ( $border['rightWidth'] ?? 0 );
174
175 // Border radius calculations
176 $topRadiusValue = ! empty( $border['commonRadius'] ) ? (int) $border['commonRadius'] : (int) ( $border['topRadius'] ?? 0 );
177 $leftRadiusValue = ! empty( $border['commonRadius'] ) ? (int) $border['commonRadius'] : (int) ( $border['leftRadius'] ?? 0 );
178 $rightRadiusValue = ! empty( $border['commonRadius'] ) ? (int) $border['commonRadius'] : (int) ( $border['rightRadius'] ?? 0 );
179 $bottomRadiusValue = ! empty( $border['commonRadius'] ) ? (int) $border['commonRadius'] : (int) ( $border['bottomRadius'] ?? 0 );
180
181 // Apply border radius with differences taken into account
182 $css['border-top-left-radius'] = ( $topRadiusValue - $topDiff ) . 'px';
183 $css['border-top-right-radius'] = ( $rightRadiusValue - $rightDiff ) . 'px';
184 $css['border-bottom-left-radius'] = ( $bottomRadiusValue - $bottomDiff ) . 'px';
185 $css['border-bottom-right-radius'] = ( $leftRadiusValue - $leftDiff ) . 'px';
186
187 return $css;
188 }
189
190 public function get_image_overlay_hover_css( $attributes ) {
191 $css = [];
192 $css['display'] = 'none';
193 return $css;
194 }
195 public function get_image_figure_css( $attributes, $device = '' ) {
196 $css = [];
197 $css['width'] = '100% !important';
198 $css['position'] = 'static !important';
199 $css['display'] = 'flex';
200 $css['flex-direction'] = 'column';
201
202 return $css;
203 }
204 public function get_wrapper_css( $attributes, $device = '' ) {
205 return array_merge(
206 isset( $attributes['padding'] ) ? Dimensions::get_css( $attributes['padding'], 'padding', $device ) : [],
207 isset( $attributes['border'] ) ? Border::get_css( $attributes['border'], '', $device ) : [],
208 );
209 }
210 public function get_wrapper_hover_css( $attributes, $device = '' ) {
211 $border_hover_css = Border::get_hover_css( isset( $attributes['border'] ) ? $attributes['border'] : null, $device );
212
213 return array_merge(
214 $border_hover_css,
215 );
216 }
217
218 public function get_image_css( $attributes, $device = '' ) {
219 $css = [];
220 $css['width'] = '100%';
221 if ( ! empty( $attributes['imageScrollOption']['value'] ) ) {
222 $checkHorizontalOption = $attributes['imageScrollOption']['value'] === 'horizontal-scroll' || $attributes['imageScrollOption']['value'] === 'left-to-right' || $attributes['imageScrollOption']['value'] === 'right-to-left';
223
224 if ( $checkHorizontalOption ) {
225 $css['width'] = 'none';
226 $css['max-width'] = 'none';
227 $css['object-fit'] = 'fill';
228 }
229 }
230 $css['height'] = '100%';
231 if ( ! empty( $attributes[ 'imgUrl' . $device ] ) ) {
232 $css['max-width'] = '100%';
233 $css['transition'] = '0.3s ease';
234 }
235
236 if ( isset( $attributes['widthHeightWidget'][ 'width' . $device ] ) ) {
237 $css['width'] = $attributes['widthHeightWidget'][ 'width' . $device ] . 'px';
238 } elseif ( isset( $attributes['widthHeightWidget']['imgNaturalWidth'] ) ) {
239 $css['width'] = $attributes['widthHeightWidget']['imgNaturalWidth'] . 'px';
240 }
241
242 $aspectRatioValue = empty( $attributes['aspectRatio'][ 'value' . $device ] ) ? false : $attributes['aspectRatio'][ 'value' . $device ];
243 $heightValue = empty( $attributes['widthHeightWidget'][ 'height' . $device ] ) ? false : $attributes['widthHeightWidget'][ 'height' . $device ];
244 $showHeight = ! empty( $attributes['widthHeightWidget'][ 'showHeight' . $device ] );
245
246 if ( $showHeight || ( ! $aspectRatioValue && $heightValue ) ) {
247 $css['height'] = $heightValue . 'px';
248 } else {
249 $css['height'] = 'auto';
250 }
251
252 if ( isset( $attributes['objectFit'][ 'value' . $device ] ) && '' !== $attributes['objectFit'][ 'value' . $device ] && 'default' !== $attributes['objectFit'][ 'value' . $device ] ) {
253 $css['object-fit'] = $attributes['objectFit'][ 'value' . $device ];
254 }
255
256 if ( $aspectRatioValue && $aspectRatioValue !== 'original' ) {
257 $css['aspect-ratio'] = $aspectRatioValue;
258 }
259
260 return array_merge(
261 $css,
262 Range::get_css([
263 'attributeValue' => $attributes['opacity'],
264 'defaultValue' => 1,
265 'unitDefaultValue' => '',
266 'property' => 'opacity',
267 'device' => $device,
268 ]),
269 isset( $attributes['cssFilter'] ) ? CssFilter::get_css( $attributes['cssFilter'], '', $device ) : [],
270 isset( $attributes['boxShadow'] ) ? BoxShadow::get_css( $attributes['boxShadow'], $device ) : []
271 );
272 }
273
274 public function get_image_hover_css( $attributes, $device = '' ) {
275 $css = [];
276 $range_css = Range::get_css([
277 'attributeValue' => $attributes['opacityH'],
278 'defaultValue' => 0,
279 'unitDefaultValue' => '',
280 'property' => 'opacity',
281 'device' => $device,
282 ]);
283 $transitionDurationRange = Range::get_css([
284 'attributeValue' => $attributes['transitionDuration'],
285 'defaultValue' => 0.5,
286 'unitDefaultValue' => '',
287 'property' => 'transition',
288 'device' => $device,
289 ]);
290 $filterTransitionDurationRange = Range::get_css([
291 'attributeValue' => $attributes['filterTransitionDuration'],
292 'defaultValue' => 0.5,
293 'unitDefaultValue' => '',
294 'property' => 'filter',
295 'device' => $device,
296 ]);
297
298 if (
299 isset( $attributes['border']['transitionDuration'] ) ||
300 isset( $attributes['boxShadow']['transitionDuration'] ) ||
301 isset( $filterTransitionDurationRange['filter'] ) ||
302 isset( $transitionDurationRange['transition'] )
303 ) {
304 $css['transition'] = sprintf(
305 'border %ss, box-shadow %ss, opacity %ss, filter %ss, transform 0.3s',
306 ! empty( $attributes['border']['transitionDuration'] ) ? $attributes['border']['transitionDuration'] : $transitionDurationRange['transition'],
307 isset( $attributes['boxShadow']['transitionDuration'] ) ? $attributes['boxShadow']['transitionDuration'] : $transitionDurationRange['transition'],
308 $filterTransitionDurationRange['filter'],
309 $filterTransitionDurationRange['filter']
310 );
311 }
312
313 return array_merge(
314 $css,
315 $range_css,
316 ( isset( $attributes['boxShadow'] ) ) ? BoxShadow::get_hover_css( $attributes['boxShadow'], $device ) : [],
317 ( isset( $attributes['cssHoverFilter'] ) ) ? CssFilter::get_css( $attributes['cssHoverFilter'], '', $device ) : [],
318 );
319 }
320
321
322
323 public function get_image_container_css( $attributes, $device = '' ) {
324 $alignment_value = $attributes['alignment'][ 'value' . $device ] ?? '';
325
326 $css = [];
327 $border = $attributes['border'] ?? [];
328 $topDiff = ! empty( $border['commonWidth'] ) ? (int) $border['commonWidth'] : (int) ( $border['topWidth'] ?? 0 );
329 $bottomDiff = ! empty( $border['commonWidth'] ) ? (int) $border['commonWidth'] : (int) ( $border['bottomWidth'] ?? 0 );
330 $leftDiff = ! empty( $border['commonWidth'] ) ? (int) $border['commonWidth'] : (int) ( $border['leftWidth'] ?? 0 );
331 $rightDiff = ! empty( $border['commonWidth'] ) ? (int) $border['commonWidth'] : (int) ( $border['rightWidth'] ?? 0 );
332
333 // Border radius calculations
334 $topRadiusValue = ! empty( $border['commonRadius'] ) ? (int) $border['commonRadius'] : (int) ( $border['topRadius'] ?? 0 );
335 $leftRadiusValue = ! empty( $border['commonRadius'] ) ? (int) $border['commonRadius'] : (int) ( $border['leftRadius'] ?? 0 );
336 $rightRadiusValue = ! empty( $border['commonRadius'] ) ? (int) $border['commonRadius'] : (int) ( $border['rightRadius'] ?? 0 );
337 $bottomRadiusValue = ! empty( $border['commonRadius'] ) ? (int) $border['commonRadius'] : (int) ( $border['bottomRadius'] ?? 0 );
338
339 // Apply border radius with differences taken into account
340 $css['border-top-left-radius'] = ( $topRadiusValue - $topDiff ) . 'px';
341 $css['border-top-right-radius'] = ( $rightRadiusValue - $rightDiff ) . 'px';
342 $css['border-bottom-left-radius'] = ( $bottomRadiusValue - $bottomDiff ) . 'px';
343 $css['border-bottom-right-radius'] = ( $leftRadiusValue - $leftDiff ) . 'px';
344 if ( ! empty( $alignment_value ) ) {
345 $css['display'] = 'flex';
346 $css['justify-content'] = $alignment_value;
347 }
348 return $css;
349 }
350 public function get_icon_wrapper_css( $attributes, $device = '' ) {
351 $css = [
352 'position' => 'absolute',
353 'top' => '45%',
354 'left' => '50%',
355 'z-index' => '5',
356 'opacity' => '1',
357 ];
358 return array_merge(
359 [ 'color' => Color::get_css( isset( $attributes['iconColor'] ) ? $attributes['iconColor'] : 'black' ) ],
360 $css,
361 Range::get_css([
362 'attributeValue' => $attributes['iconFontSize'],
363 'isResponsive' => true,
364 'hasUnit' => true,
365 'defaultValue' => 36,
366 'property' => 'font-size',
367 ])
368 );
369 }
370 public function get_icon_wrapper_hover_css( $attributes, $device = '' ) {
371 $css = [
372 'opacity' => '0'
373 ];
374 return array_merge(
375 $css,
376 );
377 }
378
379 }
380