start_controls_section( 'section_image', [ 'label' => __( 'Image', 'elementor' ), ] ); $this->add_control( 'image', [ 'label' => __( 'Choose Image', 'elementor' ), 'type' => Controls_Manager::MEDIA, 'default' => [ 'url' => Utils::get_placeholder_image_src(), ], ] ); $this->add_group_control( Group_Control_Image_Size::get_type(), [ 'name' => 'image', // Actually its `image_size`. 'default' => 'large', ] ); $this->add_responsive_control( 'align', [ 'label' => __( 'Alignment', 'elementor' ), 'type' => Controls_Manager::CHOOSE, 'options' => [ 'left' => [ 'title' => __( 'Left', 'elementor' ), 'icon' => 'fa fa-align-left', ], 'center' => [ 'title' => __( 'Center', 'elementor' ), 'icon' => 'fa fa-align-center', ], 'right' => [ 'title' => __( 'Right', 'elementor' ), 'icon' => 'fa fa-align-right', ], ], 'default' => 'center', 'selectors' => [ '{{WRAPPER}}' => 'text-align: {{VALUE}};', ], ] ); $this->add_control( 'caption', [ 'label' => __( 'Caption', 'elementor' ), 'type' => Controls_Manager::TEXT, 'default' => '', 'placeholder' => __( 'Enter your image caption', 'elementor' ), ] ); $this->add_control( 'link_to', [ 'label' => __( 'Link to', 'elementor' ), 'type' => Controls_Manager::SELECT, 'default' => 'none', 'options' => [ 'none' => __( 'None', 'elementor' ), 'file' => __( 'Media File', 'elementor' ), 'custom' => __( 'Custom URL', 'elementor' ), ], ] ); $this->add_control( 'link', [ 'label' => __( 'Link to', 'elementor' ), 'type' => Controls_Manager::URL, 'placeholder' => __( 'https://your-link.com', 'elementor' ), 'condition' => [ 'link_to' => 'custom', ], 'show_label' => false, ] ); $this->add_control( 'open_lightbox', [ 'label' => __( 'Lightbox', 'elementor' ), 'type' => Controls_Manager::SELECT, 'default' => 'default', 'options' => [ 'default' => __( 'Default', 'elementor' ), 'yes' => __( 'Yes', 'elementor' ), 'no' => __( 'No', 'elementor' ), ], 'condition' => [ 'link_to' => 'file', ], ] ); $this->add_control( 'view', [ 'label' => __( 'View', 'elementor' ), 'type' => Controls_Manager::HIDDEN, 'default' => 'traditional', ] ); $this->end_controls_section(); $this->start_controls_section( 'section_style_image', [ 'label' => __( 'Image', 'elementor' ), 'tab' => Controls_Manager::TAB_STYLE, ] ); $this->add_responsive_control( 'space', [ 'label' => __( 'Size (%)', 'elementor' ), 'type' => Controls_Manager::SLIDER, 'default' => [ 'size' => 100, 'unit' => '%', ], 'tablet_default' => [ 'unit' => '%', ], 'mobile_default' => [ 'unit' => '%', ], 'size_units' => [ '%' ], 'range' => [ '%' => [ 'min' => 1, 'max' => 100, ], ], 'selectors' => [ '{{WRAPPER}} .elementor-image img' => 'max-width: {{SIZE}}{{UNIT}};', ], ] ); $this->add_control( 'opacity', [ 'label' => __( 'Opacity (%)', 'elementor' ), 'type' => Controls_Manager::SLIDER, 'default' => [ 'size' => 1, ], 'range' => [ 'px' => [ 'max' => 1, 'min' => 0.10, 'step' => 0.01, ], ], 'selectors' => [ '{{WRAPPER}} .elementor-image img' => 'opacity: {{SIZE}};', ], ] ); $this->add_control( 'hover_animation', [ 'label' => __( 'Hover Animation', 'elementor' ), 'type' => Controls_Manager::HOVER_ANIMATION, ] ); $this->add_group_control( Group_Control_Border::get_type(), [ 'name' => 'image_border', 'selector' => '{{WRAPPER}} .elementor-image img', 'separator' => 'before', ] ); $this->add_responsive_control( 'image_border_radius', [ 'label' => __( 'Border Radius', 'elementor' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => [ 'px', '%' ], 'selectors' => [ '{{WRAPPER}} .elementor-image img' => '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}} .elementor-image img', ] ); $this->end_controls_section(); $this->start_controls_section( 'section_style_caption', [ 'label' => __( 'Caption', 'elementor' ), 'tab' => Controls_Manager::TAB_STYLE, ] ); $this->add_control( 'caption_align', [ 'label' => __( 'Alignment', 'elementor' ), 'type' => Controls_Manager::CHOOSE, 'options' => [ 'left' => [ 'title' => __( 'Left', 'elementor' ), 'icon' => 'fa fa-align-left', ], 'center' => [ 'title' => __( 'Center', 'elementor' ), 'icon' => 'fa fa-align-center', ], 'right' => [ 'title' => __( 'Right', 'elementor' ), 'icon' => 'fa fa-align-right', ], 'justify' => [ 'title' => __( 'Justified', 'elementor' ), 'icon' => 'fa fa-align-justify', ], ], 'default' => '', 'selectors' => [ '{{WRAPPER}} .widget-image-caption' => 'text-align: {{VALUE}};', ], ] ); $this->add_control( 'text_color', [ 'label' => __( 'Text Color', 'elementor' ), 'type' => Controls_Manager::COLOR, 'default' => '', 'selectors' => [ '{{WRAPPER}} .widget-image-caption' => 'color: {{VALUE}};', ], 'scheme' => [ 'type' => Scheme_Color::get_type(), 'value' => Scheme_Color::COLOR_3, ], ] ); $this->add_group_control( Group_Control_Typography::get_type(), [ 'name' => 'caption_typography', 'selector' => '{{WRAPPER}} .widget-image-caption', 'scheme' => Scheme_Typography::TYPOGRAPHY_3, ] ); $this->end_controls_section(); } /** * Render image widget output on the frontend. * * Written in PHP and used to generate the final HTML. * * @since 1.0.0 * @access protected */ protected function render() { $settings = $this->get_settings(); if ( empty( $settings['image']['url'] ) ) { return; } $has_caption = ! empty( $settings['caption'] ); $this->add_render_attribute( 'wrapper', 'class', 'elementor-image' ); if ( ! empty( $settings['shape'] ) ) { $this->add_render_attribute( 'wrapper', 'class', 'elementor-image-shape-' . $settings['shape'] ); } $link = $this->get_link_url( $settings ); if ( $link ) { $this->add_render_attribute( 'link', [ 'href' => $link['url'], 'class' => 'elementor-clickable', 'data-elementor-open-lightbox' => $settings['open_lightbox'], ] ); if ( ! empty( $link['is_external'] ) ) { $this->add_render_attribute( 'link', 'target', '_blank' ); } if ( ! empty( $link['nofollow'] ) ) { $this->add_render_attribute( 'link', 'rel', 'nofollow' ); } } ?>
get_render_attribute_string( 'wrapper' ); ?>>
get_render_attribute_string( 'link' ); ?>>
<# if ( '' !== settings.image.url ) { var image = { id: settings.image.id, url: settings.image.url, size: settings.image_size, dimension: settings.image_custom_dimension, model: view.getEditModel() }; var image_url = elementor.imagesManager.getImageUrl( image ); if ( ! image_url ) { return; } var link_url; if ( 'custom' === settings.link_to ) { link_url = settings.link.url; } if ( 'file' === settings.link_to ) { link_url = settings.image.url; } #>
<# var imgClass = '', hasCaption = '' !== settings.caption; if ( '' !== settings.hover_animation ) { imgClass = 'elementor-animation-' + settings.hover_animation; } if ( hasCaption ) { #>
<# } if ( link_url ) { #><# } #><# if ( link_url ) { #><# } if ( hasCaption ) { #>
{{{ settings.caption }}}
<# } if ( hasCaption ) { #>
<# } #>
<# } #> $settings['image']['url'], ]; } }