PluginProbe
Elementor Website Builder – more than just a page builder / 3.14.0-beta4
Elementor Website Builder – more than just a page builder v3.14.0-beta4
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.14.0-beta4, at includes/widgets/image-carousel.php

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