PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.14.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.14.0
2.14.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 All 81 releases
← All changes | includes/blocks/image-comparison/block.php +448 -0 2.7.6 → 2.14.0 View file →
@@ -1,0 +1,448 @@
1 +<?php
2 +namespace ABlocks\Blocks\ImageComparison;
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\Border;
13 +use ABlocks\Controls\Range;
14 +use ABlocks\Controls\Color;
15 +
16 +class Block extends BlockBaseAbstract {
17 + protected $block_name = 'image-comparison';
18 +
19 + public function build_css_v1( $attributes ) {
20 + $css_generator = new CssGenerator( $attributes );
21 +
22 + $css_generator->add_class_styles(
23 + '{{WRAPPER}} .ablocks-image-comparison__images-container .ablocks-image-comparison__before-image',
24 + $this->get_before_image_width_css( $attributes )
25 + );
26 +
27 + $css_generator->add_class_styles(
28 + '{{WRAPPER}} .ablocks-image-comparison__images-container-vertical .ablocks-image-comparison__before-image',
29 + $this->get_before_image_height_css( $attributes )
30 + );
31 +
32 + $css_generator->add_class_styles(
33 + '{{WRAPPER}} .ablocks-image-comparison__images-container .ablocks-image-comparison__slider-line',
34 + $this->get_slider_line_horizontal_css( $attributes ),
35 + $this->get_slider_line_horizontal_css( $attributes, 'Tablet' ),
36 + $this->get_slider_line_horizontal_css( $attributes, 'Mobile' ),
37 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_slider_line_horizontal_css( $attributes, $device ); } )
38 + );
39 +
40 + $css_generator->add_class_styles(
41 + '{{WRAPPER}} .ablocks-image-comparison__images-container-vertical .ablocks-image-comparison__slider-line',
42 + $this->get_slider_line_vertical_css( $attributes ),
43 + $this->get_slider_line_vertical_css( $attributes, 'Tablet' ),
44 + $this->get_slider_line_vertical_css( $attributes, 'Mobile' ),
45 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_slider_line_vertical_css( $attributes, $device ); } )
46 + );
47 +
48 + $css_generator->add_class_styles(
49 + '{{WRAPPER}} .ablocks-image-comparison__images-container .ablocks-image-comparison__slider-icon',
50 + $this->get_horizontal_slider_icon_css( $attributes ),
51 + $this->get_horizontal_slider_icon_css( $attributes, 'Tablet' ),
52 + $this->get_horizontal_slider_icon_css( $attributes, 'Mobile' ),
53 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_horizontal_slider_icon_css( $attributes, $device ); } )
54 + );
55 +
56 + $css_generator->add_class_styles(
57 + '{{WRAPPER}} .ablocks-image-comparison__images-container-vertical .ablocks-image-comparison__slider-icon',
58 + $this->get_vertical_slider_icon_css( $attributes ),
59 + $this->get_vertical_slider_icon_css( $attributes, 'Tablet' ),
60 + $this->get_vertical_slider_icon_css( $attributes, 'Mobile' ),
61 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_vertical_slider_icon_css( $attributes, $device ); } )
62 + );
63 +
64 + $css_generator->add_class_styles(
65 + '{{WRAPPER}} .ablocks-image-comparison__beforeImage-label',
66 + $this->get_image_overlay_css( $attributes ),
67 + $this->get_image_overlay_css( $attributes, 'Tablet' ),
68 + $this->get_image_overlay_css( $attributes, 'Mobile' ),
69 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_image_overlay_css( $attributes, $device ); } )
70 + );
71 +
72 + $css_generator->add_class_styles(
73 + '{{WRAPPER}} .ablocks-image-comparison__beforeImage-label:hover',
74 + $this->get_image_overlay_hover_css( $attributes ),
75 + $this->get_image_overlay_hover_css( $attributes, 'Tablet' ),
76 + $this->get_image_overlay_hover_css( $attributes, 'Mobile' ),
77 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_image_overlay_hover_css( $attributes, $device ); } )
78 + );
79 +
80 + $css_generator->add_class_styles(
81 + '{{WRAPPER}} .ablocks-image-comparison__afterImage-label',
82 + $this->get_image_overlay_css( $attributes ),
83 + $this->get_image_overlay_css( $attributes, 'Tablet' ),
84 + $this->get_image_overlay_css( $attributes, 'Mobile' ),
85 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_image_overlay_css( $attributes, $device ); } )
86 + );
87 +
88 + $css_generator->add_class_styles(
89 + '{{WRAPPER}} .ablocks-image-comparison__afterImage-label:hover',
90 + $this->get_image_overlay_hover_css( $attributes ),
91 + $this->get_image_overlay_hover_css( $attributes, 'Tablet' ),
92 + $this->get_image_overlay_hover_css( $attributes, 'Mobile' ),
93 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_image_overlay_hover_css( $attributes, $device ); } )
94 + );
95 +
96 + $css_generator->add_class_styles(
97 + '{{WRAPPER}} .ablocks-image-comparison__overlay',
98 + $this->get_overlay_css( $attributes ),
99 + );
100 +
101 + $css_generator->add_class_styles(
102 + '{{WRAPPER}} .ablocks-image-comparison__overlay--hover',
103 + $this->get_overlay_css( $attributes ),
104 + );
105 +
106 + $css_generator->add_class_styles(
107 + '{{WRAPPER}} .ablocks-image-comparison__beforeImage-label--horizontal',
108 + $this->get_before_image_overlay_horizontal_css( $attributes )
109 + );
110 + $css_generator->add_class_styles(
111 + '{{WRAPPER}} .ablocks-image-comparison__beforeImage-label--vertical',
112 + $this->get_before_image_overlay_vertical_css( $attributes )
113 + );
114 + $css_generator->add_class_styles(
115 + '{{WRAPPER}} .ablocks-image-comparison__afterImage-label--horizontal',
116 + $this->get_after_image_overlay_horizontal_css( $attributes )
117 + );
118 + $css_generator->add_class_styles(
119 + '{{WRAPPER}} .ablocks-image-comparison__afterImage-label--vertical',
120 + $this->get_after_image_overlay_vertical_css( $attributes )
121 + );
122 +
123 + return $css_generator->generate_css();
124 + }
125 +
126 + public function build_css_v2( $attributes ) {
127 + $css_generator = new CssGeneratorV2( $attributes );
128 +
129 + $css_generator->add_class_styles(
130 + '{{WRAPPER}} .ablocks-image-comparison__images-container .ablocks-image-comparison__before-image',
131 + $this->get_before_image_width_css( $attributes )
132 + );
133 +
134 + $css_generator->add_class_styles(
135 + '{{WRAPPER}} .ablocks-image-comparison__images-container-vertical .ablocks-image-comparison__before-image',
136 + $this->get_before_image_height_css( $attributes )
137 + );
138 +
139 + $css_generator->add_class_styles(
140 + '{{WRAPPER}} .ablocks-image-comparison__images-container .ablocks-image-comparison__slider-line',
141 + $this->get_slider_line_horizontal_css( $attributes ),
142 + $this->get_slider_line_horizontal_css( $attributes, 'Tablet' ),
143 + $this->get_slider_line_horizontal_css( $attributes, 'Mobile' ),
144 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_slider_line_horizontal_css( $attributes, $device ); } )
145 + );
146 +
147 + $css_generator->add_class_styles(
148 + '{{WRAPPER}} .ablocks-image-comparison__images-container-vertical .ablocks-image-comparison__slider-line',
149 + $this->get_slider_line_vertical_css( $attributes ),
150 + $this->get_slider_line_vertical_css( $attributes, 'Tablet' ),
151 + $this->get_slider_line_vertical_css( $attributes, 'Mobile' ),
152 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_slider_line_vertical_css( $attributes, $device ); } )
153 + );
154 +
155 + $css_generator->add_class_styles(
156 + '{{WRAPPER}} .ablocks-image-comparison__images-container .ablocks-image-comparison__slider-icon',
157 + $this->get_horizontal_slider_icon_css( $attributes ),
158 + $this->get_horizontal_slider_icon_css( $attributes, 'Tablet' ),
159 + $this->get_horizontal_slider_icon_css( $attributes, 'Mobile' ),
160 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_horizontal_slider_icon_css( $attributes, $device ); } )
161 + );
162 +
163 + $css_generator->add_class_styles(
164 + '{{WRAPPER}} .ablocks-image-comparison__images-container-vertical .ablocks-image-comparison__slider-icon',
165 + $this->get_vertical_slider_icon_css( $attributes ),
166 + $this->get_vertical_slider_icon_css( $attributes, 'Tablet' ),
167 + $this->get_vertical_slider_icon_css( $attributes, 'Mobile' ),
168 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_vertical_slider_icon_css( $attributes, $device ); } )
169 + );
170 +
171 + $css_generator->add_class_styles(
172 + '{{WRAPPER}} .ablocks-image-comparison__beforeImage-label',
173 + $this->get_image_overlay_css( $attributes ),
174 + $this->get_image_overlay_css( $attributes, 'Tablet' ),
175 + $this->get_image_overlay_css( $attributes, 'Mobile' ),
176 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_image_overlay_css( $attributes, $device ); } )
177 + );
178 +
179 + $css_generator->add_class_styles(
180 + '{{WRAPPER}} .ablocks-image-comparison__beforeImage-label:hover',
181 + $this->get_image_overlay_hover_css( $attributes ),
182 + $this->get_image_overlay_hover_css( $attributes, 'Tablet' ),
183 + $this->get_image_overlay_hover_css( $attributes, 'Mobile' ),
184 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_image_overlay_hover_css( $attributes, $device ); } )
185 + );
186 +
187 + $css_generator->add_class_styles(
188 + '{{WRAPPER}} .ablocks-image-comparison__afterImage-label',
189 + $this->get_image_overlay_css( $attributes ),
190 + $this->get_image_overlay_css( $attributes, 'Tablet' ),
191 + $this->get_image_overlay_css( $attributes, 'Mobile' ),
192 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_image_overlay_css( $attributes, $device ); } )
193 + );
194 +
195 + $css_generator->add_class_styles(
196 + '{{WRAPPER}} .ablocks-image-comparison__afterImage-label:hover',
197 + $this->get_image_overlay_hover_css( $attributes ),
198 + $this->get_image_overlay_hover_css( $attributes, 'Tablet' ),
199 + $this->get_image_overlay_hover_css( $attributes, 'Mobile' ),
200 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_image_overlay_hover_css( $attributes, $device ); } )
201 + );
202 +
203 + $css_generator->add_class_styles(
204 + '{{WRAPPER}} .ablocks-image-comparison__overlay',
205 + $this->get_overlay_css( $attributes ),
206 + );
207 +
208 + $css_generator->add_class_styles(
209 + '{{WRAPPER}} .ablocks-image-comparison__overlay--hover',
210 + $this->get_overlay_css( $attributes ),
211 + );
212 +
213 + $css_generator->add_class_styles(
214 + '{{WRAPPER}} .ablocks-image-comparison__beforeImage-label--horizontal',
215 + $this->get_before_image_overlay_horizontal_css( $attributes )
216 + );
217 + $css_generator->add_class_styles(
218 + '{{WRAPPER}} .ablocks-image-comparison__beforeImage-label--vertical',
219 + $this->get_before_image_overlay_vertical_css( $attributes )
220 + );
221 + $css_generator->add_class_styles(
222 + '{{WRAPPER}} .ablocks-image-comparison__afterImage-label--horizontal',
223 + $this->get_after_image_overlay_horizontal_css( $attributes )
224 + );
225 + $css_generator->add_class_styles(
226 + '{{WRAPPER}} .ablocks-image-comparison__afterImage-label--vertical',
227 + $this->get_after_image_overlay_vertical_css( $attributes )
228 + );
229 +
230 + return $css_generator->generate_css();
231 + }
232 +
233 +
234 + public function build_css( $attributes ) {
235 + if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) {
236 + return $this->build_css_v2( $attributes );
237 + }
238 + return $this->build_css_v1( $attributes );
239 + }
240 +
241 + public function get_before_image_width_css( $attributes ) {
242 + $slider_position = isset( $attributes['sliderPosition'] ) ? $attributes['sliderPosition'] : 50;
243 + return [ 'width' => $slider_position . '%' ];
244 + }
245 +
246 + public function get_before_image_height_css( $attributes ) {
247 + $slider_position = isset( $attributes['sliderPosition'] ) ? $attributes['sliderPosition'] : 50;
248 + return [ 'height' => $slider_position . '%' ];
249 + }
250 +
251 + public function get_slider_line_horizontal_css( $attributes, $device = '' ) {
252 + $slider_position = isset( $attributes['sliderPosition'] ) ? $attributes['sliderPosition'] : 50;
253 + $css = [];
254 + $css['left'] = $slider_position . '%';
255 + return array_merge(
256 + [ 'background' => Color::get_css( isset( $attributes['handleColor'] ) ? $attributes['handleColor'] : '' ) ],
257 + Range::get_css([
258 + 'attributeValue' => $attributes['sliderBarSize'],
259 + 'attribute_object_key' => 'value',
260 + 'isResponsive' => true,
261 + 'defaultValue' => 4,
262 + 'unitDefaultValue' => 'px',
263 + 'property' => 'width',
264 + 'device' => $device,
265 + ]),
266 + $css
267 + );
268 +
269 + }
270 +
271 + public function get_slider_line_vertical_css( $attributes, $device = '' ) {
272 + $slider_top = isset( $attributes['sliderPosition'] ) ? $attributes['sliderPosition'] : 50;
273 + $css = [];
274 + $css['top'] = $slider_top . '%';
275 + return array_merge(
276 + [ 'background' => Color::get_css( isset( $attributes['handleColor'] ) ? $attributes['handleColor'] : '' ) ],
277 + Range::get_css([
278 + 'attributeValue' => $attributes['sliderBarSize'],
279 + 'attribute_object_key' => 'value',
280 + 'isResponsive' => true,
281 + 'defaultValue' => 4,
282 + 'unitDefaultValue' => 'px',
283 + 'property' => 'height',
284 + 'device' => $device,
285 + ]),
286 + $css,
287 + );
288 + }
289 +
290 + public function get_horizontal_slider_icon_css( $attributes, $device = '' ) {
291 + $slider_position = isset( $attributes['sliderPosition'] ) ? $attributes['sliderPosition'] : 50;
292 + $slider_icon_border_size = isset( $attributes['sliderIconBorderSize'][ 'value' . $device ] ) ? $attributes['sliderIconBorderSize'][ 'value' . $device ] : [ 'value' => 2 ];
293 + $border_size = is_array( $slider_icon_border_size ) && isset( $slider_icon_border_size[ 'value' . $device ] )
294 + ? $slider_icon_border_size[ 'value' . $device ]
295 + : ( is_array( $slider_icon_border_size ) ? $slider_icon_border_size['value'] : $slider_icon_border_size );
296 + $css = [];
297 + $css['left'] = $slider_position . '%';
298 + $css['top'] = '50%';
299 + $css['border-weight'] = 'solid';
300 + return array_merge(
301 + [ 'border-color' => Color::get_css( isset( $attributes['handleColor'] ) ? $attributes['handleColor'] : '' ) ],
302 + [ 'color' => Color::get_css( isset( $attributes['handleColor'] ) ? $attributes['handleColor'] : '' ) ],
303 + Range::get_css([
304 + 'attributeValue' => $attributes['sliderIconSize'],
305 + 'attribute_object_key' => 'value',
306 + 'isResponsive' => true,
307 + 'defaultValue' => 50,
308 + 'unitDefaultValue' => 'px',
309 + 'property' => 'width',
310 + 'device' => $device,
311 + ]),
312 + Range::get_css([
313 + 'attributeValue' => $attributes['sliderIconSize'],
314 + 'attribute_object_key' => 'value',
315 + 'isResponsive' => true,
316 + 'defaultValue' => 50,
317 + 'unitDefaultValue' => 'px',
318 + 'property' => 'height',
319 + 'device' => $device,
320 + ]),
321 + Range::get_css([
322 + 'attributeValue' => $attributes['sliderIconBorderSize'],
323 + 'attribute_object_key' => 'value',
324 + 'isResponsive' => true,
325 + 'defaultValue' => 2,
326 + 'unitDefaultValue' => 'px',
327 + 'property' => 'border-width',
328 + 'device' => $device,
329 + ]),
330 + $css
331 + );
332 + }
333 +
334 + public function get_vertical_slider_icon_css( $attributes, $device = '' ) {
335 + $slider_position = isset( $attributes['sliderPosition'] ) ? $attributes['sliderPosition'] : 50;
336 + $css = [];
337 + $css['left'] = '50%';
338 + $css['top'] = $slider_position . '%';
339 + $css['border-weight'] = 'solid';
340 + return array_merge(
341 + [ 'border-color' => Color::get_css( isset( $attributes['handleColor'] ) ? $attributes['handleColor'] : '' ) ],
342 + [ 'color' => Color::get_css( isset( $attributes['handleColor'] ) ? $attributes['handleColor'] : '' ) ],
343 + Range::get_css([
344 + 'attributeValue' => $attributes['sliderIconSize'],
345 + 'attribute_object_key' => 'value',
346 + 'isResponsive' => true,
347 + 'defaultValue' => 50,
348 + 'unitDefaultValue' => 'px',
349 + 'property' => 'width',
350 + 'device' => $device,
351 + ]),
352 + Range::get_css([
353 + 'attributeValue' => $attributes['sliderIconSize'],
354 + 'attribute_object_key' => 'value',
355 + 'isResponsive' => true,
356 + 'defaultValue' => 50,
357 + 'unitDefaultValue' => 'px',
358 + 'property' => 'height',
359 + 'device' => $device,
360 + ]),
361 + Range::get_css([
362 + 'attributeValue' => $attributes['sliderIconBorderSize'],
363 + 'attribute_object_key' => 'value',
364 + 'isResponsive' => true,
365 + 'defaultValue' => 2,
366 + 'unitDefaultValue' => 'px',
367 + 'property' => 'border-width',
368 + 'device' => $device,
369 + ]),
370 + $css
371 + );
372 + }
373 +
374 + public function get_overlay_css( $attributes, $device = '' ) {
375 + return [ 'background' => Color::get_css( isset( $attributes['labelOverlayColor'] ) ? $attributes['labelOverlayColor'] : '' ) ];
376 + }
377 +
378 + public function get_image_overlay_css( $attributes, $device = '' ) {
379 + $label_border = isset( $attributes['labelBorder'] ) ? $attributes['labelBorder'] : [];
380 + $slider_orientation = isset( $attributes['sliderOrientation'] ) ? $attributes['sliderOrientation'] : '';
381 + $label_position = isset( $attributes['labelPosition'] ) ? $attributes['labelPosition'] : '';
382 +
383 + // Determine transform value based on the conditions
384 + $transform = 'none';
385 + if ( $label_position === 45 && $slider_orientation === 'vertical' ) {
386 + $transform = 'translateX(-50%)';
387 + } elseif ( $label_position === 95 && $slider_orientation === 'vertical' ) {
388 + $transform = 'translateX(-100%)';
389 + } elseif ( $label_position === 90 && $slider_orientation === 'horizontal' ) {
390 + $transform = 'translateY(-100%)';
391 + }
392 +
393 + return array_merge(
394 + Border::get_css( $label_border, '', $device ),
395 + [ 'color' => Color::get_css( isset( $attributes['labelTextColor'] ) ? $attributes['labelTextColor'] : '' ) ],
396 + [ 'background' => Color::get_css( isset( $attributes['labelBgColor'] ) ? $attributes['labelBgColor'] : '' ) ],
397 + [
398 + 'transform' => $transform,
399 + 'max-width' => '30%'
400 + ]
401 + );
402 + }
403 +
404 +
405 + public function get_image_overlay_hover_css( $attributes, $device = '' ) {
406 + return array_merge(
407 + Border::get_hover_css( $attributes['labelBorder'], '', $device ),
408 + [ 'color' => Color::get_css( isset( $attributes['labelHoverTextColor'] ) ? $attributes['labelHoverTextColor'] : '' ) ],
409 + [ 'background' => Color::get_css( isset( $attributes['labelHoverBgColor'] ) ? $attributes['labelHoverBgColor'] : '' ) ],
410 + );
411 + }
412 +
413 + public function get_before_image_overlay_horizontal_css( $attributes ) {
414 + $label_position = isset( $attributes['labelPosition'] ) ? $attributes['labelPosition'] : 45;
415 +
416 + return [
417 + 'top' => $label_position . '%',
418 + 'left' => '10px'
419 + ];
420 + }
421 +
422 + public function get_before_image_overlay_vertical_css( $attributes ) {
423 + $label_position = isset( $attributes['labelPosition'] ) ? $attributes['labelPosition'] : 45;
424 +
425 + return [
426 + 'left' => $label_position . '%',
427 + 'top' => '10px'
428 + ];
429 + }
430 +
431 + public function get_after_image_overlay_horizontal_css( $attributes ) {
432 + $label_position = isset( $attributes['labelPosition'] ) ? $attributes['labelPosition'] : 45;
433 +
434 + return [
435 + 'top' => $label_position . '%',
436 + 'right' => '10px',
437 + ];
438 + }
439 +
440 + public function get_after_image_overlay_vertical_css( $attributes ) {
441 + $label_position = isset( $attributes['labelPosition'] ) ? $attributes['labelPosition'] : 45;
442 +
443 + return [
444 + 'bottom' => '10px',
445 + 'left' => $label_position . '%',
446 + ];
447 + }
448 +}