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

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