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

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