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

707 lines 16.6 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', '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__( 'Description', '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 ]
142 );
143
144 $this->add_control(
145 'link',
146 [
147 'label' => esc_html__( 'Link', 'elementor' ),
148 'type' => Controls_Manager::URL,
149 'dynamic' => [
150 'active' => true,
151 ],
152 'placeholder' => esc_html__( 'https://your-link.com', 'elementor' ),
153 'separator' => 'before',
154 ]
155 );
156
157 $this->add_control(
158 'position',
159 [
160 'label' => esc_html__( 'Image Position', 'elementor' ),
161 'type' => Controls_Manager::CHOOSE,
162 'default' => 'top',
163 'options' => [
164 'left' => [
165 'title' => esc_html__( 'Left', 'elementor' ),
166 'icon' => 'eicon-h-align-left',
167 ],
168 'top' => [
169 'title' => esc_html__( 'Top', 'elementor' ),
170 'icon' => 'eicon-v-align-top',
171 ],
172 'right' => [
173 'title' => esc_html__( 'Right', 'elementor' ),
174 'icon' => 'eicon-h-align-right',
175 ],
176 ],
177 'prefix_class' => 'elementor-position-',
178 'toggle' => false,
179 ]
180 );
181
182 $this->add_control(
183 'title_size',
184 [
185 'label' => esc_html__( 'Title HTML Tag', 'elementor' ),
186 'type' => Controls_Manager::SELECT,
187 'options' => [
188 'h1' => 'H1',
189 'h2' => 'H2',
190 'h3' => 'H3',
191 'h4' => 'H4',
192 'h5' => 'H5',
193 'h6' => 'H6',
194 'div' => 'div',
195 'span' => 'span',
196 'p' => 'p',
197 ],
198 'default' => 'h3',
199 ]
200 );
201
202 $this->add_control(
203 'view',
204 [
205 'label' => esc_html__( 'View', 'elementor' ),
206 'type' => Controls_Manager::HIDDEN,
207 'default' => 'traditional',
208 ]
209 );
210
211 $this->end_controls_section();
212
213 $this->start_controls_section(
214 'section_style_image',
215 [
216 'label' => esc_html__( 'Image', 'elementor' ),
217 'tab' => Controls_Manager::TAB_STYLE,
218 ]
219 );
220
221 $this->add_responsive_control(
222 'image_space',
223 [
224 'label' => esc_html__( 'Spacing', 'elementor' ),
225 'type' => Controls_Manager::SLIDER,
226 'size_units' => [ 'px', '%', 'em', 'rem', 'vw', 'custom' ],
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', 'rem', 'custom' ],
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::CHOOSE,
439 'options' => [
440 'top' => [
441 'title' => esc_html__( 'Top', 'elementor' ),
442 'icon' => 'eicon-v-align-top',
443 ],
444 'middle' => [
445 'title' => esc_html__( 'Middle', 'elementor' ),
446 'icon' => 'eicon-v-align-middle',
447 ],
448 'bottom' => [
449 'title' => esc_html__( 'Bottom', 'elementor' ),
450 'icon' => 'eicon-v-align-bottom',
451 ],
452 ],
453 'default' => 'top',
454 'toggle' => false,
455 'prefix_class' => 'elementor-vertical-align-',
456 ]
457 );
458
459 $this->add_control(
460 'heading_title',
461 [
462 'label' => esc_html__( 'Title', 'elementor' ),
463 'type' => Controls_Manager::HEADING,
464 'separator' => 'before',
465 ]
466 );
467
468 $this->add_responsive_control(
469 'title_bottom_space',
470 [
471 'label' => esc_html__( 'Spacing', 'elementor' ),
472 'type' => Controls_Manager::SLIDER,
473 'range' => [
474 'px' => [
475 'min' => 0,
476 'max' => 100,
477 ],
478 ],
479 'selectors' => [
480 '{{WRAPPER}} .elementor-image-box-title' => 'margin-bottom: {{SIZE}}{{UNIT}};',
481 ],
482 ]
483 );
484
485 $this->add_control(
486 'title_color',
487 [
488 'label' => esc_html__( 'Color', 'elementor' ),
489 'type' => Controls_Manager::COLOR,
490 'default' => '',
491 'selectors' => [
492 '{{WRAPPER}} .elementor-image-box-title' => 'color: {{VALUE}};',
493 ],
494 'global' => [
495 'default' => Global_Colors::COLOR_PRIMARY,
496 ],
497 ]
498 );
499
500 $this->add_group_control(
501 Group_Control_Typography::get_type(),
502 [
503 'name' => 'title_typography',
504 'selector' => '{{WRAPPER}} .elementor-image-box-title',
505 'global' => [
506 'default' => Global_Typography::TYPOGRAPHY_PRIMARY,
507 ],
508 ]
509 );
510
511 $this->add_group_control(
512 Group_Control_Text_Stroke::get_type(),
513 [
514 'name' => 'title_stroke',
515 'selector' => '{{WRAPPER}} .elementor-image-box-title',
516 ]
517 );
518
519 $this->add_group_control(
520 Group_Control_Text_Shadow::get_type(),
521 [
522 'name' => 'title_shadow',
523 'selector' => '{{WRAPPER}} .elementor-image-box-title',
524 ]
525 );
526
527 $this->add_control(
528 'heading_description',
529 [
530 'label' => esc_html__( 'Description', 'elementor' ),
531 'type' => Controls_Manager::HEADING,
532 'separator' => 'before',
533 ]
534 );
535
536 $this->add_control(
537 'description_color',
538 [
539 'label' => esc_html__( 'Color', 'elementor' ),
540 'type' => Controls_Manager::COLOR,
541 'default' => '',
542 'selectors' => [
543 '{{WRAPPER}} .elementor-image-box-description' => 'color: {{VALUE}};',
544 ],
545 'global' => [
546 'default' => Global_Colors::COLOR_TEXT,
547 ],
548 ]
549 );
550
551 $this->add_group_control(
552 Group_Control_Typography::get_type(),
553 [
554 'name' => 'description_typography',
555 'selector' => '{{WRAPPER}} .elementor-image-box-description',
556 'global' => [
557 'default' => Global_Typography::TYPOGRAPHY_TEXT,
558 ],
559 ]
560 );
561
562 $this->add_group_control(
563 Group_Control_Text_Shadow::get_type(),
564 [
565 'name' => 'description_shadow',
566 'selector' => '{{WRAPPER}} .elementor-image-box-description',
567 ]
568 );
569
570 $this->end_controls_section();
571 }
572
573 /**
574 * Render image box widget output on the frontend.
575 *
576 * Written in PHP and used to generate the final HTML.
577 *
578 * @since 1.0.0
579 * @access protected
580 */
581 protected function render() {
582 $settings = $this->get_settings_for_display();
583
584 $has_content = ! Utils::is_empty( $settings['title_text'] ) || ! Utils::is_empty( $settings['description_text'] );
585
586 $html = '<div class="elementor-image-box-wrapper">';
587
588 if ( ! empty( $settings['link']['url'] ) ) {
589 $this->add_link_attributes( 'link', $settings['link'] );
590 }
591
592 if ( ! empty( $settings['image']['url'] ) ) {
593
594 $image_html = wp_kses_post( Group_Control_Image_Size::get_attachment_image_html( $settings, 'thumbnail', 'image' ) );
595
596 if ( ! empty( $settings['link']['url'] ) ) {
597 $image_html = '<a ' . $this->get_render_attribute_string( 'link' ) . '>' . $image_html . '</a>';
598 }
599
600 $html .= '<figure class="elementor-image-box-img">' . $image_html . '</figure>';
601 }
602
603 if ( $has_content ) {
604 $html .= '<div class="elementor-image-box-content">';
605
606 if ( ! Utils::is_empty( $settings['title_text'] ) ) {
607 $this->add_render_attribute( 'title_text', 'class', 'elementor-image-box-title' );
608
609 $this->add_inline_editing_attributes( 'title_text', 'none' );
610
611 $title_html = $settings['title_text'];
612
613 if ( ! empty( $settings['link']['url'] ) ) {
614 $title_html = '<a ' . $this->get_render_attribute_string( 'link' ) . '>' . $title_html . '</a>';
615 }
616
617 $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 );
618 }
619
620 if ( ! Utils::is_empty( $settings['description_text'] ) ) {
621 $this->add_render_attribute( 'description_text', 'class', 'elementor-image-box-description' );
622
623 $this->add_inline_editing_attributes( 'description_text' );
624
625 $html .= sprintf( '<p %1$s>%2$s</p>', $this->get_render_attribute_string( 'description_text' ), $settings['description_text'] );
626 }
627
628 $html .= '</div>';
629 }
630
631 $html .= '</div>';
632
633 Utils::print_unescaped_internal_string( $html );
634 }
635
636 /**
637 * Render image box widget output in the editor.
638 *
639 * Written as a Backbone JavaScript template and used to generate the live preview.
640 *
641 * @since 2.9.0
642 * @access protected
643 */
644 protected function content_template() {
645 ?>
646 <#
647 var html = '<div class="elementor-image-box-wrapper">';
648
649 if ( settings.image.url ) {
650 var image = {
651 id: settings.image.id,
652 url: settings.image.url,
653 size: settings.thumbnail_size,
654 dimension: settings.thumbnail_custom_dimension,
655 model: view.getEditModel()
656 };
657
658 var image_url = elementor.imagesManager.getImageUrl( image );
659
660 var imageHtml = '<img src="' + image_url + '" class="elementor-animation-' + settings.hover_animation + '" />';
661
662 if ( settings.link.url ) {
663 imageHtml = '<a href="' + settings.link.url + '">' + imageHtml + '</a>';
664 }
665
666 html += '<figure class="elementor-image-box-img">' + imageHtml + '</figure>';
667 }
668
669 var hasContent = !! ( settings.title_text || settings.description_text );
670
671 if ( hasContent ) {
672 html += '<div class="elementor-image-box-content">';
673
674 if ( settings.title_text ) {
675 var title_html = settings.title_text,
676 titleSizeTag = elementor.helpers.validateHTMLTag( settings.title_size );
677
678 if ( settings.link.url ) {
679 title_html = '<a href="' + settings.link.url + '">' + title_html + '</a>';
680 }
681
682 view.addRenderAttribute( 'title_text', 'class', 'elementor-image-box-title' );
683
684 view.addInlineEditingAttributes( 'title_text', 'none' );
685
686 html += '<' + titleSizeTag + ' ' + view.getRenderAttributeString( 'title_text' ) + '>' + title_html + '</' + titleSizeTag + '>';
687 }
688
689 if ( settings.description_text ) {
690 view.addRenderAttribute( 'description_text', 'class', 'elementor-image-box-description' );
691
692 view.addInlineEditingAttributes( 'description_text' );
693
694 html += '<p ' + view.getRenderAttributeString( 'description_text' ) + '>' + settings.description_text + '</p>';
695 }
696
697 html += '</div>';
698 }
699
700 html += '</div>';
701
702 print( html );
703 #>
704 <?php
705 }
706 }
707