PluginProbe
Bricksable for Bricks Builder / 1.3.8
Bricksable for Bricks Builder v1.3.8
1.2.9 1.3.0 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.31 1.4.32 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 All 132 releases
bricksable / includes / elements / element-floating.php

element-floating.php in Bricksable for Bricks Builder 1.3.8, at includes/elements/element-floating.php

701 lines 19.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly.
5 }
6
7 class Bricksable_Floating extends \Bricks\Element {
8 public $category = 'bricksable';
9 public $name = 'ba-floating';
10 public $icon = 'ti-layers-alt';
11
12 public function get_label() {
13 return esc_html__( 'Floating', 'bricksable' );
14 }
15 public function set_control_groups() {
16 $this->control_groups['items'] = array(
17 'title' => esc_html__( 'Float items', 'bricksable' ),
18 'tab' => 'content',
19 );
20 $this->control_groups['item'] = array(
21 'title' => esc_html__( 'Float item / layout', 'bricksable' ),
22 'tab' => 'content',
23 );
24 $this->control_groups['image'] = array(
25 'title' => esc_html__( 'Image', 'bricksable' ),
26 'tab' => 'content',
27 );
28 $this->control_groups['icon'] = array(
29 'title' => esc_html__( 'Icon', 'bricksable' ),
30 'tab' => 'content',
31 );
32 $this->control_groups['title'] = array(
33 'title' => esc_html__( 'Title', 'bricksable' ),
34 'tab' => 'content',
35 );
36 $this->control_groups['settings'] = array(
37 'title' => esc_html__( 'Floating Settings', 'bricksable' ),
38 'tab' => 'content',
39 );
40
41 }
42 public function set_controls() {
43 // Items.
44 $this->controls['items'] = array(
45 'tab' => 'content',
46 'group' => 'items',
47 'placeholder' => esc_html__( 'Float items', 'bricksable' ),
48 'type' => 'repeater',
49 'titleProperty' => 'title',
50 'fields' => array(
51 'title' => array(
52 'label' => esc_html__( 'Title', 'bricksable' ),
53 'type' => 'text',
54 'hasDynamicData' => 'text',
55 'inlineEditing' => array(
56 'selector' => '.title',
57 ),
58 ),
59 'link' => array(
60 'label' => esc_html__( 'Link', 'bricksable' ),
61 'type' => 'link',
62 ),
63 'top' => array(
64 'label' => esc_html__( 'Vertical Position', 'bricksable' ),
65 'type' => 'slider',
66 'css' => array(
67 array(
68 'property' => 'top',
69 // 'repeaterSelector' => '.ba-floating-item',
70 ),
71 ),
72 'units' => array(
73 '%' => array(
74 'min' => 0,
75 'max' => 100,
76 'step' => 10,
77 ),
78
79 ),
80 ),
81 'left' => array(
82 'label' => esc_html__( 'Horizontal Position', 'bricksable' ),
83 'type' => 'slider',
84 'css' => array(
85 array(
86 'property' => 'left',
87 // 'repeaterSelector' => '.ba-floating-item',
88 ),
89 ),
90 'units' => array(
91 '%' => array(
92 'min' => 0,
93 'max' => 100,
94 'step' => 10,
95 ),
96
97 ),
98 ),
99 'use_image' => array(
100 'label' => esc_html__( 'Use Image', 'bricksable' ),
101 'type' => 'checkbox',
102 'inline' => true,
103 ),
104 'image' => array(
105 'label' => esc_html__( 'Image', 'bricksable' ),
106 'type' => 'image',
107 'required' => array( 'use_image', '=', true ),
108 ),
109 'image_border' => array(
110 'label' => esc_html__( 'Image Border', 'bricksable' ),
111 'type' => 'border',
112 'css' => array(
113 array(
114 'property' => 'border',
115 'selector' => '.ba-floating-image',
116 ),
117 ),
118 'required' => array( 'use_image', '=', true ),
119 ),
120 'image_box_shadow' => array(
121 'label' => esc_html__( 'Image Box Shadow', 'bricksable' ),
122 'type' => 'box-shadow',
123 'css' => array(
124 array(
125 'property' => 'box-shadow',
126 'selector' => '.ba-floating-image',
127 ),
128 ),
129 'required' => array( 'use_image', '=', true ),
130 ),
131 'use_icon' => array(
132 'label' => esc_html__( 'Use Icon', 'bricksable' ),
133 'type' => 'checkbox',
134 'inline' => true,
135 ),
136 'icon' => array(
137 'label' => esc_html__( 'Icon', 'bricksable' ),
138 'type' => 'icon',
139 'required' => array( 'use_icon', '=', true ),
140 ),
141 'icon_typography' => array(
142 'label' => esc_html__( 'Icon typography', 'bricksable' ),
143 'type' => 'typography',
144 'exclude' => array(
145 'font-family',
146 'font-weight',
147 'font-style',
148 'text-align',
149 'text-transform',
150 'text-decoration',
151 'line-height',
152 'letter-spacing',
153 ),
154 'css' => array(
155 array(
156 'property' => 'font',
157 'selector' => '.icon',
158 ),
159 ),
160 'inline' => true,
161 'small' => true,
162 'required' => array( 'use_icon', '=', true ),
163 ),
164 'use_gradient' => array(
165 'label' => esc_html__( 'Use Gradient / Overlay', 'bricksable' ),
166 'type' => 'checkbox',
167 'inline' => true,
168 ),
169 'gradient' => array(
170 'label' => esc_html__( 'Gradient', 'bricksable' ),
171 'type' => 'gradient',
172 'css' => array(
173 array(
174 'property' => 'background-image',
175 // 'repeaterSelector' => '.ba-floating-item',
176 ),
177 ),
178 'required' => array( 'use_gradient', '=', true ),
179 ),
180 'width' => array(
181 'label' => esc_html__( 'Item Width', 'bricksable' ),
182 'type' => 'slider',
183 'default' => '100%',
184 'css' => array(
185 array(
186 'property' => 'max-width',
187 ),
188 ),
189 'units' => array(
190 '%' => array(
191 'min' => 1,
192 'max' => 100,
193 'step' => 1,
194 ),
195 'px' => array(
196 'min' => 1,
197 'max' => 1600,
198 'step' => 1,
199 ),
200 ),
201 ),
202 'padding' => array(
203 'label' => esc_html__( 'Item Padding', 'bricksable' ),
204 'type' => 'dimensions',
205 'css' => array(
206 array(
207 'property' => 'padding',
208 ),
209 ),
210 ),
211 'border' => array(
212 'label' => esc_html__( 'Item Border', 'bricksable' ),
213 'type' => 'border',
214 'css' => array(
215 array(
216 'property' => 'border',
217 ),
218 array(
219 'property' => 'overflow',
220 'value' => 'hidden',
221 ),
222 ),
223 ),
224 'box_shadow' => array(
225 'label' => esc_html__( 'Item Box Shadow', 'bricksable' ),
226 'type' => 'box-shadow',
227 'css' => array(
228 array(
229 'property' => 'box-shadow',
230 ),
231 ),
232 ),
233 ),
234 'default' => array(
235 array(
236 'use_gradient' => false,
237 'use_image' => true,
238 'use_icon' => false,
239 'image' => array(
240 'full' => 'https://source.unsplash.com/random/700x700?animal',
241 'url' => 'https://source.unsplash.com/random/400x400?animal',
242 ),
243 'top' => '0%',
244 'left' => '0%',
245 ),
246 array(
247 'use_gradient' => false,
248 'use_image' => true,
249 'use_icon' => false,
250 'image' => array(
251 'full' => 'https://source.unsplash.com/random/700x700?human',
252 'url' => 'https://source.unsplash.com/random/400x400?human',
253 ),
254 'top' => '20%',
255 'left' => '20%',
256 ),
257 ),
258 );
259
260 // Item.
261 $this->controls['item_direction'] = array(
262 'tab' => 'content',
263 'group' => 'item',
264 'label' => esc_html__( 'Content Direction (Title & Icon)', 'bricksable' ),
265 'title' => 'flex-direction',
266 'type' => 'select',
267 'options' => $this->control_options['flexDirection'],
268 'css' => array(
269 array(
270 'property' => 'flex-direction',
271 'selector' => '.ba-floating-item .content-wrapper',
272 ),
273 ),
274 'default' => 'column',
275 'placeholder' => esc_html__( 'Stacked (Column)', 'bricksable' ),
276 );
277
278 $this->controls['item_padding'] = array(
279 'tab' => 'content',
280 'group' => 'item',
281 'label' => esc_html__( 'Padding', 'bricksable' ),
282 'type' => 'dimensions',
283 'css' => array(
284 array(
285 'property' => 'padding',
286 'selector' => '.ba-floating-item',
287 ),
288 ),
289 );
290
291 $this->controls['item_width'] = array(
292 'tab' => 'content',
293 'group' => 'item',
294 'label' => esc_html__( 'Item width', 'bricksable' ),
295 'type' => 'slider',
296 'default' => '100%',
297 'css' => array(
298 array(
299 'property' => 'max-width',
300 'selector' => '.ba-floating-item',
301 ),
302 ),
303 'units' => array(
304 '%' => array(
305 'min' => 1,
306 'max' => 100,
307 'step' => 1,
308 ),
309 'px' => array(
310 'min' => 1,
311 'max' => 1600,
312 'step' => 1,
313 ),
314 ),
315 );
316
317 $this->controls['item_border'] = array(
318 'tab' => 'content',
319 'group' => 'item',
320 'label' => esc_html__( 'Item border', 'bricksable' ),
321 'type' => 'border',
322 'css' => array(
323 array(
324 'property' => 'border',
325 'selector' => '.ba-floating-item',
326 ),
327 ),
328 'inline' => true,
329 'small' => true,
330 );
331
332 $this->controls['item_shadow'] = array(
333 'tab' => 'content',
334 'group' => 'item',
335 'label' => esc_html__( 'Item shadow', 'bricksable' ),
336 'type' => 'box-shadow',
337 'css' => array(
338 array(
339 'property' => 'box-shadow',
340 'selector' => '.ba-floating-item',
341 ),
342 ),
343 'inline' => true,
344 'small' => true,
345 );
346
347 // Title.
348 $this->controls['title_margin'] = array(
349 'tab' => 'content',
350 'group' => 'title',
351 'label' => esc_html__( 'Margin', 'bricksable' ),
352 'type' => 'dimensions',
353 'css' => array(
354 array(
355 'property' => 'margin',
356 'selector' => '.content-wrapper .title-wrapper .title',
357 ),
358 ),
359 );
360
361 $this->controls['title_tag'] = array(
362 'tab' => 'content',
363 'group' => 'title',
364 'label' => esc_html__( 'Tag', 'bricksable' ),
365 'type' => 'select',
366 'options' => array(
367 'h1' => esc_html__( 'Heading 1 (h1)', 'bricksable' ),
368 'h2' => esc_html__( 'Heading 2 (h2)', 'bricksable' ),
369 'h3' => esc_html__( 'Heading 3 (h3)', 'bricksable' ),
370 'h4' => esc_html__( 'Heading 4 (h4)', 'bricksable' ),
371 'h5' => esc_html__( 'Heading 5 (h5)', 'bricksable' ),
372 'h6' => esc_html__( 'Heading 6 (h6)', 'bricksable' ),
373 'p' => esc_html__( 'Paragraph (p)', 'bricksable' ),
374 'span' => esc_html__( 'Span (span)', 'bricksable' ),
375 ),
376 'inline' => true,
377 'placeholder' => 'h4',
378 );
379
380 $this->controls['title_JustifyContent'] = array(
381 'tab' => 'content',
382 'group' => 'title',
383 'label' => esc_html__( 'Align', 'bricksable' ),
384 'type' => 'align-items',
385 'exclude' => array(
386 'stretch',
387 ),
388 'css' => array(
389 array(
390 'property' => 'justify-content',
391 'selector' => '.content-wrapper',
392 ),
393 ),
394 'inline' => true,
395 );
396
397 $this->controls['title_verticalAlign'] = array(
398 'tab' => 'style',
399 'group' => 'title',
400 'label' => esc_html__( 'Vertical align', 'bricksable' ),
401 'type' => 'justify-content',
402 'exclude' => array(
403 'space-between',
404 'space-around',
405 'space-evenly',
406 ),
407 'css' => array(
408 array(
409 'property' => 'align-items',
410 'selector' => '.content-wrapper',
411 ),
412 ),
413 'inline' => true,
414 'default' => 'center',
415 'placeholder' => esc_html__( 'Center', 'bricksable' ),
416 );
417
418 $this->controls['titleTypography'] = array(
419 'tab' => 'content',
420 'group' => 'title',
421 'label' => esc_html__( 'Typography', 'bricksable' ),
422 'type' => 'typography',
423 'css' => array(
424 array(
425 'property' => 'font',
426 'selector' => '.title',
427 ),
428 ),
429 'inline' => true,
430 'small' => true,
431 );
432
433 // Image.
434 $this->controls['imageWidth'] = array(
435 'tab' => 'content',
436 'group' => 'image',
437 'label' => esc_html__( 'Image width', 'bricksable' ),
438 'type' => 'slider',
439 'default' => '100%',
440 'css' => array(
441 array(
442 'property' => 'max-width',
443 'selector' => '.ba-floating-image',
444 ),
445 ),
446 'units' => array(
447 '%' => array(
448 'min' => 1,
449 'max' => 100,
450 'step' => 1,
451 ),
452 'px' => array(
453 'min' => 1,
454 'max' => 1600,
455 'step' => 1,
456 ),
457 ),
458 );
459
460 $this->controls['imageBorder'] = array(
461 'tab' => 'content',
462 'group' => 'image',
463 'label' => esc_html__( 'Image border', 'bricksable' ),
464 'type' => 'border',
465 'css' => array(
466 array(
467 'property' => 'border',
468 'selector' => '.ba-floating-image',
469 ),
470 ),
471 'inline' => true,
472 'small' => true,
473 );
474
475 $this->controls['imageShadow'] = array(
476 'tab' => 'content',
477 'group' => 'image',
478 'label' => esc_html__( 'Image shadow', 'bricksable' ),
479 'type' => 'box-shadow',
480 'css' => array(
481 array(
482 'property' => 'box-shadow',
483 'selector' => '.ba-floating-image',
484 ),
485 ),
486 'inline' => true,
487 'small' => true,
488 );
489
490 // Icon.
491 $this->controls['icon_typography'] = array(
492 'tab' => 'content',
493 'group' => 'icon',
494 'label' => esc_html__( 'Icon typography', 'bricksable' ),
495 'type' => 'typography',
496 'exclude' => array(
497 'font-family',
498 'font-weight',
499 'text-align',
500 'text-transform',
501 'line-height',
502 'letter-spacing',
503 ),
504 'css' => array(
505 array(
506 'property' => 'font',
507 'selector' => '.icon',
508 ),
509 ),
510 'inline' => true,
511 'small' => true,
512 );
513 $this->controls['icon_border'] = array(
514 'tab' => 'content',
515 'group' => 'icon',
516 'label' => esc_html__( 'Icon border', 'bricksable' ),
517 'type' => 'border',
518 'css' => array(
519 array(
520 'property' => 'border',
521 'selector' => '.icon',
522 ),
523 ),
524 'inline' => true,
525 'small' => true,
526 );
527
528 $this->controls['icon_boxshadow'] = array(
529 'tab' => 'content',
530 'group' => 'icon',
531 'label' => esc_html__( 'Icon box shadow', 'bricksable' ),
532 'type' => 'box-shadow',
533 'css' => array(
534 array(
535 'property' => 'box-shadow',
536 'selector' => '.icon',
537 ),
538 ),
539 'inline' => true,
540 'small' => true,
541 );
542
543 // Animation.
544 $this->controls['height'] = array(
545 'tab' => 'content',
546 'group' => 'settings',
547 'label' => esc_html__( 'Height', 'bricksable' ),
548 'type' => 'slider',
549 'css' => array(
550 array(
551 'property' => 'min-height',
552 'selector' => '.ba-floating-wrapper',
553 ),
554 ),
555 'units' => array(
556 'px' => array(
557 'min' => 1,
558 'max' => 1600,
559 'step' => 1,
560 ),
561 ),
562 'default' => '460px',
563 'description' => esc_html__( "Adjust the floating container's height.", 'bricksable' ),
564 );
565
566 $this->controls['animation'] = array(
567 'tab' => 'content',
568 'group' => 'settings',
569 'label' => esc_html__( 'Animation Type', 'bricksable' ),
570 'type' => 'select',
571 'options' => array(
572 'horizontal' => esc_html__( 'Horizontal', 'bricksable' ),
573 'vertical' => esc_html__( 'Vertical', 'bricksable' ),
574 ),
575 'default' => 'vertical',
576 'inline' => true,
577 'placeholder' => esc_html__( 'Vertical', 'bricksable' ),
578 );
579
580 $this->controls['animation_speed'] = array(
581 'tab' => 'content',
582 'group' => 'settings',
583 'label' => esc_html__( 'Animation Speed', 'bricksable' ),
584 'type' => 'slider',
585 'css' => array(
586 array(
587 'property' => 'animation-duration',
588 'selector' => '.ba-floating-wrapper .ba-floating-item',
589 ),
590 ),
591 'units' => array(
592 's' => array(
593 'min' => 2,
594 'max' => 10,
595 'step' => 1,
596 ),
597 ),
598 'default' => '6s',
599 'placeholder' => esc_html__( '6', 'bricksable' ),
600 'description' => esc_html__( 'Increase or decrease the speed.', 'bricksable' ),
601 );
602 }
603
604 public function render() {
605 $settings = $this->settings;
606
607 $items = $settings['items'];
608 // Wrapper.
609 $wrapper_classes = array( 'ba-floating-wrapper', 'ba-floating-animation-' . $settings['animation'] );
610 $this->set_attribute( 'wrapper', 'class', $wrapper_classes );
611
612 ?>
613 <div <?php echo $this->render_attributes( 'wrapper' ); //phpcs:ignore ?>>
614 <?php
615 if ( count( $items ) ) {
616 foreach ( $items as $index => $item ) {
617 $content_image_classes = isset( $item['use_image'] ) && null !== $item['use_image'] || isset( $item['title'] ) && ! empty( $item['title'] ) ? 'ba-floating-image-title' : '';
618 $no_image_classes = null === $item['use_image'] ? 'ba-floating-no-image' : '';
619 $item_classes = array( 'ba-floating-item', 'repeater-item', $content_image_classes, $no_image_classes );
620 $temp_string = 'calc(500ms - ';
621 $delay_animation = 'animation-delay: ' . $temp_string . $index . '000ms);';
622 $this->set_attribute( "floating-item-{$index}", 'class', $item_classes );
623 $this->set_attribute( "floating-item-{$index}", 'style', esc_attr( $delay_animation ) );
624
625 // Image.
626 $image_atts = array();
627 $image_atts['id'] = isset( $image_atts['id'] ) ? 'image-' . $item['image']['id'] : '';
628 $item_image_classes = array( 'ba-floating-image', 'css-filter' );
629 $item_image_classes[] = isset( $item['image']['size'] ) ? 'size-' . $item['image']['size'] : '';
630 $image_atts['class'] = join( ' ', $item_image_classes );
631 $this->set_attribute( "floating-image-{$index}", 'class', $item_image_classes );
632 $this->set_attribute( "floating-image-{$index}", 'src', esc_url( $item['image']['url'] ) );
633 ?>
634
635 <div <?php echo $this->render_attributes( "floating-item-$index" ); //phpcs:ignore ?>>
636 <?php
637 if ( isset( $item['link'] ) ) {
638 $this->set_link_attributes( "a-$index", $item['link'] );
639 echo '<a ' . $this->render_attributes( "a-$index" ) . '>'; //phpcs:ignore
640 }
641 if ( isset( $item['use_image'] ) && null !== $item['use_image'] ) {
642 // Lazy load atts set via 'wp_get_attachment_image_attributes' filter.
643 if ( isset( $item['image']['id'] ) ) {
644 echo wp_get_attachment_image( $item['image']['id'], $item['image']['size'], false, $image_atts );
645 } elseif ( ! empty( $item['image']['url'] ) ) {
646 echo '<img ' . $this->render_attributes( "floating-image-{$index}" ) . '>'; //phpcs:ignore
647 }
648 }
649
650 // Title.
651 if ( ( isset( $item['title'] ) && ! empty( $item['title'] ) ) || isset( $item['use_icon'] ) && null !== $item['use_icon'] ) {
652 $title_tag = isset( $settings['title_tag'] ) ? esc_attr( $settings['title_tag'] ) : 'h4';
653 $title = isset( $item['title'] ) && ! empty( $item['title'] ) ? esc_html( $item['title'] ) : '';
654 $this->set_attribute( "title-$index", $title_tag );
655 $this->set_attribute( "title-$index", 'class', array( 'title' ) );
656 $this->set_attribute( "content-wrapper-$index", 'class', array( 'content-wrapper' ) );
657
658 // Icon.
659 if ( isset( $item['icon']['icon'] ) ) {
660 $this->set_attribute(
661 "icon-{$index}",
662 'class',
663 array(
664 'icon',
665 $item['icon']['icon'],
666 )
667 );
668 }
669 $this->set_attribute( "icon-wrapper-$index", 'class', 'icon-wrapper' );
670
671 echo '<div ' . $this->render_attributes( "content-wrapper-{$index}" ) . '>'; //phpcs:ignore
672
673 if ( isset( $item['icon']['icon'] ) && null !== $item['use_icon'] ) {
674 echo '<div ' . $this->render_attributes( "icon-wrapper-{$index}" ) . '>'; //phpcs:ignore
675 echo '<i ' . $this->render_attributes( "icon-{$index}" ) . '></i>'; //phpcs:ignore
676 echo '</div>';
677 }
678 echo '<div class="title-wrapper">';
679 echo '<' . $this->render_attributes( "title-$index" ) . '>' . esc_html( $title ) . '</' . esc_html( $title_tag ) . '>'; //phpcs:ignore
680 echo '</div></div>';
681 }
682 if ( isset( $item['link'] ) ) {
683 echo '</a>';
684 }
685 ?>
686 </div>
687
688 <?php
689 }
690 ?>
691 <?php
692 } else {
693 esc_html_e( 'No items defined.', 'bricksable' );
694 }
695
696 ?>
697 </div>
698 <?php
699 }
700 }
701