PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.11.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.11.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-hotspot / block.php

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

374 lines 12.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Blocks\ImageHotspot;
3
4 use ABlocks\Controls\Range;
5 use ABlocks\Controls\Color;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit;
9 }
10
11 use ABlocks\Classes\BlockBaseAbstract;
12 use ABlocks\Classes\CssGenerator;
13 use ABlocks\Controls\BoxShadow;
14 use ABlocks\Classes\CssGeneratorV2;
15
16
17 class Block extends BlockBaseAbstract {
18 protected $block_name = 'image-hotspot';
19
20 public function build_css_v1( $attributes ) {
21 $css_generator = new CssGenerator( $attributes, $this->block_name );
22
23 $css_generator->add_class_styles(
24 '{{WRAPPER}} .ablocks-image-hotspot__pin:after',
25 [
26 'animation' => $attributes['animationType'],
27 ]
28 );
29
30 // Loop through lists and apply styles for each pin
31 if ( ! empty( $attributes['lists'] ) ) {
32 foreach ( $attributes['lists'] as $list ) {
33 $css_generator->add_class_styles(
34 "{{WRAPPER}} .ablocks-image-hotspot-list-{$list['id']}",
35 $this->get_pin_css( $attributes, $list )
36 );
37
38 $css_generator->add_class_styles(
39 "{{WRAPPER}} .ablocks-image-hotspot-list-{$list['id']}:after",
40 $this->get_pin_effect_css( $attributes, $list )
41 );
42
43 $css_generator->add_class_styles(
44 "{{WRAPPER}} .ablocks-image-hotspot-list-{$list['id']}:hover",
45 $this->get_pin_hover_css( $attributes, $list )
46 );
47
48 $css_generator->add_class_styles(
49 "{{WRAPPER}} .ablocks-image-hotspot-list-{$list['id']}:hover:after",
50 $this->get_pin_hover_effect_css( $attributes, $list )
51 );
52 }//end foreach
53 }//end if
54
55 // Tooltip content animation
56 $css_generator->add_class_styles(
57 '{{WRAPPER}} .ablocks-image-hotspot__tooltip-content',
58 $this->get_tooltip_content_css( $attributes )
59 );
60
61 $css_generator->add_class_styles(
62 '{{WRAPPER}} .ablocks-image-hotspot__tooltip--active',
63 $this->get_active_content_css( $attributes ),
64 $this->get_active_content_css( $attributes, 'Tablet' ),
65 $this->get_active_content_css( $attributes, 'Mobile' )
66 );
67
68 $css_generator->add_class_styles(
69 '{{WRAPPER}} .ablocks-image-hotspot__tooltip--active:hover',
70 $this->get_active_content_hover_css( $attributes ),
71 $this->get_active_content_hover_css( $attributes, 'Tablet' ),
72 $this->get_active_content_hover_css( $attributes, 'Mobile' )
73 );
74
75 return $css_generator->generate_css();
76 }
77 public function build_css_v2( $attributes ) {
78 $css_generator = new CssGeneratorV2( $attributes, $this->block_name );
79
80 $css_generator->add_class_styles(
81 '{{WRAPPER}} .ablocks-image-hotspot__pin:after',
82 [
83 'animation' => $attributes['animationType'],
84 ]
85 );
86
87 // Loop through lists and apply styles for each pin
88 if ( ! empty( $attributes['lists'] ) ) {
89 foreach ( $attributes['lists'] as $list ) {
90 $css_generator->add_class_styles(
91 "{{WRAPPER}} .ablocks-image-hotspot-list-{$list['id']}",
92 $this->get_pin_css( $attributes, $list )
93 );
94
95 $css_generator->add_class_styles(
96 "{{WRAPPER}} .ablocks-image-hotspot-list-{$list['id']}:after",
97 $this->get_pin_effect_css( $attributes, $list )
98 );
99
100 $css_generator->add_class_styles(
101 "{{WRAPPER}} .ablocks-image-hotspot-list-{$list['id']}:hover",
102 $this->get_pin_hover_css( $attributes, $list )
103 );
104
105 $css_generator->add_class_styles(
106 "{{WRAPPER}} .ablocks-image-hotspot-list-{$list['id']}:hover:after",
107 $this->get_pin_hover_effect_css( $attributes, $list )
108 );
109 }//end foreach
110 }//end if
111
112 // Tooltip content animation
113 $css_generator->add_class_styles(
114 '{{WRAPPER}} .ablocks-image-hotspot__tooltip-content',
115 $this->get_tooltip_content_css( $attributes )
116 );
117
118 $css_generator->add_class_styles(
119 '{{WRAPPER}} .ablocks-image-hotspot__tooltip--active',
120 $this->get_active_content_css( $attributes ),
121 $this->get_active_content_css( $attributes, 'Tablet' ),
122 $this->get_active_content_css( $attributes, 'Mobile' )
123 );
124
125 $css_generator->add_class_styles(
126 '{{WRAPPER}} .ablocks-image-hotspot__tooltip--active:hover',
127 $this->get_active_content_hover_css( $attributes ),
128 $this->get_active_content_hover_css( $attributes, 'Tablet' ),
129 $this->get_active_content_hover_css( $attributes, 'Mobile' )
130 );
131
132 return $css_generator->generate_css();
133 }
134 public function build_css( $attributes ) {
135 if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) {
136 return $this->build_css_v2( $attributes );
137 }
138 return $this->build_css_v1( $attributes );
139 }
140 public function get_pin_css( $attributes, $list ) {
141 return [
142 'background-color' => Color::get_css( ! empty( $list['pinColorEffect'] ) ? $list['pinColorEffect'] : $attributes['pinColorEffect'] ),
143 'width' => ! empty( $list['pinSize'] ) ? $list['pinSize'] . 'px' : $attributes['pinSize'] . 'px',
144 'height' => ! empty( $list['pinSize'] ) ? $list['pinSize'] . 'px' : $attributes['pinSize'] . 'px',
145 'transform' => 'translate(-50%, -50%)',
146 ];
147 }
148
149 public function get_pin_effect_css( $attributes, $list ) {
150 return [
151 'background-color' => Color::get_css( ! empty( $list['pinColor'] ) ? $list['pinColor'] : $attributes['pinColor'] ),
152 'width' => ! empty( $list['pinSize'] ) ? $list['pinSize'] . 'px' : $attributes['pinSize'] . 'px',
153 'height' => ! empty( $list['pinSize'] ) ? $list['pinSize'] . 'px' : $attributes['pinSize'] . 'px',
154 ];
155 }
156
157 public function get_pin_hover_css( $attributes, $list ) {
158 return [
159 'background-color' => Color::get_css( ! empty( $list['pinHoverColor'] ) ? $list['pinHoverColor'] : $attributes['pinHoverColor'] ),
160 'transform' => 'translate(-50%, -50%)',
161 '--ablocks-hotspot-effect-max-scale' => ! empty( $list['pinHoverSize'] ) ? $list['pinHoverSize'] : $attributes['pinHoverSize'],
162 ];
163 }
164
165 public function get_pin_hover_effect_css( $attributes, $list ) {
166 return [
167 'background-color' => Color::get_css( ! empty( $list['pinHoverColor'] ) ? $list['pinHoverColor'] : $attributes['pinHoverColor'] ),
168 '--ablocks-hotspot-effect-max-scale' => ! empty( $list['pinHoverSize'] ) ? $list['pinHoverSize'] : $attributes['pinHoverSize'],
169 ];
170 }
171
172 public function get_tooltip_content_css( $attributes ) {
173 // Extract the attributes
174 $content_position = $attributes['contentPosition'];
175 $content_animation = $attributes['contentAnimation'];
176
177 // Initialize transform values for sliding animations
178 $translateX_start = '0px';
179 $translateY_start = '0px';
180 $translateX_end = '-50%';
181 $translateY_end = '0px';
182
183 // Default transform for bottom position
184 $content_transform = 'translate(-50%, 40px)';
185
186 if ( $content_position === 'top' ) {
187 $content_transform = 'translate(-50%, calc(-100% - 40px))';
188 } elseif ( $content_position === 'left' ) {
189 $content_transform = 'translate(calc(-100% - 40px), -50%)';
190 } elseif ( $content_position === 'right' ) {
191 $content_transform = 'translate(40px, -50%)';
192 }
193
194 // Set default animation duration and ease if not provided
195 $animation_duration = '0.5s';
196 $animation_ease = 'ease';
197
198 // Set animation style dynamically based on contentAnimation
199 $animation_style = '';
200 if ( $content_animation === 'ablocks-hotspot-fadeIn' ) {
201 $animation_style = 'ablocks-hotspot-fadeIn 1.0s ease forwards';
202 } elseif ( $content_animation === 'ablocks-hotspot-fadeGrow' ) {
203 $animation_style = 'ablocks-hotspot-fadeGrow 0.5s ease';
204 switch ( $content_position ) {
205 case 'top':
206 $translateX_end = '-50%';
207 $translateY_end = 'calc(-100% - 40px)';
208 $translateX_start = $translateX_end;
209 $translateY_start = $translateY_end;
210 break;
211 case 'bottom':
212 $translateX_end = '-50%';
213 $translateY_end = '40px';
214 $translateX_start = $translateX_end;
215 $translateY_start = $translateY_end;
216 break;
217 case 'left':
218 $translateX_end = 'calc(-100% - 40px)';
219 $translateY_end = '-50%';
220 $translateX_start = $translateX_end;
221 $translateY_start = $translateY_end;
222 break;
223 case 'right':
224 $translateX_end = '40px';
225 $translateY_end = '-50%';
226 $translateX_start = $translateX_end;
227 $translateY_start = $translateY_end;
228 break;
229 }//end switch
230 // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
231 } elseif ( in_array( $content_animation, [ 'ablocks-hotspot-slideInTop', 'ablocks-hotspot-slideInBottom', 'ablocks-hotspot-slideInLeft', 'ablocks-hotspot-slideInRight' ] ) ) {
232 $animation_style = "ablocks-hotspot-slideIn {$animation_duration} {$animation_ease} forwards";
233 }//end if
234
235 // Handle specific sliding animations per position
236 switch ( $content_position ) {
237 case 'top':
238 $translateX_end = '-50%';
239 $translateY_end = 'calc(-100% - 40px)';
240 $translateX_start = $translateX_end;
241 $translateY_start = $translateY_end;
242
243 switch ( $content_animation ) {
244 case 'ablocks-hotspot-slideInLeft':
245 $translateX_start = 'calc(-50% - 40px)';
246 break;
247 case 'ablocks-hotspot-slideInRight':
248 $translateX_start = 'calc(-50% + 40px)';
249 break;
250 case 'ablocks-hotspot-slideInTop':
251 $translateY_start = 'calc(-100% - 60px)';
252 break;
253 case 'ablocks-hotspot-slideInBottom':
254 $translateY_start = 'calc(-100% + 40px)';
255 break;
256 }
257 break;
258
259 case 'bottom':
260 $translateX_end = '-50%';
261 $translateY_end = '40px';
262 $translateX_start = $translateX_end;
263 $translateY_start = $translateY_end;
264
265 switch ( $content_animation ) {
266 case 'ablocks-hotspot-slideInLeft':
267 $translateX_start = 'calc(-50% - 40px)';
268 break;
269 case 'ablocks-hotspot-slideInRight':
270 $translateX_start = 'calc(-50% + 40px)';
271 break;
272 case 'ablocks-hotspot-slideInTop':
273 $translateY_start = 'calc(40px - 40px)';
274 break;
275 case 'ablocks-hotspot-slideInBottom':
276 $translateY_start = 'calc(40px + 40px)';
277 break;
278 }
279 break;
280
281 case 'left':
282 $translateX_end = 'calc(-100% - 40px)';
283 $translateY_end = '-50%';
284 $translateX_start = $translateX_end;
285 $translateY_start = $translateY_end;
286
287 switch ( $content_animation ) {
288 case 'ablocks-hotspot-slideInLeft':
289 $translateX_start = 'calc(-100% - 40px - 40px)';
290 break;
291 case 'ablocks-hotspot-slideInRight':
292 $translateX_start = 'calc(-100% - 40px + 40px)';
293 break;
294 case 'ablocks-hotspot-slideInTop':
295 $translateY_start = 'calc(-50% - 40px)';
296 break;
297 case 'ablocks-hotspot-slideInBottom':
298 $translateY_start = 'calc(-50% + 40px)';
299 break;
300 }
301 break;
302
303 case 'right':
304 $translateX_end = '40px';
305 $translateY_end = '-50%';
306 $translateX_start = $translateX_end;
307 $translateY_start = $translateY_end;
308
309 switch ( $content_animation ) {
310 case 'ablocks-hotspot-slideInLeft':
311 $translateX_start = 'calc(40px - 40px)';
312 break;
313 case 'ablocks-hotspot-slideInRight':
314 $translateX_start = 'calc(40px + 40px)';
315 break;
316 case 'ablocks-hotspot-slideInTop':
317 $translateY_start = 'calc(-50% - 40px)';
318 break;
319 case 'ablocks-hotspot-slideInBottom':
320 $translateY_start = 'calc(-50% + 40px)';
321 break;
322 }
323 break;
324 }//end switch
325
326 // Return the final styles as an array
327 return [
328 'animation' => $animation_style,
329 'transform' => $content_transform,
330 '--ablocks-hotspot-translateX-start' => $translateX_start,
331 '--ablocks-hotspot-translateY-start' => $translateY_start,
332 '--ablocks-hotspot-translateX-end' => $translateX_end,
333 '--ablocks-hotspot-translateY-end' => $translateY_end,
334 ];
335 }
336
337 public function get_active_content_css( $attributes, $device = '' ) {
338 $css = array();
339 if ( isset( $width[ 'value' . $device ] ) && ! empty( $width[ 'value' . $device ] ) ) {
340
341 if ( ! empty( $width[ 'valueUnit' . $device ] ) ) {
342 $css['width'] = $width[ 'value' . $device ] . $width[ 'valueUnit' . $device ];
343 } else {
344 $css['width'] = $width[ 'value' . $device ] . 'px';
345 }
346 }
347
348 $css = array_merge(
349 [ 'background' => Color::get_css( isset( $attributes['backgroundColor'] ) ? $attributes['backgroundColor'] : '' ) ],
350 $css,
351 Range::get_css([
352 'attributeValue' => $attributes['childWidth'],
353 'attribute_object_key' => 'value',
354 'isResponsive' => true,
355 'defaultValue' => 200,
356 'hasUnit' => true,
357 'unitDefaultValue' => 'px',
358 'property' => 'width',
359 'device' => $device,
360 ]),
361 isset( $attributes['commonBoxShadow'] ) ? BoxShadow::get_css( $attributes['commonBoxShadow'], '', $device ) : [] );
362
363 return $css;
364 }
365
366 public function get_active_content_hover_css( $attributes, $device = '' ) {
367
368 $css = isset( $attributes['commonBoxShadow'] ) ? BoxShadow::get_hover_css( $attributes['commonBoxShadow'], '', $device ) : [];
369
370 return $css;
371 }
372
373 }
374