PluginProbe
Elementor Website Builder – more than just a page builder / 3.33.0-dev1
Elementor Website Builder – more than just a page builder v3.33.0-dev1
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-box.php

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

895 lines 21.4 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\Core\Kits\Documents\Tabs\Global_Typography;
10
11 /**
12 * Elementor image box widget.
13 *
14 * Elementor widget that displays an image, a headline and a text.
15 *
16 * @since 1.0.0
17 */
18 class Widget_Image_Box extends Widget_Base {
19
20 /**
21 * Get widget name.
22 *
23 * Retrieve image box 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-box';
32 }
33
34 /**
35 * Get widget title.
36 *
37 * Retrieve image box 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 Box', 'elementor' );
46 }
47
48 /**
49 * Get widget icon.
50 *
51 * Retrieve image box 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-image-box';
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', 'box' ];
74 }
75
76 protected function is_dynamic_content(): bool {
77 return false;
78 }
79
80 /**
81 * Get style dependencies.
82 *
83 * Retrieve the list of style dependencies the widget requires.
84 *
85 * @since 3.24.0
86 * @access public
87 *
88 * @return array Widget style dependencies.
89 */
90 public function get_style_depends(): array {
91 return [ 'widget-image-box' ];
92 }
93
94 public function has_widget_inner_wrapper(): bool {
95 return ! Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' );
96 }
97
98 /**
99 * Register image box widget controls.
100 *
101 * Adds different input fields to allow the user to change and customize the widget settings.
102 *
103 * @since 3.1.0
104 * @access protected
105 */
106 protected function register_controls() {
107 $this->start_controls_section(
108 'section_image',
109 [
110 'label' => esc_html__( 'Image Box', 'elementor' ),
111 ]
112 );
113
114 $this->add_control(
115 'image',
116 [
117 'label' => esc_html__( 'Choose Image', 'elementor' ),
118 'type' => Controls_Manager::MEDIA,
119 'dynamic' => [
120 'active' => true,
121 ],
122 'default' => [
123 'url' => Utils::get_placeholder_image_src(),
124 ],
125 ]
126 );
127
128 $this->add_group_control(
129 Group_Control_Image_Size::get_type(),
130 [
131 'name' => 'thumbnail', // Usage: `{name}_size` and `{name}_custom_dimension`, in this case `thumbnail_size` and `thumbnail_custom_dimension`.
132 'default' => 'full',
133 'condition' => [
134 'image[url]!' => '',
135 ],
136 ]
137 );
138
139 $this->add_control(
140 'title_text',
141 [
142 'label' => esc_html__( 'Title', 'elementor' ),
143 'type' => Controls_Manager::TEXT,
144 'dynamic' => [
145 'active' => true,
146 ],
147 'default' => esc_html__( 'This is the heading', 'elementor' ),
148 'placeholder' => esc_html__( 'Enter your title', 'elementor' ),
149 'label_block' => true,
150 ]
151 );
152
153 $this->add_control(
154 'description_text',
155 [
156 'label' => esc_html__( 'Description', 'elementor' ),
157 'type' => Controls_Manager::TEXTAREA,
158 'dynamic' => [
159 'active' => true,
160 ],
161 'default' => esc_html__( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.', 'elementor' ),
162 'placeholder' => esc_html__( 'Enter your description', 'elementor' ),
163 'rows' => 10,
164 ]
165 );
166
167 $this->add_control(
168 'link',
169 [
170 'label' => esc_html__( 'Link', 'elementor' ),
171 'type' => Controls_Manager::URL,
172 'dynamic' => [
173 'active' => true,
174 ],
175 'separator' => 'before',
176 ]
177 );
178
179 $this->add_control(
180 'title_size',
181 [
182 'label' => esc_html__( 'Title HTML Tag', 'elementor' ),
183 'type' => Controls_Manager::SELECT,
184 'options' => [
185 'h1' => 'H1',
186 'h2' => 'H2',
187 'h3' => 'H3',
188 'h4' => 'H4',
189 'h5' => 'H5',
190 'h6' => 'H6',
191 'div' => 'div',
192 'span' => 'span',
193 'p' => 'p',
194 ],
195 'default' => 'h3',
196 ]
197 );
198
199 $this->end_controls_section();
200
201 $this->start_controls_section(
202 'section_style_box',
203 [
204 'label' => esc_html__( 'Box', 'elementor' ),
205 'tab' => Controls_Manager::TAB_STYLE,
206 ]
207 );
208
209 $this->add_responsive_control(
210 'position',
211 [
212 'label' => esc_html__( 'Image Position', 'elementor' ),
213 'type' => Controls_Manager::CHOOSE,
214 'default' => 'top',
215 'options' => [
216 'left' => [
217 'title' => esc_html__( 'Left', 'elementor' ),
218 'icon' => 'eicon-h-align-left',
219 ],
220 'top' => [
221 'title' => esc_html__( 'Top', 'elementor' ),
222 'icon' => 'eicon-v-align-top',
223 ],
224 'right' => [
225 'title' => esc_html__( 'Right', 'elementor' ),
226 'icon' => 'eicon-h-align-right',
227 ],
228 ],
229 'prefix_class' => 'elementor-position-',
230 'toggle' => false,
231 'condition' => [
232 'image[url]!' => '',
233 ],
234 ]
235 );
236
237 $this->add_responsive_control(
238 'content_vertical_alignment',
239 [
240 'label' => esc_html__( 'Vertical Alignment', 'elementor' ),
241 'type' => Controls_Manager::CHOOSE,
242 'options' => [
243 'top' => [
244 'title' => esc_html__( 'Top', 'elementor' ),
245 'icon' => 'eicon-v-align-top',
246 ],
247 'middle' => [
248 'title' => esc_html__( 'Middle', 'elementor' ),
249 'icon' => 'eicon-v-align-middle',
250 ],
251 'bottom' => [
252 'title' => esc_html__( 'Bottom', 'elementor' ),
253 'icon' => 'eicon-v-align-bottom',
254 ],
255 ],
256 'default' => 'top',
257 'toggle' => false,
258 'prefix_class' => 'elementor-vertical-align-',
259 'condition' => [
260 'position!' => 'top',
261 ],
262 ]
263 );
264
265 $this->add_responsive_control(
266 'text_align',
267 [
268 'label' => esc_html__( 'Alignment', 'elementor' ),
269 'type' => Controls_Manager::CHOOSE,
270 'options' => [
271 'left' => [
272 'title' => esc_html__( 'Left', 'elementor' ),
273 'icon' => 'eicon-text-align-left',
274 ],
275 'center' => [
276 'title' => esc_html__( 'Center', 'elementor' ),
277 'icon' => 'eicon-text-align-center',
278 ],
279 'right' => [
280 'title' => esc_html__( 'Right', 'elementor' ),
281 'icon' => 'eicon-text-align-right',
282 ],
283 'justify' => [
284 'title' => esc_html__( 'Justified', 'elementor' ),
285 'icon' => 'eicon-text-align-justify',
286 ],
287 ],
288 'selectors' => [
289 '{{WRAPPER}} .elementor-image-box-wrapper' => 'text-align: {{VALUE}};',
290 ],
291 'separator' => 'after',
292 ]
293 );
294
295 $this->add_responsive_control(
296 'image_space',
297 [
298 'label' => esc_html__( 'Image Spacing', 'elementor' ),
299 'type' => Controls_Manager::SLIDER,
300 'size_units' => [ 'px', '%', 'em', 'rem', 'vw', 'custom' ],
301 'default' => [
302 'size' => 15,
303 ],
304 'range' => [
305 'px' => [
306 'max' => 100,
307 ],
308 ],
309 'selectors' => [
310 '{{WRAPPER}}.elementor-position-right .elementor-image-box-img' => 'margin-left: {{SIZE}}{{UNIT}};',
311 '{{WRAPPER}}.elementor-position-left .elementor-image-box-img' => 'margin-right: {{SIZE}}{{UNIT}};',
312 '{{WRAPPER}}.elementor-position-top .elementor-image-box-img' => 'margin-bottom: {{SIZE}}{{UNIT}};',
313 '(mobile){{WRAPPER}} .elementor-image-box-img' => 'margin-bottom: {{SIZE}}{{UNIT}};',
314 ],
315 'condition' => [
316 'image[url]!' => '',
317 ],
318 ]
319 );
320
321 $this->add_responsive_control(
322 'title_bottom_space',
323 [
324 'label' => esc_html__( 'Content Spacing', 'elementor' ),
325 'type' => Controls_Manager::SLIDER,
326 'size_units' => [ 'px', 'em', 'rem', 'custom' ],
327 'range' => [
328 'px' => [
329 'max' => 100,
330 ],
331 'em' => [
332 'min' => 0,
333 'max' => 10,
334 ],
335 'rem' => [
336 'min' => 0,
337 'max' => 10,
338 ],
339 ],
340 'selectors' => [
341 '{{WRAPPER}} .elementor-image-box-title' => 'margin-bottom: {{SIZE}}{{UNIT}};',
342 ],
343 ]
344 );
345
346 $this->end_controls_section();
347
348 $this->start_controls_section(
349 'section_style_image',
350 [
351 'label' => esc_html__( 'Image', 'elementor' ),
352 'tab' => Controls_Manager::TAB_STYLE,
353 'condition' => [
354 'image[url]!' => '',
355 ],
356 ]
357 );
358
359 $this->add_responsive_control(
360 'image_size',
361 [
362 'label' => esc_html__( 'Width', 'elementor' ),
363 'type' => Controls_Manager::SLIDER,
364 'default' => [
365 'size' => 30,
366 'unit' => '%',
367 ],
368 'tablet_default' => [
369 'unit' => '%',
370 ],
371 'mobile_default' => [
372 'unit' => '%',
373 ],
374 'size_units' => [ 'px', '%', 'em', 'rem', 'vw', 'custom' ],
375 'range' => [
376 '%' => [
377 'min' => 5,
378 'max' => 100,
379 ],
380 ],
381 'selectors' => [
382 '{{WRAPPER}} .elementor-image-box-wrapper .elementor-image-box-img' => 'width: {{SIZE}}{{UNIT}};',
383 ],
384 ]
385 );
386
387 $this->add_responsive_control(
388 'image_height',
389 [
390 'label' => esc_html__( 'Height', 'elementor' ),
391 'type' => Controls_Manager::SLIDER,
392 'size_units' => [ 'px', '%', 'em', 'rem', 'vh', 'custom' ],
393 'selectors' => [
394 '{{WRAPPER}} .elementor-image-box-img img' => 'height: {{SIZE}}{{UNIT}};',
395 ],
396 ]
397 );
398
399 $this->add_responsive_control(
400 'image_object_fit',
401 [
402 'label' => esc_html__( 'Object Fit', 'elementor' ),
403 'type' => Controls_Manager::SELECT,
404 'options' => [
405 '' => esc_html__( 'Default', 'elementor' ),
406 'fill' => esc_html__( 'Fill', 'elementor' ),
407 'cover' => esc_html__( 'Cover', 'elementor' ),
408 'contain' => esc_html__( 'Contain', 'elementor' ),
409 'scale-down' => esc_html__( 'Scale Down', 'elementor' ),
410 ],
411 'condition' => [
412 'image_height[size]!' => '',
413 ],
414 'selectors' => [
415 '{{WRAPPER}} .elementor-image-box-img img' => 'object-fit: {{VALUE}};',
416 ],
417 ]
418 );
419
420 $this->add_responsive_control(
421 'image_object_position',
422 [
423 'label' => esc_html__( 'Object Position', 'elementor' ),
424 'type' => Controls_Manager::SELECT,
425 'options' => [
426 'center center' => esc_html__( 'Center Center', 'elementor' ),
427 'center left' => esc_html__( 'Center Left', 'elementor' ),
428 'center right' => esc_html__( 'Center Right', 'elementor' ),
429 'top center' => esc_html__( 'Top Center', 'elementor' ),
430 'top left' => esc_html__( 'Top Left', 'elementor' ),
431 'top right' => esc_html__( 'Top Right', 'elementor' ),
432 'bottom center' => esc_html__( 'Bottom Center', 'elementor' ),
433 'bottom left' => esc_html__( 'Bottom Left', 'elementor' ),
434 'bottom right' => esc_html__( 'Bottom Right', 'elementor' ),
435 ],
436 'default' => 'center center',
437 'selectors' => [
438 '{{WRAPPER}} .elementor-image-box-img img' => 'object-position: {{VALUE}};',
439 ],
440 'condition' => [
441 'image_height[size]!' => '',
442 'image_object_fit' => [ 'cover', 'contain', 'scale-down' ],
443 ],
444 ]
445 );
446
447 $this->add_group_control(
448 Group_Control_Border::get_type(),
449 [
450 'name' => 'image_border',
451 'selector' => '{{WRAPPER}} .elementor-image-box-img img',
452 'separator' => 'before',
453 ]
454 );
455
456 $this->add_responsive_control(
457 'image_border_radius',
458 [
459 'label' => esc_html__( 'Border Radius', 'elementor' ),
460 'type' => Controls_Manager::SLIDER,
461 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
462 'selectors' => [
463 '{{WRAPPER}} .elementor-image-box-img img' => 'border-radius: {{SIZE}}{{UNIT}};',
464 ],
465 ]
466 );
467
468 $this->add_group_control(
469 Group_Control_Box_Shadow::get_type(),
470 [
471 'name' => 'image_box_shadow',
472 'selector' => '{{WRAPPER}} .elementor-image-box-img img',
473 ]
474 );
475
476 $this->add_control(
477 'separator_panel_style',
478 [
479 'type' => Controls_Manager::DIVIDER,
480 'style' => 'thick',
481 ]
482 );
483
484 $this->start_controls_tabs( 'image_effects' );
485
486 $this->start_controls_tab(
487 'normal',
488 [
489 'label' => esc_html__( 'Normal', 'elementor' ),
490 ]
491 );
492
493 $this->add_group_control(
494 Group_Control_Css_Filter::get_type(),
495 [
496 'name' => 'css_filters',
497 'selector' => '{{WRAPPER}} .elementor-image-box-img img',
498 ]
499 );
500
501 $this->add_control(
502 'image_opacity',
503 [
504 'label' => esc_html__( 'Opacity', 'elementor' ),
505 'type' => Controls_Manager::SLIDER,
506 'range' => [
507 'px' => [
508 'max' => 1,
509 'min' => 0.10,
510 'step' => 0.01,
511 ],
512 ],
513 'selectors' => [
514 '{{WRAPPER}} .elementor-image-box-img img' => 'opacity: {{SIZE}};',
515 ],
516 ]
517 );
518
519 $this->end_controls_tab();
520
521 $this->start_controls_tab(
522 'hover',
523 [
524 'label' => esc_html__( 'Hover', 'elementor' ),
525 ]
526 );
527
528 $this->add_group_control(
529 Group_Control_Css_Filter::get_type(),
530 [
531 'name' => 'css_filters_hover',
532 'selector' => '{{WRAPPER}}:hover .elementor-image-box-img img',
533 ]
534 );
535
536 $this->add_control(
537 'image_opacity_hover',
538 [
539 'label' => esc_html__( 'Opacity', 'elementor' ),
540 'type' => Controls_Manager::SLIDER,
541 'range' => [
542 'px' => [
543 'max' => 1,
544 'min' => 0.10,
545 'step' => 0.01,
546 ],
547 ],
548 'selectors' => [
549 '{{WRAPPER}}:hover .elementor-image-box-img img' => 'opacity: {{SIZE}};',
550 ],
551 ]
552 );
553
554 $this->add_control(
555 'background_hover_transition',
556 [
557 'label' => esc_html__( 'Transition Duration', 'elementor' ) . ' (s)',
558 'type' => Controls_Manager::SLIDER,
559 'default' => [
560 'size' => 0.3,
561 ],
562 'range' => [
563 'px' => [
564 'min' => 0,
565 'max' => 3,
566 'step' => 0.1,
567 ],
568 ],
569 'selectors' => [
570 '{{WRAPPER}} .elementor-image-box-img img' => 'transition-duration: {{SIZE}}s',
571 ],
572 ]
573 );
574
575 $this->add_control(
576 'hover_animation',
577 [
578 'label' => esc_html__( 'Hover Animation', 'elementor' ),
579 'type' => Controls_Manager::HOVER_ANIMATION,
580 ]
581 );
582
583 $this->end_controls_tab();
584
585 $this->end_controls_tabs();
586
587 $this->end_controls_section();
588
589 $this->start_controls_section(
590 'section_style_content',
591 [
592 'label' => esc_html__( 'Content', 'elementor' ),
593 'tab' => Controls_Manager::TAB_STYLE,
594 ]
595 );
596
597 $this->add_control(
598 'heading_title',
599 [
600 'label' => esc_html__( 'Title', 'elementor' ),
601 'type' => Controls_Manager::HEADING,
602 'separator' => 'before',
603 ]
604 );
605
606 $this->add_group_control(
607 Group_Control_Typography::get_type(),
608 [
609 'name' => 'title_typography',
610 'selector' => '{{WRAPPER}} .elementor-image-box-title',
611 'global' => [
612 'default' => Global_Typography::TYPOGRAPHY_PRIMARY,
613 ],
614 ]
615 );
616
617 $this->add_group_control(
618 Group_Control_Text_Stroke::get_type(),
619 [
620 'name' => 'title_stroke',
621 'selector' => '{{WRAPPER}} .elementor-image-box-title',
622 ]
623 );
624
625 $this->add_group_control(
626 Group_Control_Text_Shadow::get_type(),
627 [
628 'name' => 'title_shadow',
629 'selector' => '{{WRAPPER}} .elementor-image-box-title',
630 ]
631 );
632
633 $this->start_controls_tabs( 'image_box_title_colors' );
634
635 $this->start_controls_tab(
636 'image_box_title_colors_normal',
637 [
638 'label' => esc_html__( 'Normal', 'elementor' ),
639 ]
640 );
641
642 $this->add_control(
643 'title_color',
644 [
645 'label' => esc_html__( 'Color', 'elementor' ),
646 'type' => Controls_Manager::COLOR,
647 'default' => '',
648 'selectors' => [
649 '{{WRAPPER}} .elementor-image-box-title' => 'color: {{VALUE}};',
650 ],
651 'global' => [
652 'default' => Global_Colors::COLOR_PRIMARY,
653 ],
654 ]
655 );
656
657 $this->end_controls_tab();
658
659 $this->start_controls_tab(
660 'image_box_title_colors_hover',
661 [
662 'label' => esc_html__( 'Hover', 'elementor' ),
663 ]
664 );
665
666 $this->add_control(
667 'hover_title_color',
668 [
669 'label' => esc_html__( 'Color', 'elementor' ),
670 'type' => Controls_Manager::COLOR,
671 'default' => '',
672 'selectors' => [
673 '{{WRAPPER}}:has(:hover) .elementor-image-box-title,
674 {{WRAPPER}}:has(:focus) .elementor-image-box-title' => 'color: {{VALUE}};',
675 ],
676 'global' => [
677 'default' => Global_Colors::COLOR_PRIMARY,
678 ],
679 ]
680 );
681
682 $this->add_control(
683 'hover_title_color_transition_duration',
684 [
685 'label' => esc_html__( 'Transition Duration', 'elementor' ),
686 'type' => Controls_Manager::SLIDER,
687 'size_units' => [ 's', 'ms', 'custom' ],
688 'default' => [
689 'unit' => 's',
690 ],
691 'selectors' => [
692 '{{WRAPPER}} .elementor-image-box-title' => 'transition-duration: {{SIZE}}{{UNIT}};',
693 ],
694 ]
695 );
696
697 $this->end_controls_tab();
698
699 $this->end_controls_tabs();
700
701 $this->add_control(
702 'heading_description',
703 [
704 'label' => esc_html__( 'Description', 'elementor' ),
705 'type' => Controls_Manager::HEADING,
706 'separator' => 'before',
707 ]
708 );
709
710 $this->add_group_control(
711 Group_Control_Typography::get_type(),
712 [
713 'name' => 'description_typography',
714 'selector' => '{{WRAPPER}} .elementor-image-box-description',
715 'global' => [
716 'default' => Global_Typography::TYPOGRAPHY_TEXT,
717 ],
718 ]
719 );
720
721 $this->add_group_control(
722 Group_Control_Text_Shadow::get_type(),
723 [
724 'name' => 'description_shadow',
725 'selector' => '{{WRAPPER}} .elementor-image-box-description',
726 ]
727 );
728
729 $this->add_control(
730 'description_color',
731 [
732 'label' => esc_html__( 'Color', 'elementor' ),
733 'type' => Controls_Manager::COLOR,
734 'default' => '',
735 'selectors' => [
736 '{{WRAPPER}} .elementor-image-box-description' => 'color: {{VALUE}};',
737 ],
738 'global' => [
739 'default' => Global_Colors::COLOR_TEXT,
740 ],
741 ]
742 );
743
744 $this->end_controls_section();
745 }
746
747 /**
748 * Render image box widget output on the frontend.
749 *
750 * Written in PHP and used to generate the final HTML.
751 *
752 * @since 1.0.0
753 * @access protected
754 */
755 protected function render() {
756 $settings = $this->get_settings_for_display();
757
758 $description_text = wp_kses_post( $settings['description_text'] );
759 $title_text = wp_kses_post( $settings['title_text'] );
760
761 $has_image = ! empty( $settings['image']['url'] );
762 $has_content = ! Utils::is_empty( $title_text ) || ! Utils::is_empty( $description_text );
763
764 if ( ! $has_image && ! $has_content ) {
765 return;
766 }
767
768 $html = '<div class="elementor-image-box-wrapper">';
769
770 if ( ! empty( $settings['link']['url'] ) ) {
771 $this->add_link_attributes( 'link', $settings['link'] );
772 }
773
774 if ( $has_image ) {
775
776 $image_html = wp_kses_post( Group_Control_Image_Size::get_attachment_image_html( $settings, 'thumbnail', 'image' ) );
777
778 if ( ! empty( $settings['link']['url'] ) ) {
779 $image_html = '<a ' . $this->get_render_attribute_string( 'link' ) . ' tabindex="-1">' . $image_html . '</a>';
780 }
781
782 $html .= '<figure class="elementor-image-box-img">' . $image_html . '</figure>';
783 }
784
785 if ( $has_content ) {
786 $html .= '<div class="elementor-image-box-content">';
787
788 if ( ! Utils::is_empty( $title_text ) ) {
789 $title_html = $title_text;
790 $this->add_render_attribute( 'title_text', 'class', 'elementor-image-box-title' );
791
792 $this->add_inline_editing_attributes( 'title_text', 'none' );
793
794 if ( ! empty( $settings['link']['url'] ) ) {
795 $title_html = '<a ' . $this->get_render_attribute_string( 'link' ) . '>' . $title_text . '</a>';
796 }
797
798 $html .= sprintf( '<%1$s %2$s>%3$s</%1$s>', Utils::validate_html_tag( $settings['title_size'] ), $this->get_render_attribute_string( 'title_text' ), $title_html );
799 }
800
801 if ( ! Utils::is_empty( $description_text ) ) {
802 $this->add_render_attribute( 'description_text', 'class', 'elementor-image-box-description' );
803
804 $this->add_inline_editing_attributes( 'description_text' );
805
806 $html .= sprintf( '<p %1$s>%2$s</p>', $this->get_render_attribute_string( 'description_text' ), $description_text );
807 }
808
809 $html .= '</div>';
810 }
811
812 $html .= '</div>';
813
814 Utils::print_unescaped_internal_string( $html );
815 }
816
817 /**
818 * Render image box widget output in the editor.
819 *
820 * Written as a Backbone JavaScript template and used to generate the live preview.
821 *
822 * @since 2.9.0
823 * @access protected
824 */
825 protected function content_template() {
826 ?>
827 <#
828 const titleText = elementor.helpers.sanitize( settings.title_text, { ALLOW_DATA_ATTR: false } )
829 const descriptionText = elementor.helpers.sanitize( settings.description_text, { ALLOW_DATA_ATTR: false } )
830
831 var hasImage = !! settings.image.url;
832 var hasContent = !! ( titleText || descriptionText );
833
834 if ( ! hasImage && ! hasContent ) {
835 return;
836 }
837
838 var html = '<div class="elementor-image-box-wrapper">';
839
840 if ( hasImage ) {
841 var image = {
842 id: settings.image.id,
843 url: settings.image.url,
844 size: settings.thumbnail_size,
845 dimension: settings.thumbnail_custom_dimension,
846 model: view.getEditModel()
847 };
848
849 var image_url = elementor.imagesManager.getImageUrl( image );
850
851 var imageHtml = '<img src="' + _.escape( image_url ) + '" class="elementor-animation-' + _.escape( settings.hover_animation ) + '" />';
852
853 if ( settings.link?.url ) {
854 imageHtml = '<a href="' + elementor.helpers.sanitizeUrl( settings.link?.url ) + '" tabindex="-1">' + imageHtml + '</a>';
855 }
856
857 html += '<figure class="elementor-image-box-img">' + imageHtml + '</figure>';
858 }
859
860 if ( hasContent ) {
861 html += '<div class="elementor-image-box-content">';
862
863 if ( titleText ) {
864 var titleSizeTag = elementor.helpers.validateHTMLTag( settings.title_size );
865
866 if ( settings.link?.url ) {
867 title_html = '<a href="' + elementor.helpers.sanitizeUrl( settings.link?.url ) + '">' + titleText + '</a>';
868 }
869
870 view.addRenderAttribute( 'title_text', 'class', 'elementor-image-box-title' );
871
872 view.addInlineEditingAttributes( 'title_text', 'none' );
873
874 html += '<' + titleSizeTag + ' ' + view.getRenderAttributeString( 'title_text' ) + '>' + titleText + '</' + titleSizeTag + '>';
875 }
876
877 if ( descriptionText ) {
878 view.addRenderAttribute( 'description_text', 'class', 'elementor-image-box-description' );
879
880 view.addInlineEditingAttributes( 'description_text' );
881
882 html += '<p ' + view.getRenderAttributeString( 'description_text' ) + '>' + descriptionText + '</p>';
883 }
884
885 html += '</div>';
886 }
887
888 html += '</div>';
889
890 print( html );
891 #>
892 <?php
893 }
894 }
895