PluginProbe
UiCore Elements – Free widgets and templates for Elementor / 1.2.4
UiCore Elements – Free widgets and templates for Elementor v1.2.4
1.3.17 1.3.16 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 All 41 releases
uicore-elements / includes / utils / gallery-component.php

gallery-component.php in UiCore Elements – Free widgets and templates for Elementor 1.2.4, at includes/utils/gallery-component.php

1,184 lines 47.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace UiCoreElements\Utils;
3
4 use Elementor\Controls_Manager;
5 use Elementor\Utils;
6 use Elementor\Repeater;
7 use Elementor\Control_Media;
8 use Elementor\Group_Control_Image_Size;
9 use Elementor\Group_Control_Box_Shadow;
10 use Elementor\Group_Control_Border;
11 use Elementor\Group_Control_Typography;
12 use Elementor\Group_Control_Background;
13 use Elementor\Core\Kits\Documents\Tabs\Global_Colors;
14 use UiCoreElements\Helper;
15
16 use UiCoreElements\Utils\Carousel_Trait;
17
18
19 defined('ABSPATH') || exit();
20
21 /**
22 * Gallery Component
23 *
24 * @since 1.0.14
25 */
26
27
28 trait Gallery_Trait {
29
30 use Carousel_Trait;
31
32 // Controls Registration
33 function TRAIT_register_gallery_repeater_controls($title)
34 {
35 $this->start_controls_section(
36 'content_section',
37 [
38 /* translators: %s: Control title */
39 'label' => esc_html( sprintf('%s', $title), 'uicore-elements'),
40 'tab' => Controls_Manager::TAB_CONTENT,
41 ]
42 );
43
44 $repeater = new Repeater();
45 $repeater->add_control(
46 'item_image',
47 [
48 'label' => esc_html__('Image', 'uicore-elements'),
49 'type' => Controls_Manager::MEDIA,
50 'default' => [
51 'url' => Utils::get_placeholder_image_src(),
52 ],
53 ]
54 );
55 $repeater->add_control(
56 'item_url',
57 [
58 'label' => esc_html__('Link', 'uicore-elements'),
59 'type' => Controls_Manager::URL,
60 'placeholder' => 'https://your-link.com',
61 ]
62 );
63 $repeater->add_control(
64 'item_title',
65 [
66 'label' => esc_html__('Title', 'uicore-elements'),
67 'type' => Controls_Manager::TEXT,
68 'default' => esc_html__('Title', 'uicore-elements'),
69 'label_block' => true,
70 ]
71 );
72 $repeater->add_control(
73 'item_description',
74 [
75 'label' => esc_html__('Description', 'uicore-elements'),
76 'type' => Controls_Manager::TEXTAREA,
77 'label_block' => true,
78 ]
79 );
80 $repeater->add_control(
81 'item_badge',
82 [
83 'label' => esc_html__('Badge', 'uicore-elements'),
84 'type' => Controls_Manager::TEXT,
85 'label_block' => true,
86 ]
87 );
88 $repeater->add_control(
89 'item_tags',
90 [
91 'label' => esc_html__('Tags', 'uicore-elements'),
92 'type' => Controls_Manager::TEXT,
93 'description' => esc_html__('Separate tags with commas', 'uicore-elements'),
94 'label_block' => true,
95 ]
96 );
97
98 $this->add_control(
99 'gallery_items',
100 [
101 'label' => esc_html__('Items', 'uicore-elements'),
102 'type' => Controls_Manager::REPEATER,
103 'fields' => $repeater->get_controls(),
104 'default' => [
105 [
106 'item_title' => esc_html__('Item #1', 'uicore-elements'),
107 ],
108 [
109 'item_title' => esc_html__('Item #2', 'uicore-elements'),
110 ],
111 [
112 'item_title' => esc_html__('Item #3', 'uicore-elements'),
113 ],
114 [
115 'item_title' => esc_html__('Item #4', 'uicore-elements'),
116 ],
117 [
118 'item_title' => esc_html__('Item #5', 'uicore-elements'),
119 ],
120 [
121 'item_title' => esc_html__('Item #6', 'uicore-elements'),
122 ],
123 ],
124 'title_field' => '{{{ item_title }}}',
125 ]
126 );
127
128 $this->end_controls_section();
129 }
130 function TRAIT_register_additional_controls($carousel = false)
131 {
132 $this->start_controls_section(
133 'additional_section',
134 [
135 'label' => esc_html__('Additional', 'uicore-elements'),
136 'tab' => Controls_Manager::TAB_CONTENT,
137 ]
138 );
139 $this->add_control(
140 'layout',
141 [
142 'label' => esc_html__('Layout', 'uicore-elements'),
143 'type' => Controls_Manager::SELECT,
144 'default' => '',
145 'prefix_class' => '',
146 'render_type' => 'template',
147 'options' => [
148 '' => esc_html__('Default', 'uicore-elements'),
149 'ui-e-overlay' => esc_html__('Overlay', 'uicore-elements'),
150 ],
151 ]
152 );
153
154 $this->add_control(
155 'item_overflow',
156 [
157 'label' => esc_html__('Hide overflow', 'uicore-elements'),
158 'type' => Controls_Manager::SWITCHER,
159 'default' => 'no',
160 'prefix_class' => 'ui-e-overflow-',
161 'description' => __('Useful if you have an animation, on an image, for example, that surpasses the item area and you want to hide it.', 'uicore-elements'),
162 'condition' => [
163 'layout' => '',
164 ]
165 ]
166 );
167
168 $this->add_control(
169 'hide_tags',
170 [
171 'label' => __('Hide item tags', 'uicore-elements'),
172 'type' => Controls_Manager::SWITCHER,
173 'separator' => 'before',
174 'default' => 'no',
175 ]
176 );
177
178 $this->add_control(
179 'hide_title',
180 [
181 'label' => __('Hide title', 'uicore-elements'),
182 'type' => Controls_Manager::SWITCHER,
183 'default' => 'no',
184 ]
185 );
186
187 $this->add_control(
188 'hide_description',
189 [
190 'label' => __('Hide description', 'uicore-elements'),
191 'type' => Controls_Manager::SWITCHER,
192 'default' => 'no',
193 ]
194 );
195
196 if( ! $carousel ){
197 $this->add_control(
198 'filters',
199 [
200 'label' => __('Use filters', 'uicore-elements'),
201 'type' => Controls_Manager::SWITCHER,
202 'default' => 'no',
203 ]
204 );
205 $this->add_control(
206 'clear_text',
207 [
208 'label' => __('Clear Text', 'uicore-elements'),
209 'type' => Controls_Manager::TEXT,
210 'default' => __('All', 'uicore-elements'),
211 'placeholder' => __('Clear filter text', 'uicore-elements'),
212 'condition' => [
213 'filters' => 'yes'
214 ]
215 ]
216 );
217 }
218
219 $this->add_control(
220 'title_tag',
221 [
222 'label' => esc_html__('Title Tag', 'uicore-elements'),
223 'type' => Controls_Manager::SELECT,
224 'default' => 'h4',
225 'options' => Helper::get_title_tags(),
226 'separator' => 'before'
227 ]
228 );
229 $this->add_control(
230 'image_size',
231 [
232 'label' => esc_html__('Image Size', 'uicore-elements'),
233 'type' => Controls_Manager::SELECT,
234 'default' => 'uicore-medium',
235 'options' => Helper::get_images_sizes(),
236 ]
237 );
238 $this->add_control(
239 'content_position',
240 [
241 'label' => esc_html__('Content Position', 'uicore-elements'),
242 'type' => Controls_Manager::SELECT,
243 'default' => 'top',
244 'prefix_class' => 'ui-e-content-',
245 'options' => [
246 'top' => esc_html__('Top', 'uicore-elements'),
247 'center' => esc_html__('Center', 'uicore-elements'),
248 'bottom' => esc_html__('Bottom', 'uicore-elements'),
249 ],
250 'condition' => [
251 'layout' => 'ui-e-overlay',
252 ],
253 'selectors' => [
254 '{{WRAPPER}} .ui-e-content' => 'text-align:' . is_rtl() ? 'right' : 'left' . ';',
255 '{{WRAPPER}} .ui-e-title-wrapper' => 'justify-content:' . is_rtl() ? 'right' : 'left' . ';',
256 ],
257 ]
258 );
259 $this->add_control(
260 'badge_position',
261 [
262 'label' => esc_html__('Badge Position', 'uicore-elements'),
263 'type' => Controls_Manager::SELECT,
264 'default' => 'ui-e-badge-start-left',
265 'prefix_class' => '',
266 'render_type' => 'template', // without it, loading a page with image and changing to title won't work
267 'options' => [
268 '' => __('After title', 'uicore-elements'),
269 'ui-e-badge-start-left' => __('Image top left', 'uicore-elements'),
270 'ui-e-badge-start-right' => __('Image top right', 'uicore-elements'),
271 'ui-e-badge-end-left' => __('Image bottom left', 'uicore-elements'),
272 'ui-e-badge-end-right' => __('Image bottom right', 'uicore-elements'),
273 ],
274 ]
275 );
276
277 $this->end_controls_section();
278 }
279
280 function TRAIT_register_filters_style_controls()
281 {
282 $this->start_controls_section(
283 'style_filters_section',
284 [
285 'label' => __('Filters', 'uicore-elements'),
286 'tab' => Controls_Manager::TAB_STYLE,
287 'condition' => [
288 'filters' => 'yes',
289 ],
290 ]
291 );
292
293 $this->add_responsive_control(
294 'filters_align',
295 [
296 'label' => esc_html__( 'Alignment', 'uicore-elements' ),
297 'type' => Controls_Manager::CHOOSE,
298 'options' => [
299 'start' => [
300 'title' => esc_html__( 'Left', 'uicore-elements' ),
301 'icon' => 'eicon-h-align-left',
302 ],
303 'center' => [
304 'title' => esc_html__( 'Center', 'uicore-elements' ),
305 'icon' => 'eicon-h-align-center',
306 ],
307 'end' => [
308 'title' => esc_html__( 'Right', 'uicore-elements' ),
309 'icon' => 'eicon-h-align-right',
310 ],
311 ],
312 'default' => 'center',
313 'selectors' => [
314 '(desktop){{WRAPPER}} .ui-e-filters' => 'justify-content: {{VALUE}}',
315 '(mobile){{WRAPPER}} .ui-e-filters' => 'align-items: {{VALUE}}' // mobile version sets flex-direction as column
316 ]
317 ]
318 );
319 $this->add_control(
320 'filters_bottom_space',
321 [
322 'label' => __('Spacing', 'uicore-elements'),
323 'type' => Controls_Manager::SLIDER,
324 'range' => [
325 'px' => [
326 'min' => 0,
327 'max' => 50,
328 ],
329 ],
330 'default' => [
331 'size' => 10,
332 'unit' => 'px'
333 ],
334 'selectors' => [
335 '{{WRAPPER}} .ui-e-filters' => 'margin-bottom: {{SIZE}}{{UNIT}};',
336 ],
337 ]
338 );
339
340 $this->start_controls_tabs(
341 'filters_tabs',
342 [
343 'condition' => [
344 'filters' => 'yes',
345 ],
346 ]
347 );
348
349 $this->start_controls_tab(
350 'filters_normal_tab',
351 [
352 'label' => esc_html__( 'Normal', 'uicore-elements' ),
353 ]
354 );
355
356 $this->add_group_control(
357 Group_Control_Typography::get_type(),
358 [
359 'name' => 'filters_typography',
360 'selector' => '{{WRAPPER}} .ui-e-filters button',
361 ]
362 );
363 $this->add_control(
364 'filters_color',
365 [
366 'label' => __('Color', 'uicore-elements'),
367 'type' => Controls_Manager::COLOR,
368 'selectors' => [
369 '{{WRAPPER}} .ui-e-filters button' => 'color: {{VALUE}};',
370 ],
371 ]
372 );
373 $this->add_group_control(
374 Group_Control_Background::get_type(),
375 [
376 'name' => 'filters_background',
377 'selector' => '{{WRAPPER}} .ui-e-filters button',
378 ]
379 );
380 $this->add_group_control(
381 Group_Control_Border::get_type(),
382 [
383 'name' => 'filters_border',
384 'label' => esc_html__( 'Border', 'uicore-elements' ),
385 'selector' => '{{WRAPPER}} .ui-e-filters button',
386 ]
387 );
388 $this->add_group_control(
389 Group_Control_Box_Shadow::get_type(),
390 [
391 'name' => 'filters_box_shadow',
392 'selector' => '{{WRAPPER}} .ui-e-filters button',
393 ]
394 );
395
396 $this->end_controls_tab();
397
398 $this->start_controls_tab(
399 'filters_hover_tab',
400 [
401 'label' => esc_html__( 'Hover', 'uicore-elements' ),
402 ]
403 );
404
405 $this->add_control(
406 'filters_hover_color',
407 [
408 'label' => __('Color', 'uicore-elements'),
409 'type' => Controls_Manager::COLOR,
410 'selectors' => [
411 '{{WRAPPER}} .ui-e-filters button:hover' => 'color: {{VALUE}};',
412 ],
413 ]
414 );
415 $this->add_group_control(
416 Group_Control_Background::get_type(),
417 [
418 'name' => 'filters_hover_background',
419 'selector' => '{{WRAPPER}} .ui-e-filters button:hover',
420 ]
421 );
422 $this->add_group_control(
423 Group_Control_Border::get_type(),
424 [
425 'name' => 'filters_hover_border',
426 'label' => esc_html__( 'Border', 'uicore-elements' ),
427 'selector' => '{{WRAPPER}} .ui-e-filters button:hover',
428 ]
429 );
430 $this->add_group_control(
431 Group_Control_Box_Shadow::get_type(),
432 [
433 'name' => 'filters_hover_box_shadow',
434 'selector' => '{{WRAPPER}} .ui-e-filters button:hover',
435 ]
436 );
437
438 $this->end_controls_tab();
439
440 $this->start_controls_tab(
441 'filters_active_tab',
442 [
443 'label' => esc_html__( 'Active', 'uicore-elements' ),
444 ]
445 );
446
447 $this->add_control(
448 'filters_active_color',
449 [
450 'label' => __('Color', 'uicore-elements'),
451 'type' => Controls_Manager::COLOR,
452 'selectors' => [
453 '{{WRAPPER}} .ui-e-filters button.ui-e-active' => 'color: {{VALUE}};',
454 ],
455 ]
456 );
457 $this->add_group_control(
458 Group_Control_Background::get_type(),
459 [
460 'name' => 'filters_active_background',
461 'selector' => '{{WRAPPER}} .ui-e-filters button.ui-e-active',
462 ]
463 );
464 $this->add_group_control(
465 Group_Control_Border::get_type(),
466 [
467 'name' => 'filters_active_border',
468 'label' => esc_html__( 'Border', 'uicore-elements' ),
469 'selector' => '{{WRAPPER}} .ui-e-filters button.ui-e-active',
470 ]
471 );
472 $this->add_group_control(
473 Group_Control_Box_Shadow::get_type(),
474 [
475 'name' => 'filters_active_box_shadow',
476 'selector' => '{{WRAPPER}} .ui-e-filters button.ui-e-active',
477 ]
478 );
479
480 $this->end_controls_tab();
481
482 $this->end_controls_tabs();
483
484 $this->add_control(
485 'filters_separator',
486 [
487 'type' => Controls_Manager::DIVIDER,
488 ]
489 );
490
491 $this->add_control(
492 'filters_border_radius',
493 [
494 'label' => esc_html__( 'Border Radius', 'uicore-elements' ),
495 'type' => Controls_Manager::DIMENSIONS,
496 'size_units' => [ 'px', '%' ],
497 'selectors' => [
498 '{{WRAPPER}} .ui-e-filters button' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
499 ],
500 ]
501 );
502 $this->add_control(
503 'filters_padding',
504 [
505 'label' => esc_html__( 'Padding', 'uicore-elements' ),
506 'type' => Controls_Manager::DIMENSIONS,
507 'size_units' => [ 'px', 'em', '%' ],
508 'selectors' => [
509 '{{WRAPPER}} .ui-e-filters button' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
510 ],
511 ]
512 );
513
514 $this->end_controls_section();
515 }
516 function TRAIT_register_image_style_controls($is_carousel = false)
517 {
518 // Condition used by both image height and the image section
519 $condition = [
520 'relation' => 'or',
521 'terms' => [
522 [
523 'name' => 'layout',
524 'operator' => '==',
525 'value' => '',
526 ],
527 [
528 'relation' => 'and',
529 'terms' => [
530 [
531 'name' => 'layout',
532 'operator' => '==',
533 'value' => 'ui-e-overlay',
534 ],
535 [
536 'name' => 'masonry',
537 'operator' => '!==',
538 'value' => 'yes',
539 ]
540 ],
541 ],
542 ],
543 ];
544
545 $this->start_controls_section(
546 'style_image_section',
547 [
548 'label' => __('Image', 'uicore-elements'),
549 'tab' => Controls_Manager::TAB_STYLE,
550 'conditions' => $condition
551 ]
552 );
553
554 $this->add_responsive_control(
555 'image_height',
556 [
557 'label' => esc_html__('Image Height', 'uicore-elements'),
558 'type' => Controls_Manager::SLIDER,
559 'size_units' => ['px', 'em', 'vh'],
560 'range' => [
561 'px' => [
562 'min' => 50,
563 'max' => 500,
564 'step' => 5,
565 ],
566 'em' => [
567 'min' => 5,
568 'max' => 30,
569 'step' => 1,
570 ],
571 'vh' => [
572 'min' => 5,
573 'max' => 50,
574 ],
575 ],
576 'default' => [
577 'unit' => 'px',
578 'size' => 400,
579 ],
580 'selectors' => [
581 '{{WRAPPER}}' => '--ui-e-img-height: {{SIZE}}{{UNIT}};',
582 ],
583 'conditions' => $condition
584 ]
585 );
586
587 $this->add_control(
588 'image_bottom_space',
589 [
590 'label' => __('Spacing', 'uicore-elements'),
591 'type' => Controls_Manager::SLIDER,
592 'range' => [
593 'px' => [
594 'min' => 0,
595 'max' => 50,
596 ],
597 ],
598 'default' => [
599 'size' => 10,
600 'unit' => 'px'
601 ],
602 'condition' => [
603 'layout' => ''
604 ],
605 'selectors' => [
606 '{{WRAPPER}}' => '--ui-e-image-spacing: {{SIZE}}{{UNIT}};',
607 ],
608 ]
609 );
610 $this->add_control(
611 'image_radius',
612 [
613 'label' => esc_html__( 'Border Radius', 'uicore-elements' ),
614 'type' => Controls_Manager::DIMENSIONS,
615 'size_units' => [ 'px', '%' ],
616 'condition' => [
617 'layout' => ''
618 ],
619 'selectors' => [
620 '{{WRAPPER}} .ui-e-item img' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
621 ],
622 ]
623 );
624 $this->add_group_control(
625 Group_Control_Box_Shadow::get_type(),
626 [
627 'name' => 'image_box_shadow',
628 'selector' => '{{WRAPPER}} .ui-e-item img',
629 'condition' => [
630 'layout' => ''
631 ]
632 ]
633 );
634
635 $this->end_controls_section();
636 }
637 function TRAIT_register_title_style_controls()
638 {
639 $this->start_controls_section(
640 'style_title_section',
641 [
642 'label' => __('Title', 'uicore-elements'),
643 'tab' => Controls_Manager::TAB_STYLE,
644 'condition' => [
645 'hide_title!' => 'yes',
646 ]
647 ]
648 );
649
650 $this->add_group_control(
651 Group_Control_Typography::get_type(),
652 [
653 'name' => 'title_typography',
654 'selector' => '{{WRAPPER}} .ui-e-title',
655 ]
656 );
657 $this->add_control(
658 'title_color',
659 [
660 'label' => __('Color', 'uicore-elements'),
661 'type' => Controls_Manager::COLOR,
662 'selectors' => [
663 '{{WRAPPER}} .ui-e-title' => 'color: {{VALUE}};',
664 ],
665 ]
666 );
667 $this->add_control(
668 'title_hover_color',
669 [
670 'label' => __('Hover Color', 'uicore-elements'),
671 'type' => Controls_Manager::COLOR,
672 'selectors' => [
673 '{{WRAPPER}} .ui-e-item:hover .ui-e-title' => 'color: {{VALUE}};',
674 ],
675 ]
676 );
677 $this->add_control(
678 'title_bottom_space',
679 [
680 'label' => __('Spacing', 'uicore-elements'),
681 'type' => Controls_Manager::SLIDER,
682 'range' => [
683 'px' => [
684 'min' => 0,
685 'max' => 50,
686 ],
687 ],
688 'default' => [
689 'size' => 10,
690 'unit' => 'px'
691 ],
692 'selectors' => [
693 '{{WRAPPER}}' => '--ui-e-title-spacing: {{SIZE}}{{UNIT}};',
694 ],
695 ]
696 );
697
698 $this->end_controls_section();
699 }
700 function TRAIT_register_description_style_controls()
701 {
702 $this->start_controls_section(
703 'style_description_section',
704 [
705 'label' => __('Description', 'uicore-elements'),
706 'tab' => Controls_Manager::TAB_STYLE,
707 'condition' => [
708 'hide_description!' => 'yes',
709 ]
710 ]
711 );
712
713 $this->add_group_control(
714 Group_Control_Typography::get_type(),
715 [
716 'name' => 'description_typography',
717 'selector' => '{{WRAPPER}} .ui-e-description',
718 ]
719 );
720 $this->add_control(
721 'description_color',
722 [
723 'label' => __('Color', 'uicore-elements'),
724 'type' => Controls_Manager::COLOR,
725 'selectors' => [
726 '{{WRAPPER}} .ui-e-description' => 'color: {{VALUE}};',
727 ],
728 ]
729 );
730 $this->add_control(
731 'description_bottom_space',
732 [
733 'label' => __('Spacing', 'uicore-elements'),
734 'type' => Controls_Manager::SLIDER,
735 'range' => [
736 'px' => [
737 'min' => 0,
738 'max' => 50,
739 ],
740 ],
741 'default' => [
742 'size' => 10,
743 'unit' => 'px'
744 ],
745 'condition' => [
746 'hide_tags!' => 'yes',
747 ],
748 'selectors' => [
749 '{{WRAPPER}} .ui-e-description' => 'padding-bottom: {{SIZE}}{{UNIT}};',
750 ],
751 ]
752 );
753
754 $this->end_controls_section();
755 }
756 function TRAIT_register_tags_style_controls()
757 {
758 $this->start_controls_section(
759 'style_tags_section',
760 [
761 'label' => __('Tags', 'uicore-elements'),
762 'tab' => Controls_Manager::TAB_STYLE,
763 'condition' => [
764 'hide_tags!' => 'yes',
765 ]
766 ]
767 );
768
769 $this->add_group_control(
770 Group_Control_Typography::get_type(),
771 [
772 'name' => 'tags_typography',
773 'selector' => '{{WRAPPER}} .ui-e-tags',
774 ]
775 );
776 $this->add_control(
777 'tags_color',
778 [
779 'label' => __('Color', 'uicore-elements'),
780 'type' => Controls_Manager::COLOR,
781 'selectors' => [
782 '{{WRAPPER}} .ui-e-tags' => 'color: {{VALUE}};',
783 ],
784 ]
785 );
786
787 $this->end_controls_section();
788 }
789 function TRAIT_register_badge_style_controls()
790 {
791 $this->start_controls_section(
792 'style_badge_section',
793 [
794 'label' => __('Badge', 'uicore-elements'),
795 'tab' => Controls_Manager::TAB_STYLE,
796 ]
797 );
798
799 $this->add_group_control(
800 Group_Control_Typography::get_type(),
801 [
802 'name' => 'badge_typography',
803 'selector' => '{{WRAPPER}} .ui-e-badge',
804 ]
805 );
806 $this->add_control(
807 'badge_color',
808 [
809 'label' => __('Color', 'uicore-elements'),
810 'type' => Controls_Manager::COLOR,
811 'selectors' => [
812 '{{WRAPPER}} .ui-e-badge' => 'color: {{VALUE}};',
813 ],
814 ]
815 );
816 $this->add_control(
817 'badge_background_color',
818 [
819 'label' => __('Background Color', 'uicore-elements'),
820 'type' => Controls_Manager::COLOR,
821 'global' => [
822 'default' => Global_Colors::COLOR_PRIMARY,
823 ],
824 'selectors' => [
825 '{{WRAPPER}} .ui-e-badge' => 'background-color: {{VALUE}};',
826 ],
827 ]
828 );
829 $this->add_group_control(
830 Group_Control_Border::get_type(),
831 [
832 'name' => 'badge_border',
833 'label' => esc_html__( 'Border', 'uicore-elements' ),
834 'selector' => '{{WRAPPER}} .ui-e-badge',
835 ]
836 );
837 $this->add_control(
838 'badge_border_radius',
839 [
840 'label' => esc_html__( 'Border Radius', 'uicore-elements' ),
841 'type' => Controls_Manager::DIMENSIONS,
842 'size_units' => [ 'px', '%' ],
843 'default' => [
844 'top' => 4,
845 'right' => 4,
846 'bottom' => 4,
847 'left' => 4,
848 ],
849 'selectors' => [
850 '{{WRAPPER}} .ui-e-badge' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
851 ],
852 ]
853 );
854 $this->add_control(
855 'badge_padding',
856 [
857 'label' => esc_html__( 'Padding', 'uicore-elements' ),
858 'type' => Controls_Manager::DIMENSIONS,
859 'size_units' => [ 'px', 'em', '%' ],
860 'size_units' => [ 'px', '%' ],
861 'default' => [
862 'top' => 3,
863 'right' => 10,
864 'bottom' => 3,
865 'left' => 10,
866 'unit' => 'px',
867 'isLinked' => false,
868 ],
869 'selectors' => [
870 '{{WRAPPER}} .ui-e-badge' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
871 ],
872 ]
873 );
874 $this->add_group_control(
875 Group_Control_Box_Shadow::get_type(),
876 [
877 'name' => 'badge_box_shadow',
878 'selector' => '{{WRAPPER}} .ui-e-badge',
879 ]
880 );
881
882 $this->end_controls_section();
883 }
884 function TRAIT_register_gallery_animations()
885 {
886 $this->start_controls_section(
887 'items_animation',
888 [
889 'label' => esc_html__('Animation', 'uicore-elements'),
890 'tab' => Controls_Manager::TAB_STYLE,
891 ]
892 );
893 $this->TRAIT_register_entrance_animations_controls(); // animate each item
894 $this->TRAIT_register_hover_animation_control(
895 'Item Hover Animation',
896 [],
897 ['underline']
898 );
899 $this->TRAIT_register_hover_animation_control(
900 'Image Animation',
901 ['layout' => ''],
902 ['underline']
903 );
904 // TODO: update all controls below after 'show' is globally implemented
905 $this->TRAIT_register_hover_animation_control(
906 'Title Animation',
907 ['hide_title!' => 'yes'],
908 ['zoom'],
909 null,
910 true,
911 'ui-e-animated-title-'
912 );
913 $this->TRAIT_register_hover_animation_control(
914 'Description Animation',
915 ['hide_description!' => 'yes'],
916 ['zoom', 'underline'],
917 null,
918 true,
919 'ui-e-animated-description-'
920 );
921 $this->TRAIT_register_hover_animation_control(
922 'Badge Animation',
923 [],
924 ['underline'],
925 null,
926 true
927 );
928 $this->TRAIT_register_hover_animation_control(
929 'Tags Animation',
930 ['hide_tags!' => 'yes'],
931 ['zoom'],
932 null,
933 true
934 );
935
936 $this->end_controls_section();
937 }
938
939 // Elements rendering
940 protected function TRAIT_render_gallery($settings, $is_carousel = false)
941 {
942 // Get entrance and item hover animation classes
943 $entrance = $this->is_option('animate_items', 'ui-e-grid-animate') ? 'elementor-invisible' : '';
944 $hover = isset($settings['item_hover_animation']) ? $settings['item_hover_animation'] : null;
945 $animations = sprintf('%s %s', $entrance, $hover);
946
947 // Get all elements animation control options (triggered by .ui-e-animations-wrp:hover)
948 $animation_options = [
949 $settings['title_animation'],
950 $settings['description_animation'],
951 $settings['image_animation'],
952 $settings['badge_animation'],
953 $settings['tags_animation'],
954 ];
955
956 // get item animation only if is not slider,
957 if (!str_contains($this->get_name(), 'slider')) {
958 $animation_options[] = $settings['item_hover_animation'];
959 }
960
961 // check if any of the animation are set
962 $has_animation = array_filter($animation_options, function($value) {
963 return $value !== '';
964 });
965
966 // and also check if entrance is set
967 $has_animation = $entrance !== '' ? true : $has_animation;
968
969 //
970 $item_classes = $is_carousel
971 ? 'ui-e-wrp swiper-slide'
972 : 'ui-e-wrp ui-e-filtered';
973 $this->add_render_attribute('item_wrapper', 'class', $item_classes );
974
975 // Render items
976 foreach ( $settings['gallery_items'] as $index => $item ) {
977 $this->render_item($index, $item, $settings, $has_animation, $animations);
978 }
979
980 if($is_carousel) {
981 $total_slides = count($settings['gallery_items']);
982
983 // Most recent swiper versions requires, if loop, at least one extra slide compared to visible slides
984 if( $this->TRAIT_should_duplicate_slides($total_slides)) {
985 $diff = $this->TRAIT_get_duplication_diff($total_slides);
986 for($i = 0; $i <= $diff; $i++){
987 $this->render_item($index, $item, $settings, $has_animation, $animations);
988 }
989 }
990 }
991 }
992
993 protected function render_item($index, $item, $settings, $has_animation, $animations)
994 {
995 // Params
996 $key = 'item_'.$index;
997 $tag = 'div ';
998
999 $this->add_render_attribute($key, 'class', 'ui-e-item' );
1000
1001 // Build URL
1002 if ( !empty($item['item_url']['url']) ) {
1003 $tag = 'a ';
1004 $this->add_link_attributes($key, $item['item_url'] );
1005 }
1006
1007 ?>
1008 <div <?php $this->print_render_attribute_string('item_wrapper'); ?> data-ui-e-tags="<?php echo esc_attr( sanitize_title( $item['item_tags'] )); ?>">
1009
1010 <?php if($has_animation) : ?>
1011 <div class='ui-e-animations-wrp <?php echo esc_attr($animations);?>'>
1012 <?php endif; ?>
1013
1014 <<?php echo esc_html($tag);?> <?php $this->print_render_attribute_string($key); ?>>
1015 <?php $this->render_image($index, $item, $settings); ?>
1016 <?php $this->render_contents($item, $settings); ?>
1017 </<?php echo esc_html($tag);?>>
1018
1019 <?php if($has_animation) : ?>
1020 </div>
1021 <?php endif; ?>
1022
1023 </div>
1024 <?php
1025 }
1026
1027 protected function render_contents($instance, $settings){
1028
1029 // Content container should only be rendered if at least one of the content elements is available
1030 if(
1031 ( empty( $instance['item_title'] ) || $this->is_option('hide_title', 'yes') ) &
1032 ( empty( $instance['item_description'] ) || $this->is_option('hide_description', 'yes')) &
1033 ( empty( $instance['item_tags'] ) || $this->is_option('hide_tags', 'yes'))
1034 ){
1035 return;
1036 }
1037
1038 ?>
1039 <div class="ui-e-content">
1040 <?php $this->render_title($instance, $settings); ?>
1041 <?php $this->render_description($instance, $settings['description_animation']) ?>
1042 <?php $this->render_tags($instance, $settings); ?>
1043 </div>
1044 <?php
1045 }
1046 protected function render_image($index, $instance, $settings){
1047
1048 if( empty($instance['item_image']['url']) ){
1049 return;
1050 }
1051
1052
1053 // Only default layout has media wrapper
1054 if( $this->is_option('layout', '') ){
1055 ?> <div class="ui-e-media-wrp <?php echo esc_attr($settings['image_animation']);?>"> <?php
1056 }
1057
1058 $this->add_render_attribute(
1059 'image',
1060 [
1061 'src' => $instance['item_image']['url'],
1062 'alt' => Control_Media::get_image_alt( $instance['item_image'] ),
1063 'title' => Control_Media::get_image_title( $instance['item_image'] ),
1064 'class' => 'ui-e-img',
1065 ]
1066 );
1067
1068 if( ! empty($settings['badge_position']) ) {
1069 $this->render_badge($instance, $settings['badge_animation']);
1070 }
1071
1072 echo wp_kses_post( Group_Control_Image_Size::get_attachment_image_html( $instance, 'item_image', ));
1073
1074 if( $this->is_option('layout', '') ){
1075 ?> </div> <?php
1076 }
1077
1078 }
1079 protected function render_title($instance, $settings)
1080 {
1081 if( empty( $instance['item_title'] ) || $this->is_option('hide_title', 'yes') ){
1082 return;
1083 }
1084
1085 ?>
1086 <div class="ui-e-title-wrapper">
1087 <<?php echo esc_html($settings['title_tag']);?> class="ui-e-title <?php echo esc_attr($settings['title_animation'])?>">
1088 <span> <?php echo Helper::esc_string( $instance['item_title'] ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> </span>
1089 </<?php echo esc_html($settings['title_tag']);?>>
1090
1091 <?php
1092 if( empty($settings['badge_position']) ) {
1093 $this->render_badge($instance, $settings['badge_animation']);
1094 }
1095 ?>
1096 </div>
1097 <?php
1098 }
1099 protected function render_description($instance, $animation)
1100 {
1101 if( empty( $instance['item_description'] ) || $this->is_option('hide_description', 'yes') ){
1102 return;
1103 }
1104
1105 ?>
1106 <p class="ui-e-description <?php echo esc_attr($animation);?>">
1107 <?php echo Helper::esc_string( $instance['item_description'] ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
1108 </p>
1109 <?php
1110 }
1111 protected function render_badge($instance, $animation)
1112 {
1113 if( empty( $instance['item_badge']) ){
1114 return;
1115 }
1116
1117 ?>
1118 <span class="ui-e-badge <?php echo esc_attr($animation) ;?>">
1119 <?php echo esc_html( $instance['item_badge'] ); ?>
1120 </span>
1121 <?php
1122 }
1123 protected function render_tags($instance, $settings)
1124 {
1125 if( empty( $instance['item_tags'] ) || $this->is_option('hide_tags', 'yes') ){
1126 return;
1127 }
1128
1129 $tags = explode(',', $instance['item_tags']);
1130
1131 ?>
1132 <div class="ui-e-tags <?php echo esc_attr($settings['tags_animation']);?>">
1133 <?php foreach($tags as $tag) : ?>
1134 <span class="ui-e-tag">
1135 <?php
1136 echo esc_html($tag);
1137 echo end($tags) !== $tag ? ', ': ''; // print separator if is not last item
1138 ?>
1139 </span>
1140 <?php endforeach; ?>
1141 </div>
1142 <?php
1143 }
1144 protected function TRAIT_render_gallery_filters($settings)
1145 {
1146 if( $this->is_option('filters', 'yes', '!==') ){
1147 return;
1148 }
1149
1150 $filters = [];
1151
1152 foreach( $settings['gallery_items'] as $item ) {
1153
1154 // tags are comma separated strings
1155 $tags = explode(',', $item['item_tags']);
1156 $tags = array_map('trim', $tags);
1157
1158 foreach ( $tags as $tag ) {
1159 // skip duplicates or empty tags
1160 if( in_array($tag, $filters) || empty($tag) ){
1161 continue;
1162 }
1163
1164 $filters[] = $tag;
1165 }
1166 }
1167
1168 ?>
1169 <div class="ui-e-filters">
1170
1171 <button class="ui-e-filter-item" data-filter="all">
1172 <?php echo esc_html( $settings['clear_text'] ); ?>
1173 </button>
1174
1175 <?php foreach($filters as $filter) : ?>
1176 <button class="ui-e-filter-item" data-filter="<?php echo esc_attr( sanitize_title($filter)); ?>">
1177 <?php echo esc_html($filter); ?>
1178 </button>
1179 <?php endforeach; ?>
1180
1181 </div>
1182 <?php
1183 }
1184 }