PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.9.1
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.9.1
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.9.1, at includes/blocks/image-scroll/block.php

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