start_controls_section( 'section_images', [ 'label' => __( 'Images', 'elementor-extras' ), ] ); $this->add_control( 'wp_gallery', [ 'label' => __( 'Add Images', 'elementor-extras' ), 'type' => Controls_Manager::GALLERY, 'frontend_available' => true, 'dynamic' => [ 'active' => true, ], ] ); $this->add_group_control( Group_Control_Image_Size::get_type(), [ 'name' => 'image', // Actually its `image_size`. 'label' => __( 'Image Size', 'elementor-extras' ), 'default' => 'full', ] ); $this->add_responsive_control( 'align', [ 'label' => __( 'Alignment', 'elementor-extras' ), 'type' => Controls_Manager::CHOOSE, 'options' => [ 'left' => [ 'title' => __( 'Left', 'elementor-extras' ), 'icon' => 'fa fa-align-left', ], 'center' => [ 'title' => __( 'Center', 'elementor-extras' ), 'icon' => 'fa fa-align-center', ], 'right' => [ 'title' => __( 'Right', 'elementor-extras' ), 'icon' => 'fa fa-align-right', ], ], 'selectors' => [ '{{WRAPPER}}' => 'text-align: {{VALUE}};', ], ] ); $this->add_control( 'caption', [ 'label' => __( 'Caption', 'elementor-extras' ), 'type' => Controls_Manager::SWITCHER, 'default' => '', 'label_on' => __( 'Show', 'elementor-extras' ), 'label_off' => __( 'Hide', 'elementor-extras' ), 'return_value' => 'yes', ] ); $this->add_control( 'link_to', [ 'label' => __( 'Link to', 'elementor-extras' ), 'type' => Controls_Manager::SELECT, 'default' => 'none', 'options' => [ 'none' => __( 'None', 'elementor-extras' ), 'file' => __( 'Media File', 'elementor-extras' ), 'custom' => __( 'Custom URL', 'elementor-extras' ), ], ] ); $this->add_control( 'link', [ 'label' => __( 'Link to', 'elementor-extras' ), 'type' => Controls_Manager::URL, 'dynamic' => [ 'active' => true, ], 'placeholder' => __( 'https://your-link.com', 'elementor-extras' ), 'condition' => [ 'link_to' => 'custom', ], 'show_label' => false, ] ); $this->add_control( 'open_lightbox', [ 'label' => __( 'Lightbox', 'elementor-extras' ), 'type' => Controls_Manager::SELECT, 'default' => 'default', 'options' => [ 'default' => __( 'Default', 'elementor-extras' ), 'yes' => __( 'Yes', 'elementor-extras' ), 'no' => __( 'No', 'elementor-extras' ), ], 'condition' => [ 'link_to' => 'file', ], ] ); $this->end_controls_section(); $this->start_controls_section( 'section_style_image', [ 'label' => __( 'Image', 'elementor-extras' ), 'tab' => Controls_Manager::TAB_STYLE, ] ); $this->add_responsive_control( 'width', [ 'label' => __( 'Width', 'elementor-extras' ), 'type' => Controls_Manager::SLIDER, 'default' => [ 'unit' => '%', ], 'tablet_default' => [ 'unit' => '%', ], 'mobile_default' => [ 'unit' => '%', ], 'size_units' => [ '%', 'px', 'vw' ], 'range' => [ '%' => [ 'min' => 1, 'max' => 100, ], 'px' => [ 'min' => 1, 'max' => 1000, ], 'vw' => [ 'min' => 1, 'max' => 100, ], ], 'selectors' => [ '{{WRAPPER}} .ee-random-image__image' => 'width: {{SIZE}}{{UNIT}};', ], ] ); $this->add_responsive_control( 'space', [ 'label' => __( 'Max Width', 'elementor-extras' ) . ' (%)', 'type' => Controls_Manager::SLIDER, 'default' => [ 'unit' => '%', ], 'tablet_default' => [ 'unit' => '%', ], 'mobile_default' => [ 'unit' => '%', ], 'size_units' => [ '%' ], 'range' => [ '%' => [ 'min' => 1, 'max' => 100, ], ], 'selectors' => [ '{{WRAPPER}} .ee-random-image__image' => 'max-width: {{SIZE}}{{UNIT}};', ], ] ); $this->add_control( 'opacity', [ 'label' => __( 'Opacity', 'elementor-extras' ), 'type' => Controls_Manager::SLIDER, 'range' => [ 'px' => [ 'max' => 1, 'min' => 0.10, 'step' => 0.01, ], ], 'selectors' => [ '{{WRAPPER}} .ee-random-image__image' => 'opacity: {{SIZE}};', ], ] ); $this->add_control( 'hover_animation', [ 'label' => __( 'Hover Animation', 'elementor-extras' ), 'type' => Controls_Manager::HOVER_ANIMATION, ] ); $this->add_group_control( Group_Control_Border::get_type(), [ 'name' => 'image_border', 'selector' => '{{WRAPPER}} .ee-random-image__image', 'separator' => 'before', ] ); $this->add_responsive_control( 'image_border_radius', [ 'label' => __( 'Border Radius', 'elementor-extras' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => [ 'px', '%' ], 'selectors' => [ '{{WRAPPER}} .ee-random-image__image' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ], ] ); $this->add_group_control( Group_Control_Box_Shadow::get_type(), [ 'name' => 'image_box_shadow', 'exclude' => [ 'box_shadow_position', ], 'selector' => '{{WRAPPER}} .ee-random-image__image', ] ); $this->end_controls_section(); $this->start_controls_section( 'section_style_caption', [ 'label' => __( 'Caption', 'elementor-extras' ), 'tab' => Controls_Manager::TAB_STYLE, 'condition' => [ 'caption!' => '', ], ] ); $this->add_control( 'caption_align', [ 'label' => __( 'Alignment', 'elementor-extras' ), 'type' => Controls_Manager::CHOOSE, 'options' => [ 'left' => [ 'title' => __( 'Left', 'elementor-extras' ), 'icon' => 'fa fa-align-left', ], 'center' => [ 'title' => __( 'Center', 'elementor-extras' ), 'icon' => 'fa fa-align-center', ], 'right' => [ 'title' => __( 'Right', 'elementor-extras' ), 'icon' => 'fa fa-align-right', ], 'justify' => [ 'title' => __( 'Justified', 'elementor-extras' ), 'icon' => 'fa fa-align-justify', ], ], 'default' => '', 'selectors' => [ '{{WRAPPER}} .widget-image-caption' => 'text-align: {{VALUE}};', ], ] ); $this->add_control( 'text_color', [ 'label' => __( 'Text Color', 'elementor-extras' ), 'type' => Controls_Manager::COLOR, 'default' => '', 'selectors' => [ '{{WRAPPER}} .widget-image-caption' => 'color: {{VALUE}};', ], ] ); $this->add_group_control( Group_Control_Typography::get_type(), [ 'name' => 'caption_typography', 'selector' => '{{WRAPPER}} .widget-image-caption', 'global' => [ 'default' => Global_Typography::TYPOGRAPHY_TEXT, ], ] ); $this->add_responsive_control( 'caption_space', [ 'label' => __( 'Spacing', 'elementor-extras' ), 'type' => Controls_Manager::SLIDER, 'range' => [ 'px' => [ 'min' => 0, 'max' => 100, ], ], 'selectors' => [ '{{WRAPPER}} .widget-image-caption' => 'margin-top: {{SIZE}}{{UNIT}};', ], ] ); $this->end_controls_section(); } /** * Render * * Render widget contents on frontend * * @since 2.0.0 * @return void */ protected function render() { $settings = $this->get_settings_for_display(); if ( ! $settings['wp_gallery'] ) { echo $this->render_placeholder( [ 'body' => __( 'No images selected.', 'elementor-extras' ), ] ); return; } $count = count( $settings['wp_gallery'] ); $index = ( $count > 1 ) ? rand( 0, $count - 1 ) : 0; $id = $settings['wp_gallery'][ $index ]['id']; $has_caption = 'yes' === $settings['caption']; $link = $this->get_link_url( $settings, $index ); $attachment = get_post( $id ); $this->add_render_attribute( [ 'wrapper' => [ 'class' => 'ee-random-image', ], 'figure' => [ 'class' => [ 'wp-caption', 'ee-random-image__figure' ], ], 'image' => [ 'class' => 'elementor-image ee-random-image__image', 'src' => Group_Control_Image_Size::get_attachment_image_src( $id, 'image', $settings ), 'alt' => esc_attr( Control_Media::get_image_alt( $id ) ), ], 'caption' => [ 'class' => [ 'widget-image-caption', 'wp-caption-text', 'ee-random-image__caption', ], ], ] ); if ( '' !== $settings['hover_animation'] ) { $this->add_render_attribute( 'image', 'class', 'elementor-animation-' . $settings['hover_animation'] ); } if ( $link ) { if ( ! empty( $link['url'] ) ) { $this->add_render_attribute( 'link', 'href', $link['url'] ); } if ( ! empty( $link['is_external'] ) ) { $this->add_render_attribute( 'link', 'target', '_blank' ); } if ( ! empty( $link['nofollow'] ) ) { $this->add_render_attribute( 'link', 'rel', 'nofollow' ); } $this->add_lightbox_data_attributes( 'link', $id, $settings['open_lightbox'], $this->get_id_for_loop() ); if ( $this->_is_edit_mode ) { $this->add_render_attribute( 'link', 'class', 'elementor-clickable' ); } } ?>