PluginProbe
Elementor Website Builder – more than just a page builder / 3.20.0-dev2
Elementor Website Builder – more than just a page builder v3.20.0-dev2
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.20.0-dev2, at includes/widgets/image-box.php

731 lines 17.1 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 /**
77 * Register image box 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',
87 [
88 'label' => esc_html__( 'Image Box', 'elementor' ),
89 ]
90 );
91
92 $this->add_control(
93 'image',
94 [
95 'label' => esc_html__( 'Choose Image', 'elementor' ),
96 'type' => Controls_Manager::MEDIA,
97 'dynamic' => [
98 'active' => true,
99 ],
100 'default' => [
101 'url' => Utils::get_placeholder_image_src(),
102 ],
103 ]
104 );
105
106 $this->add_group_control(
107 Group_Control_Image_Size::get_type(),
108 [
109 'name' => 'thumbnail', // Usage: `{name}_size` and `{name}_custom_dimension`, in this case `thumbnail_size` and `thumbnail_custom_dimension`.
110 'default' => 'full',
111 'condition' => [
112 'image[url]!' => '',
113 ],
114 ]
115 );
116
117 $this->add_control(
118 'title_text',
119 [
120 'label' => esc_html__( 'Title', 'elementor' ),
121 'type' => Controls_Manager::TEXT,
122 'dynamic' => [
123 'active' => true,
124 ],
125 'default' => esc_html__( 'This is the heading', 'elementor' ),
126 'placeholder' => esc_html__( 'Enter your title', 'elementor' ),
127 'label_block' => true,
128 ]
129 );
130
131 $this->add_control(
132 'description_text',
133 [
134 'label' => esc_html__( 'Description', 'elementor' ),
135 'type' => Controls_Manager::TEXTAREA,
136 'dynamic' => [
137 'active' => true,
138 ],
139 'default' => esc_html__( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.', 'elementor' ),
140 'placeholder' => esc_html__( 'Enter your description', 'elementor' ),
141 'rows' => 10,
142 ]
143 );
144
145 $this->add_control(
146 'link',
147 [
148 'label' => esc_html__( 'Link', 'elementor' ),
149 'type' => Controls_Manager::URL,
150 'dynamic' => [
151 'active' => true,
152 ],
153 'separator' => 'before',
154 ]
155 );
156
157 $this->add_control(
158 'title_size',
159 [
160 'label' => esc_html__( 'Title HTML Tag', 'elementor' ),
161 'type' => Controls_Manager::SELECT,
162 'options' => [
163 'h1' => 'H1',
164 'h2' => 'H2',
165 'h3' => 'H3',
166 'h4' => 'H4',
167 'h5' => 'H5',
168 'h6' => 'H6',
169 'div' => 'div',
170 'span' => 'span',
171 'p' => 'p',
172 ],
173 'default' => 'h3',
174 ]
175 );
176
177 $this->end_controls_section();
178
179 $this->start_controls_section(
180 'section_style_box',
181 [
182 'label' => esc_html__( 'Box', 'elementor' ),
183 'tab' => Controls_Manager::TAB_STYLE,
184 ]
185 );
186
187 $this->add_responsive_control(
188 'position',
189 [
190 'label' => esc_html__( 'Image Position', 'elementor' ),
191 'type' => Controls_Manager::CHOOSE,
192 'default' => 'top',
193 'options' => [
194 'left' => [
195 'title' => esc_html__( 'Left', 'elementor' ),
196 'icon' => 'eicon-h-align-left',
197 ],
198 'top' => [
199 'title' => esc_html__( 'Top', 'elementor' ),
200 'icon' => 'eicon-v-align-top',
201 ],
202 'right' => [
203 'title' => esc_html__( 'Right', 'elementor' ),
204 'icon' => 'eicon-h-align-right',
205 ],
206 ],
207 'prefix_class' => 'elementor-position-',
208 'toggle' => false,
209 'condition' => [
210 'image[url]!' => '',
211 ],
212 ]
213 );
214
215 $this->add_responsive_control(
216 'content_vertical_alignment',
217 [
218 'label' => esc_html__( 'Vertical Alignment', 'elementor' ),
219 'type' => Controls_Manager::CHOOSE,
220 'options' => [
221 'top' => [
222 'title' => esc_html__( 'Top', 'elementor' ),
223 'icon' => 'eicon-v-align-top',
224 ],
225 'middle' => [
226 'title' => esc_html__( 'Middle', 'elementor' ),
227 'icon' => 'eicon-v-align-middle',
228 ],
229 'bottom' => [
230 'title' => esc_html__( 'Bottom', 'elementor' ),
231 'icon' => 'eicon-v-align-bottom',
232 ],
233 ],
234 'default' => 'top',
235 'toggle' => false,
236 'prefix_class' => 'elementor-vertical-align-',
237 'condition' => [
238 'position!' => 'top',
239 ],
240 ]
241 );
242
243 $this->add_responsive_control(
244 'text_align',
245 [
246 'label' => esc_html__( 'Alignment', 'elementor' ),
247 'type' => Controls_Manager::CHOOSE,
248 'options' => [
249 'left' => [
250 'title' => esc_html__( 'Left', 'elementor' ),
251 'icon' => 'eicon-text-align-left',
252 ],
253 'center' => [
254 'title' => esc_html__( 'Center', 'elementor' ),
255 'icon' => 'eicon-text-align-center',
256 ],
257 'right' => [
258 'title' => esc_html__( 'Right', 'elementor' ),
259 'icon' => 'eicon-text-align-right',
260 ],
261 'justify' => [
262 'title' => esc_html__( 'Justified', 'elementor' ),
263 'icon' => 'eicon-text-align-justify',
264 ],
265 ],
266 'selectors' => [
267 '{{WRAPPER}} .elementor-image-box-wrapper' => 'text-align: {{VALUE}};',
268 ],
269 'separator' => 'after',
270 ]
271 );
272
273 $this->add_responsive_control(
274 'image_space',
275 [
276 'label' => esc_html__( 'Image Spacing', 'elementor' ),
277 'type' => Controls_Manager::SLIDER,
278 'size_units' => [ 'px', '%', 'em', 'rem', 'vw', 'custom' ],
279 'default' => [
280 'size' => 15,
281 ],
282 'range' => [
283 'px' => [
284 'max' => 100,
285 ],
286 ],
287 'selectors' => [
288 '{{WRAPPER}}.elementor-position-right .elementor-image-box-img' => 'margin-left: {{SIZE}}{{UNIT}};',
289 '{{WRAPPER}}.elementor-position-left .elementor-image-box-img' => 'margin-right: {{SIZE}}{{UNIT}};',
290 '{{WRAPPER}}.elementor-position-top .elementor-image-box-img' => 'margin-bottom: {{SIZE}}{{UNIT}};',
291 '(mobile){{WRAPPER}} .elementor-image-box-img' => 'margin-bottom: {{SIZE}}{{UNIT}};',
292 ],
293 'condition' => [
294 'image[url]!' => '',
295 ],
296 ]
297 );
298
299 $this->add_responsive_control(
300 'title_bottom_space',
301 [
302 'label' => esc_html__( 'Content Spacing', 'elementor' ),
303 'type' => Controls_Manager::SLIDER,
304 'size_units' => [ 'px', 'em', 'rem', 'custom' ],
305 'range' => [
306 'px' => [
307 'max' => 100,
308 ],
309 'em' => [
310 'min' => 0,
311 'max' => 10,
312 ],
313 'rem' => [
314 'min' => 0,
315 'max' => 10,
316 ],
317 ],
318 'selectors' => [
319 '{{WRAPPER}} .elementor-image-box-title' => 'margin-bottom: {{SIZE}}{{UNIT}};',
320 ],
321 ]
322 );
323
324 $this->end_controls_section();
325
326 $this->start_controls_section(
327 'section_style_image',
328 [
329 'label' => esc_html__( 'Image', 'elementor' ),
330 'tab' => Controls_Manager::TAB_STYLE,
331 'condition' => [
332 'image[url]!' => '',
333 ],
334 ]
335 );
336
337 $this->add_responsive_control(
338 'image_size',
339 [
340 'label' => esc_html__( 'Width', 'elementor' ),
341 'type' => Controls_Manager::SLIDER,
342 'default' => [
343 'size' => 30,
344 'unit' => '%',
345 ],
346 'tablet_default' => [
347 'unit' => '%',
348 ],
349 'mobile_default' => [
350 'unit' => '%',
351 ],
352 'size_units' => [ 'px', '%', 'em', 'rem', 'vw', 'custom' ],
353 'range' => [
354 '%' => [
355 'min' => 5,
356 'max' => 100,
357 ],
358 ],
359 'selectors' => [
360 '{{WRAPPER}} .elementor-image-box-wrapper .elementor-image-box-img' => 'width: {{SIZE}}{{UNIT}};',
361 ],
362 ]
363 );
364
365 $this->add_group_control(
366 Group_Control_Border::get_type(),
367 [
368 'name' => 'image_border',
369 'selector' => '{{WRAPPER}} .elementor-image-box-img img',
370 'separator' => 'before',
371 ]
372 );
373
374 $this->add_responsive_control(
375 'image_border_radius',
376 [
377 'label' => esc_html__( 'Border Radius', 'elementor' ),
378 'type' => Controls_Manager::SLIDER,
379 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
380 'separator' => 'after',
381 'selectors' => [
382 '{{WRAPPER}} .elementor-image-box-img img' => 'border-radius: {{SIZE}}{{UNIT}};',
383 ],
384 ]
385 );
386
387 $this->start_controls_tabs( 'image_effects' );
388
389 $this->start_controls_tab(
390 'normal',
391 [
392 'label' => esc_html__( 'Normal', 'elementor' ),
393 ]
394 );
395
396 $this->add_group_control(
397 Group_Control_Css_Filter::get_type(),
398 [
399 'name' => 'css_filters',
400 'selector' => '{{WRAPPER}} .elementor-image-box-img img',
401 ]
402 );
403
404 $this->add_control(
405 'image_opacity',
406 [
407 'label' => esc_html__( 'Opacity', 'elementor' ),
408 'type' => Controls_Manager::SLIDER,
409 'range' => [
410 'px' => [
411 'max' => 1,
412 'min' => 0.10,
413 'step' => 0.01,
414 ],
415 ],
416 'selectors' => [
417 '{{WRAPPER}} .elementor-image-box-img img' => 'opacity: {{SIZE}};',
418 ],
419 ]
420 );
421
422 $this->end_controls_tab();
423
424 $this->start_controls_tab(
425 'hover',
426 [
427 'label' => esc_html__( 'Hover', 'elementor' ),
428 ]
429 );
430
431 $this->add_group_control(
432 Group_Control_Css_Filter::get_type(),
433 [
434 'name' => 'css_filters_hover',
435 'selector' => '{{WRAPPER}}:hover .elementor-image-box-img img',
436 ]
437 );
438
439 $this->add_control(
440 'image_opacity_hover',
441 [
442 'label' => esc_html__( 'Opacity', 'elementor' ),
443 'type' => Controls_Manager::SLIDER,
444 'range' => [
445 'px' => [
446 'max' => 1,
447 'min' => 0.10,
448 'step' => 0.01,
449 ],
450 ],
451 'selectors' => [
452 '{{WRAPPER}}:hover .elementor-image-box-img img' => 'opacity: {{SIZE}};',
453 ],
454 ]
455 );
456
457 $this->add_control(
458 'background_hover_transition',
459 [
460 'label' => esc_html__( 'Transition Duration', 'elementor' ) . ' (s)',
461 'type' => Controls_Manager::SLIDER,
462 'default' => [
463 'size' => 0.3,
464 ],
465 'range' => [
466 'px' => [
467 'min' => 0,
468 'max' => 3,
469 'step' => 0.1,
470 ],
471 ],
472 'selectors' => [
473 '{{WRAPPER}} .elementor-image-box-img img' => 'transition-duration: {{SIZE}}s',
474 ],
475 ]
476 );
477
478 $this->add_control(
479 'hover_animation',
480 [
481 'label' => esc_html__( 'Hover Animation', 'elementor' ),
482 'type' => Controls_Manager::HOVER_ANIMATION,
483 ]
484 );
485
486 $this->end_controls_tab();
487
488 $this->end_controls_tabs();
489
490 $this->end_controls_section();
491
492 $this->start_controls_section(
493 'section_style_content',
494 [
495 'label' => esc_html__( 'Content', 'elementor' ),
496 'tab' => Controls_Manager::TAB_STYLE,
497 ]
498 );
499
500 $this->add_control(
501 'heading_title',
502 [
503 'label' => esc_html__( 'Title', 'elementor' ),
504 'type' => Controls_Manager::HEADING,
505 'separator' => 'before',
506 ]
507 );
508
509 $this->add_control(
510 'title_color',
511 [
512 'label' => esc_html__( 'Color', 'elementor' ),
513 'type' => Controls_Manager::COLOR,
514 'default' => '',
515 'selectors' => [
516 '{{WRAPPER}} .elementor-image-box-title' => 'color: {{VALUE}};',
517 ],
518 'global' => [
519 'default' => Global_Colors::COLOR_PRIMARY,
520 ],
521 ]
522 );
523
524 $this->add_group_control(
525 Group_Control_Typography::get_type(),
526 [
527 'name' => 'title_typography',
528 'selector' => '{{WRAPPER}} .elementor-image-box-title',
529 'global' => [
530 'default' => Global_Typography::TYPOGRAPHY_PRIMARY,
531 ],
532 ]
533 );
534
535 $this->add_group_control(
536 Group_Control_Text_Stroke::get_type(),
537 [
538 'name' => 'title_stroke',
539 'selector' => '{{WRAPPER}} .elementor-image-box-title',
540 ]
541 );
542
543 $this->add_group_control(
544 Group_Control_Text_Shadow::get_type(),
545 [
546 'name' => 'title_shadow',
547 'selector' => '{{WRAPPER}} .elementor-image-box-title',
548 ]
549 );
550
551 $this->add_control(
552 'heading_description',
553 [
554 'label' => esc_html__( 'Description', 'elementor' ),
555 'type' => Controls_Manager::HEADING,
556 'separator' => 'before',
557 ]
558 );
559
560 $this->add_control(
561 'description_color',
562 [
563 'label' => esc_html__( 'Color', 'elementor' ),
564 'type' => Controls_Manager::COLOR,
565 'default' => '',
566 'selectors' => [
567 '{{WRAPPER}} .elementor-image-box-description' => 'color: {{VALUE}};',
568 ],
569 'global' => [
570 'default' => Global_Colors::COLOR_TEXT,
571 ],
572 ]
573 );
574
575 $this->add_group_control(
576 Group_Control_Typography::get_type(),
577 [
578 'name' => 'description_typography',
579 'selector' => '{{WRAPPER}} .elementor-image-box-description',
580 'global' => [
581 'default' => Global_Typography::TYPOGRAPHY_TEXT,
582 ],
583 ]
584 );
585
586 $this->add_group_control(
587 Group_Control_Text_Shadow::get_type(),
588 [
589 'name' => 'description_shadow',
590 'selector' => '{{WRAPPER}} .elementor-image-box-description',
591 ]
592 );
593
594 $this->end_controls_section();
595 }
596
597 /**
598 * Render image box widget output on the frontend.
599 *
600 * Written in PHP and used to generate the final HTML.
601 *
602 * @since 1.0.0
603 * @access protected
604 */
605 protected function render() {
606 $settings = $this->get_settings_for_display();
607
608 $has_content = ! Utils::is_empty( $settings['title_text'] ) || ! Utils::is_empty( $settings['description_text'] );
609
610 $html = '<div class="elementor-image-box-wrapper">';
611
612 if ( ! empty( $settings['link']['url'] ) ) {
613 $this->add_link_attributes( 'link', $settings['link'] );
614 }
615
616 if ( ! empty( $settings['image']['url'] ) ) {
617
618 $image_html = wp_kses_post( Group_Control_Image_Size::get_attachment_image_html( $settings, 'thumbnail', 'image' ) );
619
620 if ( ! empty( $settings['link']['url'] ) ) {
621 $image_html = '<a ' . $this->get_render_attribute_string( 'link' ) . ' tabindex="-1">' . $image_html . '</a>';
622 }
623
624 $html .= '<figure class="elementor-image-box-img">' . $image_html . '</figure>';
625 }
626
627 if ( $has_content ) {
628 $html .= '<div class="elementor-image-box-content">';
629
630 if ( ! Utils::is_empty( $settings['title_text'] ) ) {
631 $this->add_render_attribute( 'title_text', 'class', 'elementor-image-box-title' );
632
633 $this->add_inline_editing_attributes( 'title_text', 'none' );
634
635 $title_html = $settings['title_text'];
636
637 if ( ! empty( $settings['link']['url'] ) ) {
638 $title_html = '<a ' . $this->get_render_attribute_string( 'link' ) . '>' . $title_html . '</a>';
639 }
640
641 $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 );
642 }
643
644 if ( ! Utils::is_empty( $settings['description_text'] ) ) {
645 $this->add_render_attribute( 'description_text', 'class', 'elementor-image-box-description' );
646
647 $this->add_inline_editing_attributes( 'description_text' );
648
649 $html .= sprintf( '<p %1$s>%2$s</p>', $this->get_render_attribute_string( 'description_text' ), $settings['description_text'] );
650 }
651
652 $html .= '</div>';
653 }
654
655 $html .= '</div>';
656
657 Utils::print_unescaped_internal_string( $html );
658 }
659
660 /**
661 * Render image box widget output in the editor.
662 *
663 * Written as a Backbone JavaScript template and used to generate the live preview.
664 *
665 * @since 2.9.0
666 * @access protected
667 */
668 protected function content_template() {
669 ?>
670 <#
671 var html = '<div class="elementor-image-box-wrapper">';
672
673 if ( settings.image.url ) {
674 var image = {
675 id: settings.image.id,
676 url: settings.image.url,
677 size: settings.thumbnail_size,
678 dimension: settings.thumbnail_custom_dimension,
679 model: view.getEditModel()
680 };
681
682 var image_url = elementor.imagesManager.getImageUrl( image );
683
684 var imageHtml = '<img src="' + _.escape( image_url ) + '" class="elementor-animation-' + settings.hover_animation + '" />';
685
686 if ( settings.link.url ) {
687 imageHtml = '<a href="' + _.escape( settings.link.url ) + '" tabindex="-1">' + imageHtml + '</a>';
688 }
689
690 html += '<figure class="elementor-image-box-img">' + imageHtml + '</figure>';
691 }
692
693 var hasContent = !! ( settings.title_text || settings.description_text );
694
695 if ( hasContent ) {
696 html += '<div class="elementor-image-box-content">';
697
698 if ( settings.title_text ) {
699 var title_html = settings.title_text,
700 titleSizeTag = elementor.helpers.validateHTMLTag( settings.title_size );
701
702 if ( settings.link.url ) {
703 title_html = '<a href="' + _.escape( settings.link.url ) + '">' + title_html + '</a>';
704 }
705
706 view.addRenderAttribute( 'title_text', 'class', 'elementor-image-box-title' );
707
708 view.addInlineEditingAttributes( 'title_text', 'none' );
709
710 html += '<' + titleSizeTag + ' ' + view.getRenderAttributeString( 'title_text' ) + '>' + title_html + '</' + titleSizeTag + '>';
711 }
712
713 if ( settings.description_text ) {
714 view.addRenderAttribute( 'description_text', 'class', 'elementor-image-box-description' );
715
716 view.addInlineEditingAttributes( 'description_text' );
717
718 html += '<p ' + view.getRenderAttributeString( 'description_text' ) + '>' + settings.description_text + '</p>';
719 }
720
721 html += '</div>';
722 }
723
724 html += '</div>';
725
726 print( html );
727 #>
728 <?php
729 }
730 }
731