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

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