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

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