PluginProbe
Bricksable for Bricks Builder / 1.5.7
Bricksable for Bricks Builder v1.5.7
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 / floating / element-floating.php

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

709 lines 19.9 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' => 'number',
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' => 'number',
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' => 'number',
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 'type' => 'direction',
266 'css' => array(
267 array(
268 'property' => 'flex-direction',
269 'selector' => '.ba-floating-item .content-wrapper',
270 ),
271 ),
272 'default' => 'column',
273 'placeholder' => esc_html__( 'Stacked (Column)', 'bricksable' ),
274 );
275
276 $this->controls['item_padding'] = array(
277 'tab' => 'content',
278 'group' => 'item',
279 'label' => esc_html__( 'Padding', 'bricksable' ),
280 'type' => 'dimensions',
281 'css' => array(
282 array(
283 'property' => 'padding',
284 'selector' => '.ba-floating-item',
285 ),
286 ),
287 );
288
289 $this->controls['item_width'] = array(
290 'tab' => 'content',
291 'group' => 'item',
292 'label' => esc_html__( 'Item width', 'bricksable' ),
293 'type' => 'number',
294 'default' => '100%',
295 'css' => array(
296 array(
297 'property' => 'max-width',
298 'selector' => '.ba-floating-item',
299 ),
300 ),
301 'units' => array(
302 '%' => array(
303 'min' => 1,
304 'max' => 100,
305 'step' => 1,
306 ),
307 'px' => array(
308 'min' => 1,
309 'max' => 1600,
310 'step' => 1,
311 ),
312 ),
313 );
314
315 $this->controls['item_border'] = array(
316 'tab' => 'content',
317 'group' => 'item',
318 'label' => esc_html__( 'Item border', 'bricksable' ),
319 'type' => 'border',
320 'css' => array(
321 array(
322 'property' => 'border',
323 'selector' => '.ba-floating-item',
324 ),
325 ),
326 'inline' => true,
327 'small' => true,
328 );
329
330 $this->controls['item_shadow'] = array(
331 'tab' => 'content',
332 'group' => 'item',
333 'label' => esc_html__( 'Item shadow', 'bricksable' ),
334 'type' => 'box-shadow',
335 'css' => array(
336 array(
337 'property' => 'box-shadow',
338 'selector' => '.ba-floating-item',
339 ),
340 ),
341 'inline' => true,
342 'small' => true,
343 );
344
345 // Title.
346 $this->controls['title_margin'] = array(
347 'tab' => 'content',
348 'group' => 'title',
349 'label' => esc_html__( 'Margin', 'bricksable' ),
350 'type' => 'dimensions',
351 'css' => array(
352 array(
353 'property' => 'margin',
354 'selector' => '.content-wrapper .title-wrapper .title',
355 ),
356 ),
357 );
358
359 $this->controls['title_tag'] = array(
360 'tab' => 'content',
361 'group' => 'title',
362 'label' => esc_html__( 'Tag', 'bricksable' ),
363 'type' => 'select',
364 'options' => array(
365 'h1' => esc_html__( 'Heading 1 (h1)', 'bricksable' ),
366 'h2' => esc_html__( 'Heading 2 (h2)', 'bricksable' ),
367 'h3' => esc_html__( 'Heading 3 (h3)', 'bricksable' ),
368 'h4' => esc_html__( 'Heading 4 (h4)', 'bricksable' ),
369 'h5' => esc_html__( 'Heading 5 (h5)', 'bricksable' ),
370 'h6' => esc_html__( 'Heading 6 (h6)', 'bricksable' ),
371 'p' => esc_html__( 'Paragraph (p)', 'bricksable' ),
372 'span' => esc_html__( 'Span (span)', 'bricksable' ),
373 ),
374 'inline' => true,
375 'placeholder' => 'h4',
376 );
377
378 $this->controls['title_JustifyContent'] = array(
379 'tab' => 'content',
380 'group' => 'title',
381 'label' => esc_html__( 'Align', 'bricksable' ),
382 'type' => 'align-items',
383 'exclude' => array(
384 'stretch',
385 ),
386 'css' => array(
387 array(
388 'property' => 'justify-content',
389 'selector' => '.content-wrapper',
390 ),
391 ),
392 'inline' => true,
393 );
394
395 $this->controls['title_verticalAlign'] = array(
396 'tab' => 'style',
397 'group' => 'title',
398 'label' => esc_html__( 'Vertical align', 'bricksable' ),
399 'type' => 'justify-content',
400 'exclude' => array(
401 'space-between',
402 'space-around',
403 'space-evenly',
404 ),
405 'css' => array(
406 array(
407 'property' => 'align-items',
408 'selector' => '.content-wrapper',
409 ),
410 ),
411 'inline' => true,
412 'default' => 'center',
413 'placeholder' => esc_html__( 'Center', 'bricksable' ),
414 );
415
416 $this->controls['titleTypography'] = array(
417 'tab' => 'content',
418 'group' => 'title',
419 'label' => esc_html__( 'Typography', 'bricksable' ),
420 'type' => 'typography',
421 'css' => array(
422 array(
423 'property' => 'font',
424 'selector' => '.title',
425 ),
426 ),
427 'inline' => true,
428 'small' => true,
429 );
430
431 // Image.
432 $this->controls['imageWidth'] = array(
433 'tab' => 'content',
434 'group' => 'image',
435 'label' => esc_html__( 'Image width', 'bricksable' ),
436 'type' => 'number',
437 'default' => '100%',
438 'css' => array(
439 array(
440 'property' => 'max-width',
441 'selector' => '.ba-floating-image',
442 ),
443 ),
444 'units' => array(
445 '%' => array(
446 'min' => 1,
447 'max' => 100,
448 'step' => 1,
449 ),
450 'px' => array(
451 'min' => 1,
452 'max' => 1600,
453 'step' => 1,
454 ),
455 ),
456 );
457
458 $this->controls['imageBorder'] = array(
459 'tab' => 'content',
460 'group' => 'image',
461 'label' => esc_html__( 'Image border', 'bricksable' ),
462 'type' => 'border',
463 'css' => array(
464 array(
465 'property' => 'border',
466 'selector' => '.ba-floating-image',
467 ),
468 ),
469 'inline' => true,
470 'small' => true,
471 );
472
473 $this->controls['imageShadow'] = array(
474 'tab' => 'content',
475 'group' => 'image',
476 'label' => esc_html__( 'Image shadow', 'bricksable' ),
477 'type' => 'box-shadow',
478 'css' => array(
479 array(
480 'property' => 'box-shadow',
481 'selector' => '.ba-floating-image',
482 ),
483 ),
484 'inline' => true,
485 'small' => true,
486 );
487
488 // Icon.
489 $this->controls['icon_typography'] = array(
490 'tab' => 'content',
491 'group' => 'icon',
492 'label' => esc_html__( 'Icon typography', 'bricksable' ),
493 'type' => 'typography',
494 'exclude' => array(
495 'font-family',
496 'font-weight',
497 'text-align',
498 'text-transform',
499 'line-height',
500 'letter-spacing',
501 ),
502 'css' => array(
503 array(
504 'property' => 'font',
505 'selector' => '.icon',
506 ),
507 ),
508 'inline' => true,
509 'small' => true,
510 );
511 $this->controls['icon_border'] = array(
512 'tab' => 'content',
513 'group' => 'icon',
514 'label' => esc_html__( 'Icon border', 'bricksable' ),
515 'type' => 'border',
516 'css' => array(
517 array(
518 'property' => 'border',
519 'selector' => '.icon',
520 ),
521 ),
522 'inline' => true,
523 'small' => true,
524 );
525
526 $this->controls['icon_boxshadow'] = array(
527 'tab' => 'content',
528 'group' => 'icon',
529 'label' => esc_html__( 'Icon box shadow', 'bricksable' ),
530 'type' => 'box-shadow',
531 'css' => array(
532 array(
533 'property' => 'box-shadow',
534 'selector' => '.icon',
535 ),
536 ),
537 'inline' => true,
538 'small' => true,
539 );
540
541 // Animation.
542 $this->controls['height'] = array(
543 'tab' => 'content',
544 'group' => 'settings',
545 'label' => esc_html__( 'Height', 'bricksable' ),
546 'type' => 'number',
547 'css' => array(
548 array(
549 'property' => 'min-height',
550 'selector' => '.ba-floating-wrapper',
551 ),
552 ),
553 'units' => array(
554 'px' => array(
555 'min' => 1,
556 'max' => 1600,
557 'step' => 1,
558 ),
559 ),
560 'default' => '460px',
561 'description' => esc_html__( "Adjust the floating container's height.", 'bricksable' ),
562 );
563
564 $this->controls['animation'] = array(
565 'tab' => 'content',
566 'group' => 'settings',
567 'label' => esc_html__( 'Animation Type', 'bricksable' ),
568 'type' => 'select',
569 'options' => array(
570 'horizontal' => esc_html__( 'Horizontal', 'bricksable' ),
571 'vertical' => esc_html__( 'Vertical', 'bricksable' ),
572 ),
573 'default' => 'vertical',
574 'inline' => true,
575 'placeholder' => esc_html__( 'Vertical', 'bricksable' ),
576 );
577
578 $this->controls['animation_speed'] = array(
579 'tab' => 'content',
580 'group' => 'settings',
581 'label' => esc_html__( 'Animation Speed', 'bricksable' ),
582 'type' => 'number',
583 'css' => array(
584 array(
585 'property' => 'animation-duration',
586 'selector' => '.ba-floating-wrapper .ba-floating-item',
587 ),
588 ),
589 'units' => array(
590 's' => array(
591 'min' => 2,
592 'max' => 10,
593 'step' => 1,
594 ),
595 ),
596 'default' => '6s',
597 'placeholder' => esc_html__( '6', 'bricksable' ),
598 'description' => esc_html__( 'Increase or decrease the speed.', 'bricksable' ),
599 );
600 }
601
602 public function enqueue_scripts() {
603 wp_enqueue_style( 'ba-floating' );
604 }
605
606 public function render() {
607 $settings = $this->settings;
608
609 $items = $settings['items'];
610 // Wrapper.
611 $wrapper_classes = array( 'ba-floating-wrapper', 'ba-floating-animation-' . $settings['animation'] );
612 $this->set_attribute( 'wrapper', 'class', $wrapper_classes );
613 if ( substr( BRICKS_VERSION, 0, 3 ) > '1.3' ) {
614 //phpcs:ignore
615 echo "<div {$this->render_attributes( '_root' )}>";
616 }
617 ?>
618 <div <?php echo $this->render_attributes( 'wrapper' ); //phpcs:ignore ?>>
619 <?php
620 if ( count( $items ) ) {
621 foreach ( $items as $index => $item ) {
622 $content_image_classes = isset( $item['use_image'] ) && null !== $item['use_image'] || isset( $item['title'] ) && ! empty( $item['title'] ) ? 'ba-floating-image-title' : '';
623 $no_image_classes = isset( $item['use_image'] ) && null !== $item['use_image'] ? 'ba-floating-no-image' : '';
624 $item_classes = array( 'ba-floating-item', 'repeater-item', $content_image_classes, $no_image_classes );
625 $temp_string = 'calc(500ms - ';
626 $delay_animation = 'animation-delay: ' . $temp_string . $index . '000ms);';
627 $this->set_attribute( "floating-item-{$index}", 'class', $item_classes );
628 $this->set_attribute( "floating-item-{$index}", 'style', esc_attr( $delay_animation ) );
629
630 // Image.
631 $image_atts = array();
632 $image_atts['id'] = isset( $image_atts['id'] ) ? 'image-' . $item['image']['id'] : '';
633 $item_image_classes = array( 'ba-floating-image', 'css-filter' );
634 $item_image_classes[] = isset( $item['image']['size'] ) ? 'size-' . $item['image']['size'] : '';
635 $image_atts['class'] = join( ' ', $item_image_classes );
636 $this->set_attribute( "floating-image-{$index}", 'class', $item_image_classes );
637 $this->set_attribute( "floating-image-{$index}", 'src', esc_url( $item['image']['url'] ) );
638 ?>
639
640 <div <?php echo $this->render_attributes( "floating-item-$index" ); //phpcs:ignore ?>>
641 <?php
642 if ( isset( $item['link'] ) ) {
643 $this->set_link_attributes( "a-$index", $item['link'] );
644 echo '<a ' . $this->render_attributes( "a-$index" ) . '>'; //phpcs:ignore
645 }
646 if ( isset( $item['use_image'] ) && null !== $item['use_image'] ) {
647 // Lazy load atts set via 'wp_get_attachment_image_attributes' filter.
648 if ( isset( $item['image']['id'] ) ) {
649 echo wp_get_attachment_image( $item['image']['id'], $item['image']['size'], false, $image_atts );
650 } elseif ( ! empty( $item['image']['url'] ) ) {
651 echo '<img ' . $this->render_attributes( "floating-image-{$index}" ) . '>'; //phpcs:ignore
652 }
653 }
654
655 // Title.
656 if ( ( isset( $item['title'] ) && ! empty( $item['title'] ) ) || isset( $item['use_icon'] ) && null !== $item['use_icon'] ) {
657 $title_tag = isset( $settings['title_tag'] ) ? esc_attr( $settings['title_tag'] ) : 'h4';
658 $title = isset( $item['title'] ) && ! empty( $item['title'] ) ? esc_html( $item['title'] ) : '';
659 $this->set_attribute( "title-$index", $title_tag );
660 $this->set_attribute( "title-$index", 'class', array( 'title' ) );
661 $this->set_attribute( "content-wrapper-$index", 'class', array( 'content-wrapper' ) );
662
663 // Icon.
664 if ( isset( $item['icon']['icon'] ) ) {
665 $this->set_attribute(
666 "icon-{$index}",
667 'class',
668 array(
669 'icon',
670 $item['icon']['icon'],
671 )
672 );
673 }
674 $this->set_attribute( "icon-wrapper-$index", 'class', 'icon-wrapper' );
675
676 echo '<div ' . $this->render_attributes( "content-wrapper-{$index}" ) . '>'; //phpcs:ignore
677
678 if ( isset( $item['icon']['icon'] ) && null !== $item['use_icon'] ) {
679 echo '<div ' . $this->render_attributes( "icon-wrapper-{$index}" ) . '>'; //phpcs:ignore
680 echo '<i ' . $this->render_attributes( "icon-{$index}" ) . '></i>'; //phpcs:ignore
681 echo '</div>';
682 }
683 echo '<div class="title-wrapper">';
684 echo '<' . $this->render_attributes( "title-$index" ) . '>' . esc_html( $title ) . '</' . esc_html( $title_tag ) . '>'; //phpcs:ignore
685 echo '</div></div>';
686 }
687 if ( isset( $item['link'] ) ) {
688 echo '</a>';
689 }
690 ?>
691 </div>
692
693 <?php
694 }
695 ?>
696 <?php
697 } else {
698 esc_html_e( 'No items defined.', 'bricksable' );
699 }
700
701 ?>
702 </div>
703 <?php
704 if ( substr( BRICKS_VERSION, 0, 3 ) > '1.3' ) {
705 echo '</div>';
706 }
707 }
708 }
709