| @@ -88,31 +88,9 @@ | ||
| 88 | 88 | public function get_keywords() { |
| 89 | 89 | return [ 'image', 'photo', 'visual' ]; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - protected function is_dynamic_content(): bool { | |
| 93 | - return false; | |
| 94 | - } | |
| 95 | - | |
| 96 | 92 | /** |
| 97 | - * Get style dependencies. | |
| 98 | - * | |
| 99 | - * Retrieve the list of style dependencies the widget requires. | |
| 100 | - * | |
| 101 | - * @since 3.24.0 | |
| 102 | - * @access public | |
| 103 | - * | |
| 104 | - * @return array Widget style dependencies. | |
| 105 | - */ | |
| 106 | - public function get_style_depends(): array { | |
| 107 | - return [ 'widget-image' ]; | |
| 108 | - } | |
| 109 | - | |
| 110 | - public function has_widget_inner_wrapper(): bool { | |
| 111 | - return ! Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' ); | |
| 112 | - } | |
| 113 | - | |
| 114 | - /** | |
| 115 | 93 | * Register image widget controls. |
| 116 | 94 | * |
| 117 | 95 | * Adds different input fields to allow the user to change and customize the widget settings. |
| 118 | 96 | * |
| @@ -145,11 +123,34 @@ | ||
| 145 | 123 | Group_Control_Image_Size::get_type(), |
| 146 | 124 | [ |
| 147 | 125 | 'name' => 'image', // Usage: `{name}_size` and `{name}_custom_dimension`, in this case `image_size` and `image_custom_dimension`. |
| 148 | 126 | 'default' => 'large', |
| 149 | - 'condition' => [ | |
| 150 | - 'image[url]!' => '', | |
| 127 | + 'separator' => 'none', | |
| 128 | + ] | |
| 129 | + ); | |
| 130 | + | |
| 131 | + $this->add_responsive_control( | |
| 132 | + 'align', | |
| 133 | + [ | |
| 134 | + 'label' => esc_html__( 'Alignment', 'elementor' ), | |
| 135 | + 'type' => Controls_Manager::CHOOSE, | |
| 136 | + 'options' => [ | |
| 137 | + 'left' => [ | |
| 138 | + 'title' => esc_html__( 'Left', 'elementor' ), | |
| 139 | + 'icon' => 'eicon-text-align-left', | |
| 140 | + ], | |
| 141 | + 'center' => [ | |
| 142 | + 'title' => esc_html__( 'Center', 'elementor' ), | |
| 143 | + 'icon' => 'eicon-text-align-center', | |
| 144 | + ], | |
| 145 | + 'right' => [ | |
| 146 | + 'title' => esc_html__( 'Right', 'elementor' ), | |
| 147 | + 'icon' => 'eicon-text-align-right', | |
| 148 | + ], | |
| 151 | 149 | ], |
| 150 | + 'selectors' => [ | |
| 151 | + '{{WRAPPER}}' => 'text-align: {{VALUE}};', | |
| 152 | + ], | |
| 152 | 153 | ] |
| 153 | 154 | ); |
| 154 | 155 | |
| 155 | 156 | $this->add_control( |
| @@ -162,11 +163,8 @@ | ||
| 162 | 163 | 'attachment' => esc_html__( 'Attachment Caption', 'elementor' ), |
| 163 | 164 | 'custom' => esc_html__( 'Custom Caption', 'elementor' ), |
| 164 | 165 | ], |
| 165 | 166 | 'default' => 'none', |
| 166 | - 'condition' => [ | |
| 167 | - 'image[url]!' => '', | |
| 168 | - ], | |
| 169 | 167 | ] |
| 170 | 168 | ); |
| 171 | 169 | |
| 172 | 170 | $this->add_control( |
| @@ -176,9 +174,8 @@ | ||
| 176 | 174 | 'type' => Controls_Manager::TEXT, |
| 177 | 175 | 'default' => '', |
| 178 | 176 | 'placeholder' => esc_html__( 'Enter your image caption', 'elementor' ), |
| 179 | 177 | 'condition' => [ |
| 180 | - 'image[url]!' => '', | |
| 181 | 178 | 'caption_source' => 'custom', |
| 182 | 179 | ], |
| 183 | 180 | 'dynamic' => [ |
| 184 | 181 | 'active' => true, |
| @@ -196,11 +193,8 @@ | ||
| 196 | 193 | 'none' => esc_html__( 'None', 'elementor' ), |
| 197 | 194 | 'file' => esc_html__( 'Media File', 'elementor' ), |
| 198 | 195 | 'custom' => esc_html__( 'Custom URL', 'elementor' ), |
| 199 | 196 | ], |
| 200 | - 'condition' => [ | |
| 201 | - 'image[url]!' => '', | |
| 202 | - ], | |
| 203 | 197 | ] |
| 204 | 198 | ); |
| 205 | 199 | |
| 206 | 200 | $this->add_control( |
| @@ -210,10 +204,10 @@ | ||
| 210 | 204 | 'type' => Controls_Manager::URL, |
| 211 | 205 | 'dynamic' => [ |
| 212 | 206 | 'active' => true, |
| 213 | 207 | ], |
| 208 | + 'placeholder' => esc_html__( 'https://your-link.com', 'elementor' ), | |
| 214 | 209 | 'condition' => [ |
| 215 | - 'image[url]!' => '', | |
| 216 | 210 | 'link_to' => 'custom', |
| 217 | 211 | ], |
| 218 | 212 | 'show_label' => false, |
| 219 | 213 | ] |
| @@ -236,14 +230,22 @@ | ||
| 236 | 230 | 'yes' => esc_html__( 'Yes', 'elementor' ), |
| 237 | 231 | 'no' => esc_html__( 'No', 'elementor' ), |
| 238 | 232 | ], |
| 239 | 233 | 'condition' => [ |
| 240 | - 'image[url]!' => '', | |
| 241 | 234 | 'link_to' => 'file', |
| 242 | 235 | ], |
| 243 | 236 | ] |
| 244 | 237 | ); |
| 245 | 238 | |
| 239 | + $this->add_control( | |
| 240 | + 'view', | |
| 241 | + [ | |
| 242 | + 'label' => esc_html__( 'View', 'elementor' ), | |
| 243 | + 'type' => Controls_Manager::HIDDEN, | |
| 244 | + 'default' => 'traditional', | |
| 245 | + ] | |
| 246 | + ); | |
| 247 | + | |
| 246 | 248 | $this->end_controls_section(); |
| 247 | 249 | |
| 248 | 250 | $this->start_controls_section( |
| 249 | 251 | 'section_style_image', |
| @@ -253,38 +255,8 @@ | ||
| 253 | 255 | ] |
| 254 | 256 | ); |
| 255 | 257 | |
| 256 | 258 | $this->add_responsive_control( |
| 257 | - 'align', | |
| 258 | - [ | |
| 259 | - 'label' => esc_html__( 'Alignment', 'elementor' ), | |
| 260 | - 'type' => Controls_Manager::CHOOSE, | |
| 261 | - 'options' => [ | |
| 262 | - 'start' => [ | |
| 263 | - 'title' => esc_html__( 'Start', 'elementor' ), | |
| 264 | - 'icon' => 'eicon-text-align-left', | |
| 265 | - ], | |
| 266 | - 'center' => [ | |
| 267 | - 'title' => esc_html__( 'Center', 'elementor' ), | |
| 268 | - 'icon' => 'eicon-text-align-center', | |
| 269 | - ], | |
| 270 | - 'end' => [ | |
| 271 | - 'title' => esc_html__( 'End', 'elementor' ), | |
| 272 | - 'icon' => 'eicon-text-align-right', | |
| 273 | - ], | |
| 274 | - ], | |
| 275 | - 'classes' => 'elementor-control-start-end', | |
| 276 | - 'selectors_dictionary' => [ | |
| 277 | - 'left' => is_rtl() ? 'end' : 'start', | |
| 278 | - 'right' => is_rtl() ? 'start' : 'end', | |
| 279 | - ], | |
| 280 | - 'selectors' => [ | |
| 281 | - '{{WRAPPER}}' => 'text-align: {{VALUE}};', | |
| 282 | - ], | |
| 283 | - ] | |
| 284 | - ); | |
| 285 | - | |
| 286 | - $this->add_responsive_control( | |
| 287 | 259 | 'width', |
| 288 | 260 | [ |
| 289 | 261 | 'label' => esc_html__( 'Width', 'elementor' ), |
| 290 | 262 | 'type' => Controls_Manager::SLIDER, |
| @@ -387,9 +359,8 @@ | ||
| 387 | 359 | '' => esc_html__( 'Default', 'elementor' ), |
| 388 | 360 | 'fill' => esc_html__( 'Fill', 'elementor' ), |
| 389 | 361 | 'cover' => esc_html__( 'Cover', 'elementor' ), |
| 390 | 362 | 'contain' => esc_html__( 'Contain', 'elementor' ), |
| 391 | - 'scale-down' => esc_html__( 'Scale Down', 'elementor' ), | |
| 392 | 363 | ], |
| 393 | 364 | 'default' => '', |
| 394 | 365 | 'selectors' => [ |
| 395 | 366 | '{{WRAPPER}} img' => 'object-fit: {{VALUE}};', |
| @@ -396,35 +367,8 @@ | ||
| 396 | 367 | ], |
| 397 | 368 | ] |
| 398 | 369 | ); |
| 399 | 370 | |
| 400 | - $this->add_responsive_control( | |
| 401 | - 'object-position', | |
| 402 | - [ | |
| 403 | - 'label' => esc_html__( 'Object Position', 'elementor' ), | |
| 404 | - 'type' => Controls_Manager::SELECT, | |
| 405 | - 'options' => [ | |
| 406 | - 'center center' => esc_html__( 'Center Center', 'elementor' ), | |
| 407 | - 'center left' => esc_html__( 'Center Left', 'elementor' ), | |
| 408 | - 'center right' => esc_html__( 'Center Right', 'elementor' ), | |
| 409 | - 'top center' => esc_html__( 'Top Center', 'elementor' ), | |
| 410 | - 'top left' => esc_html__( 'Top Left', 'elementor' ), | |
| 411 | - 'top right' => esc_html__( 'Top Right', 'elementor' ), | |
| 412 | - 'bottom center' => esc_html__( 'Bottom Center', 'elementor' ), | |
| 413 | - 'bottom left' => esc_html__( 'Bottom Left', 'elementor' ), | |
| 414 | - 'bottom right' => esc_html__( 'Bottom Right', 'elementor' ), | |
| 415 | - ], | |
| 416 | - 'default' => 'center center', | |
| 417 | - 'selectors' => [ | |
| 418 | - '{{WRAPPER}} img' => 'object-position: {{VALUE}};', | |
| 419 | - ], | |
| 420 | - 'condition' => [ | |
| 421 | - 'height[size]!' => '', | |
| 422 | - 'object-fit' => [ 'cover', 'contain', 'scale-down' ], | |
| 423 | - ], | |
| 424 | - ] | |
| 425 | - ); | |
| 426 | - | |
| 427 | 371 | $this->add_control( |
| 428 | 372 | 'separator_panel_style', |
| 429 | 373 | [ |
| 430 | 374 | 'type' => Controls_Manager::DIVIDER, |
| @@ -502,13 +446,12 @@ | ||
| 502 | 446 | |
| 503 | 447 | $this->add_control( |
| 504 | 448 | 'background_hover_transition', |
| 505 | 449 | [ |
| 506 | - 'label' => esc_html__( 'Transition Duration', 'elementor' ) . ' (s)', | |
| 450 | + 'label' => esc_html__( 'Transition Duration', 'elementor' ), | |
| 507 | 451 | 'type' => Controls_Manager::SLIDER, |
| 508 | 452 | 'range' => [ |
| 509 | 453 | 'px' => [ |
| 510 | - 'min' => 0, | |
| 511 | 454 | 'max' => 3, |
| 512 | 455 | 'step' => 0.1, |
| 513 | 456 | ], |
| 514 | 457 | ], |
| @@ -569,9 +512,8 @@ | ||
| 569 | 512 | [ |
| 570 | 513 | 'label' => esc_html__( 'Caption', 'elementor' ), |
| 571 | 514 | 'tab' => Controls_Manager::TAB_STYLE, |
| 572 | 515 | 'condition' => [ |
| 573 | - 'image[url]!' => '', | |
| 574 | 516 | 'caption_source!' => 'none', |
| 575 | 517 | ], |
| 576 | 518 | ] |
| 577 | 519 | ); |
| @@ -581,10 +523,10 @@ | ||
| 581 | 523 | [ |
| 582 | 524 | 'label' => esc_html__( 'Alignment', 'elementor' ), |
| 583 | 525 | 'type' => Controls_Manager::CHOOSE, |
| 584 | 526 | 'options' => [ |
| 585 | - 'start' => [ | |
| 586 | - 'title' => esc_html__( 'Start', 'elementor' ), | |
| 527 | + 'left' => [ | |
| 528 | + 'title' => esc_html__( 'Left', 'elementor' ), | |
| 587 | 529 | 'icon' => 'eicon-text-align-left', |
| 588 | 530 | ], |
| 589 | 531 | 'center' => [ |
| 590 | 532 | 'title' => esc_html__( 'Center', 'elementor' ), |
| @@ -589,10 +531,10 @@ | ||
| 589 | 531 | 'center' => [ |
| 590 | 532 | 'title' => esc_html__( 'Center', 'elementor' ), |
| 591 | 533 | 'icon' => 'eicon-text-align-center', |
| 592 | 534 | ], |
| 593 | - 'end' => [ | |
| 594 | - 'title' => esc_html__( 'End', 'elementor' ), | |
| 535 | + 'right' => [ | |
| 536 | + 'title' => esc_html__( 'Right', 'elementor' ), | |
| 595 | 537 | 'icon' => 'eicon-text-align-right', |
| 596 | 538 | ], |
| 597 | 539 | 'justify' => [ |
| 598 | 540 | 'title' => esc_html__( 'Justified', 'elementor' ), |
| @@ -598,13 +540,8 @@ | ||
| 598 | 540 | 'title' => esc_html__( 'Justified', 'elementor' ), |
| 599 | 541 | 'icon' => 'eicon-text-align-justify', |
| 600 | 542 | ], |
| 601 | 543 | ], |
| 602 | - 'classes' => 'elementor-control-start-end', | |
| 603 | - 'selectors_dictionary' => [ | |
| 604 | - 'left' => is_rtl() ? 'end' : 'start', | |
| 605 | - 'right' => is_rtl() ? 'start' : 'end', | |
| 606 | - ], | |
| 607 | 544 | 'default' => '', |
| 608 | 545 | 'selectors' => [ |
| 609 | 546 | '{{WRAPPER}} .widget-image-caption' => 'text-align: {{VALUE}};', |
| 610 | 547 | ], |
| @@ -660,24 +597,16 @@ | ||
| 660 | 597 | 'caption_space', |
| 661 | 598 | [ |
| 662 | 599 | 'label' => esc_html__( 'Spacing', 'elementor' ), |
| 663 | 600 | 'type' => Controls_Manager::SLIDER, |
| 664 | - 'size_units' => [ 'px', 'em', 'rem', 'custom' ], | |
| 665 | 601 | 'range' => [ |
| 666 | 602 | 'px' => [ |
| 603 | + 'min' => 0, | |
| 667 | 604 | 'max' => 100, |
| 668 | 605 | ], |
| 669 | - 'em' => [ | |
| 670 | - 'min' => 0, | |
| 671 | - 'max' => 10, | |
| 672 | - ], | |
| 673 | - 'rem' => [ | |
| 674 | - 'min' => 0, | |
| 675 | - 'max' => 10, | |
| 676 | - ], | |
| 677 | 606 | ], |
| 678 | 607 | 'selectors' => [ |
| 679 | - '{{WRAPPER}} .widget-image-caption' => 'margin-block-start: {{SIZE}}{{UNIT}};', | |
| 608 | + '{{WRAPPER}} .widget-image-caption' => 'margin-top: {{SIZE}}{{UNIT}};', | |
| 680 | 609 | ], |
| 681 | 610 | ] |
| 682 | 611 | ); |
| 683 | 612 | |
| @@ -702,9 +631,9 @@ | ||
| 702 | 631 | * Get the caption for current widget. |
| 703 | 632 | * |
| 704 | 633 | * @access private |
| 705 | 634 | * @since 2.3.0 |
| 706 | - * @param array $settings | |
| 635 | + * @param $settings | |
| 707 | 636 | * |
| 708 | 637 | * @return string |
| 709 | 638 | */ |
| 710 | 639 | private function get_caption( $settings ) { |
| @@ -735,8 +664,12 @@ | ||
| 735 | 664 | if ( empty( $settings['image']['url'] ) ) { |
| 736 | 665 | return; |
| 737 | 666 | } |
| 738 | 667 | |
| 668 | + if ( ! Plugin::$instance->experiments->is_feature_active( 'e_dom_optimization' ) ) { | |
| 669 | + $this->add_render_attribute( 'wrapper', 'class', 'elementor-image' ); | |
| 670 | + } | |
| 671 | + | |
| 739 | 672 | $has_caption = $this->has_caption( $settings ); |
| 740 | 673 | |
| 741 | 674 | $link = $this->get_link_url( $settings ); |
| 742 | 675 | |
| @@ -752,8 +685,11 @@ | ||
| 752 | 685 | if ( 'custom' !== $settings['link_to'] ) { |
| 753 | 686 | $this->add_lightbox_data_attributes( 'link', $settings['image']['id'], $settings['open_lightbox'] ); |
| 754 | 687 | } |
| 755 | 688 | } ?> |
| 689 | + <?php if ( ! Plugin::$instance->experiments->is_feature_active( 'e_dom_optimization' ) ) { ?> | |
| 690 | + <div <?php $this->print_render_attribute_string( 'wrapper' ); ?>> | |
| 691 | + <?php } ?> | |
| 756 | 692 | <?php if ( $has_caption ) : ?> |
| 757 | 693 | <figure class="wp-caption"> |
| 758 | 694 | <?php endif; ?> |
| 759 | 695 | <?php if ( $link ) : ?> |
| @@ -770,67 +706,14 @@ | ||
| 770 | 706 | <?php endif; ?> |
| 771 | 707 | <?php if ( $has_caption ) : ?> |
| 772 | 708 | </figure> |
| 773 | 709 | <?php endif; ?> |
| 710 | + <?php if ( ! Plugin::$instance->experiments->is_feature_active( 'e_dom_optimization' ) ) { ?> | |
| 711 | + </div> | |
| 712 | + <?php } ?> | |
| 774 | 713 | <?php |
| 775 | 714 | } |
| 776 | 715 | |
| 777 | - public function render_markdown(): string { | |
| 778 | - $settings = $this->get_settings_for_display(); | |
| 779 | - | |
| 780 | - if ( empty( $settings['image']['url'] ) ) { | |
| 781 | - return ''; | |
| 782 | - } | |
| 783 | - | |
| 784 | - $url = esc_url( $settings['image']['url'] ); | |
| 785 | - $alt = $this->get_image_alt_text( $settings ); | |
| 786 | - $image_md = ''; | |
| 787 | - | |
| 788 | - $link = $this->get_link_url( $settings ); | |
| 789 | - | |
| 790 | - if ( ! empty( $link['url'] ) && $link['url'] !== $url ) { | |
| 791 | - $image_md = '[' . $image_md . '](' . esc_url( $link['url'] ) . ')'; | |
| 792 | - } | |
| 793 | - | |
| 794 | - $caption = $this->get_visible_caption( $settings ); | |
| 795 | - | |
| 796 | - if ( ! empty( $caption ) ) { | |
| 797 | - $image_md .= "\n" . $caption; | |
| 798 | - } | |
| 799 | - | |
| 800 | - return $image_md; | |
| 801 | - } | |
| 802 | - | |
| 803 | - private function get_image_alt_text( array $settings ): string { | |
| 804 | - if ( empty( $settings['image']['id'] ) ) { | |
| 805 | - return ''; | |
| 806 | - } | |
| 807 | - | |
| 808 | - $attachment_id = $settings['image']['id']; | |
| 809 | - | |
| 810 | - $alt = get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ); | |
| 811 | - | |
| 812 | - if ( ! empty( $alt ) ) { | |
| 813 | - return $alt; | |
| 814 | - } | |
| 815 | - | |
| 816 | - $attachment = get_post( $attachment_id ); | |
| 817 | - | |
| 818 | - if ( ! $attachment ) { | |
| 819 | - return ''; | |
| 820 | - } | |
| 821 | - | |
| 822 | - return $attachment->post_title ?? ''; | |
| 823 | - } | |
| 824 | - | |
| 825 | - private function get_visible_caption( array $settings ): string { | |
| 826 | - if ( ! $this->has_caption( $settings ) ) { | |
| 827 | - return ''; | |
| 828 | - } | |
| 829 | - | |
| 830 | - return Utils::html_to_plain_text( $this->get_caption( $settings ) ); | |
| 831 | - } | |
| 832 | - | |
| 833 | 716 | /** |
| 834 | 717 | * Render image widget output in the editor. |
| 835 | 718 | * |
| 836 | 719 | * Written as a Backbone JavaScript template and used to generate the live preview. |
| @@ -887,9 +770,9 @@ | ||
| 887 | 770 | |
| 888 | 771 | var link_url; |
| 889 | 772 | |
| 890 | 773 | if ( 'custom' === settings.link_to ) { |
| 891 | - link_url = settings.link?.url; | |
| 774 | + link_url = settings.link.url; | |
| 892 | 775 | } |
| 893 | 776 | |
| 894 | 777 | if ( 'file' === settings.link_to ) { |
| 895 | 778 | link_url = settings.image.url; |
| @@ -894,8 +777,12 @@ | ||
| 894 | 777 | if ( 'file' === settings.link_to ) { |
| 895 | 778 | link_url = settings.image.url; |
| 896 | 779 | } |
| 897 | 780 | |
| 781 | + <?php if ( ! Plugin::$instance->experiments->is_feature_active( 'e_dom_optimization' ) ) { ?> | |
| 782 | + #><div class="elementor-image{{ settings.shape ? ' elementor-image-shape-' + settings.shape : '' }}"><# | |
| 783 | + <?php } ?> | |
| 784 | + | |
| 898 | 785 | var imgClass = ''; |
| 899 | 786 | |
| 900 | 787 | if ( '' !== settings.hover_animation ) { |
| 901 | 788 | imgClass = 'elementor-animation-' + settings.hover_animation; |
| @@ -905,9 +792,9 @@ | ||
| 905 | 792 | #><figure class="wp-caption"><# |
| 906 | 793 | } |
| 907 | 794 | |
| 908 | 795 | if ( link_url ) { |
| 909 | - #><a class="elementor-clickable" data-elementor-open-lightbox="{{ settings.open_lightbox }}" href="{{ elementor.helpers.sanitizeUrl( link_url ) }}"><# | |
| 796 | + #><a class="elementor-clickable" data-elementor-open-lightbox="{{ settings.open_lightbox }}" href="{{ link_url }}"><# | |
| 910 | 797 | } |
| 911 | 798 | #><img src="{{ image_url }}" class="{{ imgClass }}" /><# |
| 912 | 799 | |
| 913 | 800 | if ( link_url ) { |
| @@ -920,8 +807,13 @@ | ||
| 920 | 807 | |
| 921 | 808 | if ( hasCaption() ) { |
| 922 | 809 | #></figure><# |
| 923 | 810 | } |
| 811 | + | |
| 812 | + <?php if ( ! Plugin::$instance->experiments->is_feature_active( 'e_dom_optimization' ) ) { ?> | |
| 813 | + #></div><# | |
| 814 | + <?php } ?> | |
| 815 | + | |
| 924 | 816 | } #> |
| 925 | 817 | <?php |
| 926 | 818 | } |
| 927 | 819 | |