PluginProbe
Elementor Website Builder – more than just a page builder / 3.29.1
Elementor Website Builder – more than just a page builder v3.29.1
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / includes / widgets / image-carousel.php

image-carousel.php in Elementor Website Builder – more than just a page builder 3.29.1, at includes/widgets/image-carousel.php

1,131 lines 27.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit; // Exit if accessed directly.
6 }
7
8 use Elementor\Core\Kits\Documents\Tabs\Global_Colors;
9 use Elementor\Modules\Promotions\Controls\Promotion_Control;
10
11 /**
12 * Elementor image carousel widget.
13 *
14 * Elementor widget that displays a set of images in a rotating carousel or
15 * slider.
16 *
17 * @since 1.0.0
18 */
19 class Widget_Image_Carousel extends Widget_Base {
20
21 /**
22 * Get widget name.
23 *
24 * Retrieve image carousel widget name.
25 *
26 * @since 1.0.0
27 * @access public
28 *
29 * @return string Widget name.
30 */
31 public function get_name() {
32 return 'image-carousel';
33 }
34
35 /**
36 * Get widget title.
37 *
38 * Retrieve image carousel widget title.
39 *
40 * @since 1.0.0
41 * @access public
42 *
43 * @return string Widget title.
44 */
45 public function get_title() {
46 return esc_html__( 'Image Carousel', 'elementor' );
47 }
48
49 /**
50 * Get widget icon.
51 *
52 * Retrieve image carousel widget icon.
53 *
54 * @since 1.0.0
55 * @access public
56 *
57 * @return string Widget icon.
58 */
59 public function get_icon() {
60 return 'eicon-slider-push';
61 }
62
63 /**
64 * Get widget keywords.
65 *
66 * Retrieve the list of keywords the widget belongs to.
67 *
68 * @since 2.1.0
69 * @access public
70 *
71 * @return array Widget keywords.
72 */
73 public function get_keywords() {
74 return [ 'image', 'photo', 'visual', 'carousel', 'slider' ];
75 }
76
77 protected function is_dynamic_content(): bool {
78 return false;
79 }
80
81 /**
82 * Get style dependencies.
83 *
84 * Retrieve the list of style dependencies the widget requires.
85 *
86 * @since 3.24.0
87 * @access public
88 *
89 * @return array Widget style dependencies.
90 */
91 public function get_style_depends(): array {
92 return [ 'e-swiper', 'widget-image-carousel' ];
93 }
94
95 /**
96 * Get script dependencies.
97 *
98 * Retrieve the list of script dependencies the widget requires.
99 *
100 * @since 3.27.0
101 * @access public
102 *
103 * @return array Widget script dependencies.
104 */
105 public function get_script_depends(): array {
106 return [ 'swiper' ];
107 }
108
109 public function has_widget_inner_wrapper(): bool {
110 return ! Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' );
111 }
112
113 /**
114 * Register image carousel widget controls.
115 *
116 * Adds different input fields to allow the user to change and customize the widget settings.
117 *
118 * @since 3.1.0
119 * @access protected
120 */
121 protected function register_controls() {
122 $this->start_controls_section(
123 'section_image_carousel',
124 [
125 'label' => esc_html__( 'Image Carousel', 'elementor' ),
126 ]
127 );
128
129 $this->add_control(
130 'carousel_name',
131 [
132 'label' => esc_html__( 'Carousel Name', 'elementor' ),
133 'type' => Controls_Manager::TEXT,
134 'default' => esc_html__( 'Image Carousel', 'elementor' ),
135 ]
136 );
137
138 $this->add_control(
139 'carousel',
140 [
141 'label' => esc_html__( 'Add Images', 'elementor' ),
142 'type' => Controls_Manager::GALLERY,
143 'default' => [],
144 'show_label' => false,
145 'dynamic' => [
146 'active' => true,
147 ],
148 ]
149 );
150
151 $this->add_group_control(
152 Group_Control_Image_Size::get_type(),
153 [
154 'name' => 'thumbnail', // Usage: `{name}_size` and `{name}_custom_dimension`, in this case `thumbnail_size` and `thumbnail_custom_dimension`.
155 ]
156 );
157
158 $slides_to_show = range( 1, 10 );
159 $slides_to_show = array_combine( $slides_to_show, $slides_to_show );
160
161 $this->add_responsive_control(
162 'slides_to_show',
163 [
164 'label' => esc_html__( 'Slides to Show', 'elementor' ),
165 'type' => Controls_Manager::SELECT,
166 'options' => [
167 '' => esc_html__( 'Default', 'elementor' ),
168 ] + $slides_to_show,
169 'frontend_available' => true,
170 'render_type' => 'template',
171 'selectors' => [
172 '{{WRAPPER}}' => '--e-image-carousel-slides-to-show: {{VALUE}}',
173 ],
174 'content_classes' => 'elementor-control-field-select-small',
175 ]
176 );
177
178 $this->add_responsive_control(
179 'slides_to_scroll',
180 [
181 'label' => esc_html__( 'Slides to Scroll', 'elementor' ),
182 'type' => Controls_Manager::SELECT,
183 'description' => esc_html__( 'Set how many slides are scrolled per swipe.', 'elementor' ),
184 'options' => [
185 '' => esc_html__( 'Default', 'elementor' ),
186 ] + $slides_to_show,
187 'condition' => [
188 'slides_to_show!' => '1',
189 ],
190 'frontend_available' => true,
191 'content_classes' => 'elementor-control-field-select-small',
192 ]
193 );
194
195 $this->add_control(
196 'image_stretch',
197 [
198 'label' => esc_html__( 'Image Stretch', 'elementor' ),
199 'type' => Controls_Manager::SELECT,
200 'default' => 'no',
201 'options' => [
202 'no' => esc_html__( 'No', 'elementor' ),
203 'yes' => esc_html__( 'Yes', 'elementor' ),
204 ],
205 ]
206 );
207
208 $this->add_control(
209 'navigation',
210 [
211 'label' => esc_html__( 'Navigation', 'elementor' ),
212 'type' => Controls_Manager::SELECT,
213 'default' => 'both',
214 'options' => [
215 'both' => esc_html__( 'Arrows and Dots', 'elementor' ),
216 'arrows' => esc_html__( 'Arrows', 'elementor' ),
217 'dots' => esc_html__( 'Dots', 'elementor' ),
218 'none' => esc_html__( 'None', 'elementor' ),
219 ],
220 'frontend_available' => true,
221 ]
222 );
223
224 $this->add_control(
225 'navigation_previous_icon',
226 [
227 'label' => esc_html__( 'Previous Arrow Icon', 'elementor' ),
228 'type' => Controls_Manager::ICONS,
229 'fa4compatibility' => 'icon',
230 'skin' => 'inline',
231 'label_block' => false,
232 'skin_settings' => [
233 'inline' => [
234 'none' => [
235 'label' => 'Default',
236 'icon' => 'eicon-chevron-left',
237 ],
238 'icon' => [
239 'icon' => 'eicon-star',
240 ],
241 ],
242 ],
243 'recommended' => [
244 'fa-regular' => [
245 'arrow-alt-circle-left',
246 'caret-square-left',
247 ],
248 'fa-solid' => [
249 'angle-double-left',
250 'angle-left',
251 'arrow-alt-circle-left',
252 'arrow-circle-left',
253 'arrow-left',
254 'caret-left',
255 'caret-square-left',
256 'chevron-circle-left',
257 'chevron-left',
258 'long-arrow-alt-left',
259 ],
260 ],
261 'conditions' => [
262 'relation' => 'or',
263 'terms' => [
264 [
265 'name' => 'navigation',
266 'operator' => '=',
267 'value' => 'both',
268 ],
269 [
270 'name' => 'navigation',
271 'operator' => '=',
272 'value' => 'arrows',
273 ],
274 ],
275 ],
276 ]
277 );
278
279 $this->add_control(
280 'navigation_next_icon',
281 [
282 'label' => esc_html__( 'Next Arrow Icon', 'elementor' ),
283 'type' => Controls_Manager::ICONS,
284 'fa4compatibility' => 'icon',
285 'skin' => 'inline',
286 'label_block' => false,
287 'skin_settings' => [
288 'inline' => [
289 'none' => [
290 'label' => 'Default',
291 'icon' => 'eicon-chevron-right',
292 ],
293 'icon' => [
294 'icon' => 'eicon-star',
295 ],
296 ],
297 ],
298 'recommended' => [
299 'fa-regular' => [
300 'arrow-alt-circle-right',
301 'caret-square-right',
302 ],
303 'fa-solid' => [
304 'angle-double-right',
305 'angle-right',
306 'arrow-alt-circle-right',
307 'arrow-circle-right',
308 'arrow-right',
309 'caret-right',
310 'caret-square-right',
311 'chevron-circle-right',
312 'chevron-right',
313 'long-arrow-alt-right',
314 ],
315 ],
316 'conditions' => [
317 'relation' => 'or',
318 'terms' => [
319 [
320 'name' => 'navigation',
321 'operator' => '=',
322 'value' => 'both',
323 ],
324 [
325 'name' => 'navigation',
326 'operator' => '=',
327 'value' => 'arrows',
328 ],
329 ],
330 ],
331 ]
332 );
333
334 $this->add_control(
335 'link_to',
336 [
337 'label' => esc_html__( 'Link', 'elementor' ),
338 'type' => Controls_Manager::SELECT,
339 'default' => 'none',
340 'options' => [
341 'none' => esc_html__( 'None', 'elementor' ),
342 'file' => esc_html__( 'Media File', 'elementor' ),
343 'custom' => esc_html__( 'Custom URL', 'elementor' ),
344 ],
345 ]
346 );
347
348 $this->add_control(
349 'link',
350 [
351 'label' => esc_html__( 'Link', 'elementor' ),
352 'type' => Controls_Manager::URL,
353 'condition' => [
354 'link_to' => 'custom',
355 ],
356 'show_label' => false,
357 'dynamic' => [
358 'active' => true,
359 ],
360 ]
361 );
362
363 $this->add_control(
364 'open_lightbox',
365 [
366 'label' => esc_html__( 'Lightbox', 'elementor' ),
367 'type' => Controls_Manager::SELECT,
368 'description' => sprintf(
369 /* translators: 1: Link open tag, 2: Link close tag. */
370 esc_html__( 'Manage your site’s lightbox settings in the %1$sLightbox panel%2$s.', 'elementor' ),
371 '<a href="javascript: $e.run( \'panel/global/open\' ).then( () => $e.route( \'panel/global/settings-lightbox\' ) )">',
372 '</a>'
373 ),
374 'default' => 'default',
375 'options' => [
376 'default' => esc_html__( 'Default', 'elementor' ),
377 'yes' => esc_html__( 'Yes', 'elementor' ),
378 'no' => esc_html__( 'No', 'elementor' ),
379 ],
380 'condition' => [
381 'link_to' => 'file',
382 ],
383 ]
384 );
385
386 $this->add_control(
387 'caption_type',
388 [
389 'label' => esc_html__( 'Caption', 'elementor' ),
390 'type' => Controls_Manager::SELECT,
391 'default' => '',
392 'options' => [
393 '' => esc_html__( 'None', 'elementor' ),
394 'title' => esc_html__( 'Title', 'elementor' ),
395 'caption' => esc_html__( 'Caption', 'elementor' ),
396 'description' => esc_html__( 'Description', 'elementor' ),
397 ],
398 ]
399 );
400
401 if ( ! Utils::has_pro() ) {
402 $this->add_control(
403 Utils::IMAGE_CAROUSEL . '_promotion',
404 [
405 'label' => esc_html__( 'Carousel PRO widget', 'elementor' ),
406 'type' => Promotion_Control::TYPE,
407 ]
408 );
409 }
410
411 $this->end_controls_section();
412
413 $this->start_controls_section(
414 'section_additional_options',
415 [
416 'label' => esc_html__( 'Additional Options', 'elementor' ),
417 ]
418 );
419
420 $this->add_control(
421 'lazyload',
422 [
423 'label' => esc_html__( 'Lazyload', 'elementor' ),
424 'type' => Controls_Manager::SWITCHER,
425 'frontend_available' => true,
426 ]
427 );
428
429 $this->add_control(
430 'autoplay',
431 [
432 'label' => esc_html__( 'Autoplay', 'elementor' ),
433 'type' => Controls_Manager::SWITCHER,
434 'label_on' => esc_html__( 'Yes', 'elementor' ),
435 'label_off' => esc_html__( 'No', 'elementor' ),
436 'return_value' => 'yes',
437 'default' => 'yes',
438 'frontend_available' => true,
439 ]
440 );
441
442 $this->add_control(
443 'pause_on_hover',
444 [
445 'label' => esc_html__( 'Pause on Hover', 'elementor' ),
446 'type' => Controls_Manager::SWITCHER,
447 'label_on' => esc_html__( 'Yes', 'elementor' ),
448 'label_off' => esc_html__( 'No', 'elementor' ),
449 'return_value' => 'yes',
450 'default' => 'yes',
451 'condition' => [
452 'autoplay' => 'yes',
453 ],
454 'render_type' => 'none',
455 'frontend_available' => true,
456 ]
457 );
458
459 $this->add_control(
460 'pause_on_interaction',
461 [
462 'label' => esc_html__( 'Pause on Interaction', 'elementor' ),
463 'type' => Controls_Manager::SWITCHER,
464 'label_on' => esc_html__( 'Yes', 'elementor' ),
465 'label_off' => esc_html__( 'No', 'elementor' ),
466 'return_value' => 'yes',
467 'default' => 'yes',
468 'condition' => [
469 'autoplay' => 'yes',
470 ],
471 'frontend_available' => true,
472 ]
473 );
474
475 $this->add_control(
476 'autoplay_speed',
477 [
478 'label' => esc_html__( 'Autoplay Speed', 'elementor' ),
479 'type' => Controls_Manager::NUMBER,
480 'default' => 5000,
481 'condition' => [
482 'autoplay' => 'yes',
483 ],
484 'render_type' => 'none',
485 'frontend_available' => true,
486 ]
487 );
488
489 // Loop requires a re-render so no 'render_type = none'
490 $this->add_control(
491 'infinite',
492 [
493 'label' => esc_html__( 'Infinite Loop', 'elementor' ),
494 'type' => Controls_Manager::SWITCHER,
495 'label_on' => esc_html__( 'Yes', 'elementor' ),
496 'label_off' => esc_html__( 'No', 'elementor' ),
497 'return_value' => 'yes',
498 'default' => 'yes',
499 'frontend_available' => true,
500 ]
501 );
502
503 $this->add_control(
504 'effect',
505 [
506 'label' => esc_html__( 'Effect', 'elementor' ),
507 'type' => Controls_Manager::SELECT,
508 'default' => 'slide',
509 'options' => [
510 'slide' => esc_html__( 'Slide', 'elementor' ),
511 'fade' => esc_html__( 'Fade', 'elementor' ),
512 ],
513 'condition' => [
514 'slides_to_show' => '1',
515 ],
516 'frontend_available' => true,
517 ]
518 );
519
520 $this->add_control(
521 'speed',
522 [
523 'label' => esc_html__( 'Animation Speed', 'elementor' ),
524 'type' => Controls_Manager::NUMBER,
525 'default' => 500,
526 'render_type' => 'none',
527 'frontend_available' => true,
528 ]
529 );
530
531 $this->add_control(
532 'direction',
533 [
534 'label' => esc_html__( 'Direction', 'elementor' ),
535 'type' => Controls_Manager::SELECT,
536 'default' => 'ltr',
537 'options' => [
538 'ltr' => esc_html__( 'Left', 'elementor' ),
539 'rtl' => esc_html__( 'Right', 'elementor' ),
540 ],
541 ]
542 );
543
544 $this->end_controls_section();
545
546 $this->start_controls_section(
547 'section_style_navigation',
548 [
549 'label' => esc_html__( 'Navigation', 'elementor' ),
550 'tab' => Controls_Manager::TAB_STYLE,
551 'condition' => [
552 'navigation' => [ 'arrows', 'dots', 'both' ],
553 ],
554 ]
555 );
556
557 $this->add_control(
558 'heading_style_arrows',
559 [
560 'label' => esc_html__( 'Arrows', 'elementor' ),
561 'type' => Controls_Manager::HEADING,
562 'separator' => 'before',
563 'condition' => [
564 'navigation' => [ 'arrows', 'both' ],
565 ],
566 ]
567 );
568
569 $this->add_control(
570 'arrows_position',
571 [
572 'label' => esc_html__( 'Position', 'elementor' ),
573 'type' => Controls_Manager::SELECT,
574 'default' => 'inside',
575 'options' => [
576 'inside' => esc_html__( 'Inside', 'elementor' ),
577 'outside' => esc_html__( 'Outside', 'elementor' ),
578 ],
579 'prefix_class' => 'elementor-arrows-position-',
580 'condition' => [
581 'navigation' => [ 'arrows', 'both' ],
582 ],
583 ]
584 );
585
586 $this->add_responsive_control(
587 'arrows_size',
588 [
589 'label' => esc_html__( 'Size', 'elementor' ),
590 'type' => Controls_Manager::SLIDER,
591 'size_units' => [ 'px', 'em', 'rem', 'custom' ],
592 'range' => [
593 'px' => [
594 'max' => 100,
595 ],
596 ],
597 'selectors' => [
598 '{{WRAPPER}} .elementor-swiper-button.elementor-swiper-button-prev, {{WRAPPER}} .elementor-swiper-button.elementor-swiper-button-next' => 'font-size: {{SIZE}}{{UNIT}};',
599 ],
600 'condition' => [
601 'navigation' => [ 'arrows', 'both' ],
602 ],
603 ]
604 );
605
606 $this->add_control(
607 'arrows_color',
608 [
609 'label' => esc_html__( 'Color', 'elementor' ),
610 'type' => Controls_Manager::COLOR,
611 'selectors' => [
612 '{{WRAPPER}} .elementor-swiper-button.elementor-swiper-button-prev, {{WRAPPER}} .elementor-swiper-button.elementor-swiper-button-next' => 'color: {{VALUE}};',
613 '{{WRAPPER}} .elementor-swiper-button.elementor-swiper-button-prev svg, {{WRAPPER}} .elementor-swiper-button.elementor-swiper-button-next svg' => 'fill: {{VALUE}};',
614 ],
615 'condition' => [
616 'navigation' => [ 'arrows', 'both' ],
617 ],
618 ]
619 );
620
621 $this->add_control(
622 'heading_style_dots',
623 [
624 'label' => esc_html__( 'Pagination', 'elementor' ),
625 'type' => Controls_Manager::HEADING,
626 'separator' => 'before',
627 'condition' => [
628 'navigation' => [ 'dots', 'both' ],
629 ],
630 ]
631 );
632
633 $this->add_control(
634 'dots_position',
635 [
636 'label' => esc_html__( 'Position', 'elementor' ),
637 'type' => Controls_Manager::SELECT,
638 'default' => 'outside',
639 'options' => [
640 'outside' => esc_html__( 'Outside', 'elementor' ),
641 'inside' => esc_html__( 'Inside', 'elementor' ),
642 ],
643 'prefix_class' => 'elementor-pagination-position-',
644 'condition' => [
645 'navigation' => [ 'dots', 'both' ],
646 ],
647 ]
648 );
649
650 $this->add_responsive_control(
651 'dots_gap',
652 [
653 'label' => esc_html__( 'Space Between Dots', 'elementor' ),
654 'type' => Controls_Manager::SLIDER,
655 'size_units' => [ 'px', 'em', 'rem', 'custom' ],
656 'range' => [
657 'px' => [
658 'max' => 20,
659 ],
660 ],
661 'selectors' => [
662 '{{WRAPPER}} .swiper-pagination-bullet' => '--swiper-pagination-bullet-horizontal-gap: {{SIZE}}{{UNIT}}; --swiper-pagination-bullet-vertical-gap: {{SIZE}}{{UNIT}};',
663 ],
664 'condition' => [
665 'navigation' => [ 'dots', 'both' ],
666 ],
667 ]
668 );
669
670 $this->add_responsive_control(
671 'dots_size',
672 [
673 'label' => esc_html__( 'Size', 'elementor' ),
674 'type' => Controls_Manager::SLIDER,
675 'size_units' => [ 'px', 'em', 'rem', 'custom' ],
676 'range' => [
677 'px' => [
678 'max' => 20,
679 ],
680 ],
681 'selectors' => [
682 '{{WRAPPER}} .swiper-pagination-bullet' => 'width: {{SIZE}}{{UNIT}}; height: {{SIZE}}{{UNIT}};',
683 ],
684 'condition' => [
685 'navigation' => [ 'dots', 'both' ],
686 ],
687 ]
688 );
689
690 $this->add_control(
691 'dots_inactive_color',
692 [
693 'label' => esc_html__( 'Color', 'elementor' ),
694 'type' => Controls_Manager::COLOR,
695 'selectors' => [
696 // The opacity property will override the default inactive dot color which is opacity 0.2.
697 '{{WRAPPER}} .swiper-pagination-bullet:not(.swiper-pagination-bullet-active)' => 'background: {{VALUE}}; opacity: 1',
698 ],
699 'condition' => [
700 'navigation' => [ 'dots', 'both' ],
701 ],
702 ]
703 );
704
705 $this->add_control(
706 'dots_color',
707 [
708 'label' => esc_html__( 'Active Color', 'elementor' ),
709 'type' => Controls_Manager::COLOR,
710 'selectors' => [
711 '{{WRAPPER}} .swiper-pagination-bullet' => 'background: {{VALUE}};',
712 ],
713 'condition' => [
714 'navigation' => [ 'dots', 'both' ],
715 ],
716 ]
717 );
718
719 $this->end_controls_section();
720
721 $this->start_controls_section(
722 'section_style_image',
723 [
724 'label' => esc_html__( 'Image', 'elementor' ),
725 'tab' => Controls_Manager::TAB_STYLE,
726 ]
727 );
728
729 $this->add_responsive_control(
730 'gallery_vertical_align',
731 [
732 'label' => esc_html__( 'Vertical Align', 'elementor' ),
733 'type' => Controls_Manager::CHOOSE,
734 'options' => [
735 'flex-start' => [
736 'title' => esc_html__( 'Start', 'elementor' ),
737 'icon' => 'eicon-v-align-top',
738 ],
739 'center' => [
740 'title' => esc_html__( 'Center', 'elementor' ),
741 'icon' => 'eicon-v-align-middle',
742 ],
743 'flex-end' => [
744 'title' => esc_html__( 'End', 'elementor' ),
745 'icon' => 'eicon-v-align-bottom',
746 ],
747 ],
748 'condition' => [
749 'slides_to_show!' => '1',
750 ],
751 'selectors' => [
752 '{{WRAPPER}} .swiper-wrapper' => 'display: flex; align-items: {{VALUE}};',
753 ],
754 ]
755 );
756
757 $this->add_control(
758 'image_spacing',
759 [
760 'label' => esc_html__( 'Spacing', 'elementor' ),
761 'type' => Controls_Manager::SELECT,
762 'options' => [
763 '' => esc_html__( 'Default', 'elementor' ),
764 'custom' => esc_html__( 'Custom', 'elementor' ),
765 ],
766 'default' => '',
767 'condition' => [
768 'slides_to_show!' => '1',
769 ],
770 ]
771 );
772
773 $this->add_responsive_control(
774 'image_spacing_custom',
775 [
776 'label' => esc_html__( 'Image Spacing', 'elementor' ),
777 'type' => Controls_Manager::SLIDER,
778 'size_units' => [ 'px' ],
779 'range' => [
780 'px' => [
781 'max' => 100,
782 ],
783 ],
784 'default' => [
785 'size' => 20,
786 ],
787 'condition' => [
788 'image_spacing' => 'custom',
789 'slides_to_show!' => '1',
790 ],
791 'frontend_available' => true,
792 'render_type' => 'none',
793 'separator' => 'after',
794 ]
795 );
796
797 $this->add_group_control(
798 Group_Control_Border::get_type(),
799 [
800 'name' => 'image_border',
801 'selector' => '{{WRAPPER}} .elementor-image-carousel-wrapper .elementor-image-carousel .swiper-slide-image',
802 ]
803 );
804
805 $this->add_responsive_control(
806 'image_border_radius',
807 [
808 'label' => esc_html__( 'Border Radius', 'elementor' ),
809 'type' => Controls_Manager::DIMENSIONS,
810 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
811 'selectors' => [
812 '{{WRAPPER}} .elementor-image-carousel-wrapper .elementor-image-carousel .swiper-slide-image' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
813 ],
814 ]
815 );
816
817 $this->end_controls_section();
818
819 $this->start_controls_section(
820 'section_caption',
821 [
822 'label' => esc_html__( 'Caption', 'elementor' ),
823 'tab' => Controls_Manager::TAB_STYLE,
824 'condition' => [
825 'caption_type!' => '',
826 ],
827 ]
828 );
829
830 $this->add_responsive_control(
831 'caption_align',
832 [
833 'label' => esc_html__( 'Alignment', 'elementor' ),
834 'type' => Controls_Manager::CHOOSE,
835 'options' => [
836 'left' => [
837 'title' => esc_html__( 'Left', 'elementor' ),
838 'icon' => 'eicon-text-align-left',
839 ],
840 'center' => [
841 'title' => esc_html__( 'Center', 'elementor' ),
842 'icon' => 'eicon-text-align-center',
843 ],
844 'right' => [
845 'title' => esc_html__( 'Right', 'elementor' ),
846 'icon' => 'eicon-text-align-right',
847 ],
848 'justify' => [
849 'title' => esc_html__( 'Justified', 'elementor' ),
850 'icon' => 'eicon-text-align-justify',
851 ],
852 ],
853 'default' => 'center',
854 'selectors' => [
855 '{{WRAPPER}} .elementor-image-carousel-caption' => 'text-align: {{VALUE}};',
856 ],
857 ]
858 );
859
860 $this->add_control(
861 'caption_text_color',
862 [
863 'label' => esc_html__( 'Text Color', 'elementor' ),
864 'type' => Controls_Manager::COLOR,
865 'default' => '',
866 'selectors' => [
867 '{{WRAPPER}} .elementor-image-carousel-caption' => 'color: {{VALUE}};',
868 ],
869 ]
870 );
871
872 $this->add_group_control(
873 Group_Control_Typography::get_type(),
874 [
875 'name' => 'caption_typography',
876 'global' => [
877 'default' => Global_Colors::COLOR_ACCENT,
878 ],
879 'selector' => '{{WRAPPER}} .elementor-image-carousel-caption',
880 ]
881 );
882
883 $this->add_group_control(
884 Group_Control_Text_Shadow::get_type(),
885 [
886 'name' => 'caption_shadow',
887 'selector' => '{{WRAPPER}} .elementor-image-carousel-caption',
888 ]
889 );
890
891 $this->add_responsive_control(
892 'caption_space',
893 [
894 'label' => esc_html__( 'Spacing', 'elementor' ),
895 'type' => Controls_Manager::SLIDER,
896 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
897 'selectors' => [
898 '{{WRAPPER}} .elementor-image-carousel-caption' => 'margin-block-start: {{SIZE}}{{UNIT}};',
899 ],
900 ]
901 );
902
903 $this->end_controls_section();
904 }
905
906 /**
907 * Render image carousel widget output on the frontend.
908 *
909 * Written in PHP and used to generate the final HTML.
910 *
911 * @since 1.0.0
912 * @access protected
913 */
914 protected function render() {
915 $settings = $this->get_settings_for_display();
916
917 $lazyload = 'yes' === $settings['lazyload'];
918
919 if ( empty( $settings['carousel'] ) ) {
920 return;
921 }
922
923 $slides = [];
924
925 foreach ( $settings['carousel'] as $index => $attachment ) {
926 $image_url = Group_Control_Image_Size::get_attachment_image_src( $attachment['id'], 'thumbnail', $settings );
927
928 if ( ! $image_url && isset( $attachment['url'] ) ) {
929 $image_url = $attachment['url'];
930 }
931
932 if ( $lazyload ) {
933 $image_html = '<img class="swiper-slide-image swiper-lazy" data-src="' . esc_attr( $image_url ) . '" alt="' . esc_attr( Control_Media::get_image_alt( $attachment ) ) . '" />';
934 } else {
935 $image_html = '<img class="swiper-slide-image" src="' . esc_attr( $image_url ) . '" alt="' . esc_attr( Control_Media::get_image_alt( $attachment ) ) . '" />';
936 }
937
938 $link_tag = '';
939
940 $link = $this->get_link_url( $attachment, $settings );
941
942 if ( $link ) {
943 $link_key = 'link_' . $index;
944
945 $this->add_lightbox_data_attributes( $link_key, $attachment['id'], $settings['open_lightbox'], $this->get_id() );
946
947 if ( Plugin::$instance->editor->is_edit_mode() ) {
948 $this->add_render_attribute( $link_key, [
949 'class' => 'elementor-clickable',
950 ] );
951 }
952
953 $this->add_link_attributes( $link_key, $link );
954
955 $link_tag = '<a ' . $this->get_render_attribute_string( $link_key ) . '>';
956 }
957
958 $image_caption = $this->get_image_caption( $attachment );
959
960 $slide_count = $index + 1;
961 $slide_setting_key = 'swiper_slide_' . $index;
962
963 $this->add_render_attribute( $slide_setting_key, [
964 'class' => 'swiper-slide',
965 'role' => 'group',
966 'aria-roledescription' => 'slide',
967 'aria-label' => sprintf(
968 /* translators: 1: Slide count, 2: Total slides count. */
969 esc_html__( '%1$s of %2$s', 'elementor' ),
970 $slide_count,
971 count( $settings['carousel'] )
972 ),
973 ] );
974
975 $slide_html = '<div ' . $this->get_render_attribute_string( $slide_setting_key ) . '>' . $link_tag . '<figure class="swiper-slide-inner">' . $image_html;
976
977 if ( $lazyload ) {
978 $slide_html .= '<div class="swiper-lazy-preloader"></div>';
979 }
980
981 if ( ! empty( $image_caption ) ) {
982 $slide_html .= '<figcaption class="elementor-image-carousel-caption">' . wp_kses_post( $image_caption ) . '</figcaption>';
983 }
984
985 $slide_html .= '</figure>';
986
987 if ( $link ) {
988 $slide_html .= '</a>';
989 }
990
991 $slide_html .= '</div>';
992
993 $slides[] = $slide_html;
994
995 }
996
997 if ( empty( $slides ) ) {
998 return;
999 }
1000
1001 $swiper_class = 'swiper';
1002 $has_autoplay_enabled = 'yes' === $this->get_settings_for_display( 'autoplay' );
1003
1004 $this->add_render_attribute( [
1005 'carousel' => [
1006 'class' => 'elementor-image-carousel swiper-wrapper',
1007 'aria-live' => $has_autoplay_enabled ? 'off' : 'polite',
1008 ],
1009 'carousel-wrapper' => [
1010 'class' => 'elementor-image-carousel-wrapper ' . $swiper_class,
1011 'role' => 'region',
1012 'aria-roledescription' => 'carousel',
1013 'aria-label' => $settings['carousel_name'],
1014 'dir' => $settings['direction'],
1015 ],
1016 ] );
1017
1018 $show_dots = ( in_array( $settings['navigation'], [ 'dots', 'both' ] ) );
1019 $show_arrows = ( in_array( $settings['navigation'], [ 'arrows', 'both' ] ) );
1020
1021 if ( 'yes' === $settings['image_stretch'] ) {
1022 $this->add_render_attribute( 'carousel', 'class', 'swiper-image-stretch' );
1023 }
1024
1025 $slides_count = count( $settings['carousel'] );
1026 ?>
1027 <div <?php $this->print_render_attribute_string( 'carousel-wrapper' ); ?>>
1028 <div <?php $this->print_render_attribute_string( 'carousel' ); ?>>
1029 <?php // PHPCS - $slides contains the slides content, all the relevant content is escaped above. ?>
1030 <?php echo implode( '', $slides ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
1031 </div>
1032 <?php if ( 1 < $slides_count ) : ?>
1033 <?php if ( $show_arrows ) : ?>
1034 <div class="elementor-swiper-button elementor-swiper-button-prev" role="button" tabindex="0">
1035 <?php $this->render_swiper_button( 'previous' ); ?>
1036 </div>
1037 <div class="elementor-swiper-button elementor-swiper-button-next" role="button" tabindex="0">
1038 <?php $this->render_swiper_button( 'next' ); ?>
1039 </div>
1040 <?php endif; ?>
1041
1042 <?php if ( $show_dots ) : ?>
1043 <div class="swiper-pagination"></div>
1044 <?php endif; ?>
1045 <?php endif; ?>
1046 </div>
1047 <?php
1048 }
1049
1050 /**
1051 * Retrieve image carousel link URL.
1052 *
1053 * @since 1.0.0
1054 * @access private
1055 *
1056 * @param array $attachment
1057 * @param object $instance
1058 *
1059 * @return array|string|false An array/string containing the attachment URL, or false if no link.
1060 */
1061 private function get_link_url( $attachment, $instance ) {
1062 if ( 'none' === $instance['link_to'] ) {
1063 return false;
1064 }
1065
1066 if ( 'custom' === $instance['link_to'] ) {
1067 if ( empty( $instance['link']['url'] ) ) {
1068 return false;
1069 }
1070
1071 return $instance['link'];
1072 }
1073
1074 return [
1075 'url' => wp_get_attachment_url( $attachment['id'] ),
1076 ];
1077 }
1078
1079 /**
1080 * Retrieve image carousel caption.
1081 *
1082 * @since 1.2.0
1083 * @access private
1084 *
1085 * @param array $attachment
1086 *
1087 * @return string The caption of the image.
1088 */
1089 private function get_image_caption( $attachment ) {
1090 $caption_type = $this->get_settings_for_display( 'caption_type' );
1091
1092 if ( empty( $caption_type ) ) {
1093 return '';
1094 }
1095
1096 $attachment_post = get_post( $attachment['id'] );
1097
1098 if ( Utils::has_invalid_post_permissions( $attachment_post ) ) {
1099 return '';
1100 }
1101
1102 if ( 'caption' === $caption_type ) {
1103 return $attachment_post->post_excerpt;
1104 }
1105
1106 if ( 'title' === $caption_type ) {
1107 return $attachment_post->post_title;
1108 }
1109
1110 if ( empty( $attachment_post->post_content ) ) {
1111 return '';
1112 }
1113
1114 return $attachment_post->post_content;
1115 }
1116
1117 private function render_swiper_button( $type ) {
1118 $direction = 'next' === $type ? 'right' : 'left';
1119 $icon_settings = $this->get_settings_for_display( 'navigation_' . $type . '_icon' );
1120
1121 if ( empty( $icon_settings['value'] ) ) {
1122 $icon_settings = [
1123 'library' => 'eicons',
1124 'value' => 'eicon-chevron-' . $direction,
1125 ];
1126 }
1127
1128 Icons_Manager::render_icon( $icon_settings, [ 'aria-hidden' => 'true' ] );
1129 }
1130 }
1131