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

694 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 'size_units' => [ 's', 'ms' ],
344 'default' => [
345 'unit' => 's',
346 'size' => 0.3,
347 ],
348 'selectors' => [
349 '{{WRAPPER}} .elementor-image-box-img img' => 'transition-duration: {{SIZE}}{{UNIT}}',
350 ],
351 ]
352 );
353
354 $this->end_controls_tab();
355
356 $this->start_controls_tab( 'hover',
357 [
358 'label' => esc_html__( 'Hover', 'elementor' ),
359 ]
360 );
361
362 $this->add_group_control(
363 Group_Control_Css_Filter::get_type(),
364 [
365 'name' => 'css_filters_hover',
366 'selector' => '{{WRAPPER}}:hover .elementor-image-box-img img',
367 ]
368 );
369
370 $this->add_control(
371 'image_opacity_hover',
372 [
373 'label' => esc_html__( 'Opacity', 'elementor' ),
374 'type' => Controls_Manager::SLIDER,
375 'range' => [
376 'px' => [
377 'max' => 1,
378 'min' => 0.10,
379 'step' => 0.01,
380 ],
381 ],
382 'selectors' => [
383 '{{WRAPPER}}:hover .elementor-image-box-img img' => 'opacity: {{SIZE}};',
384 ],
385 ]
386 );
387
388 $this->end_controls_tab();
389
390 $this->end_controls_tabs();
391
392 $this->end_controls_section();
393
394 $this->start_controls_section(
395 'section_style_content',
396 [
397 'label' => esc_html__( 'Content', 'elementor' ),
398 'tab' => Controls_Manager::TAB_STYLE,
399 ]
400 );
401
402 $this->add_responsive_control(
403 'text_align',
404 [
405 'label' => esc_html__( 'Alignment', 'elementor' ),
406 'type' => Controls_Manager::CHOOSE,
407 'options' => [
408 'left' => [
409 'title' => esc_html__( 'Left', 'elementor' ),
410 'icon' => 'eicon-text-align-left',
411 ],
412 'center' => [
413 'title' => esc_html__( 'Center', 'elementor' ),
414 'icon' => 'eicon-text-align-center',
415 ],
416 'right' => [
417 'title' => esc_html__( 'Right', 'elementor' ),
418 'icon' => 'eicon-text-align-right',
419 ],
420 'justify' => [
421 'title' => esc_html__( 'Justified', 'elementor' ),
422 'icon' => 'eicon-text-align-justify',
423 ],
424 ],
425 'selectors' => [
426 '{{WRAPPER}} .elementor-image-box-wrapper' => 'text-align: {{VALUE}};',
427 ],
428 ]
429 );
430
431 $this->add_control(
432 'content_vertical_alignment',
433 [
434 'label' => esc_html__( 'Vertical Alignment', 'elementor' ),
435 'type' => Controls_Manager::SELECT,
436 'options' => [
437 'top' => esc_html__( 'Top', 'elementor' ),
438 'middle' => esc_html__( 'Middle', 'elementor' ),
439 'bottom' => esc_html__( 'Bottom', 'elementor' ),
440 ],
441 'default' => 'top',
442 'prefix_class' => 'elementor-vertical-align-',
443 ]
444 );
445
446 $this->add_control(
447 'heading_title',
448 [
449 'label' => esc_html__( 'Title', 'elementor' ),
450 'type' => Controls_Manager::HEADING,
451 'separator' => 'before',
452 ]
453 );
454
455 $this->add_responsive_control(
456 'title_bottom_space',
457 [
458 'label' => esc_html__( 'Spacing', 'elementor' ),
459 'type' => Controls_Manager::SLIDER,
460 'range' => [
461 'px' => [
462 'min' => 0,
463 'max' => 100,
464 ],
465 ],
466 'selectors' => [
467 '{{WRAPPER}} .elementor-image-box-title' => 'margin-bottom: {{SIZE}}{{UNIT}};',
468 ],
469 ]
470 );
471
472 $this->add_control(
473 'title_color',
474 [
475 'label' => esc_html__( 'Color', 'elementor' ),
476 'type' => Controls_Manager::COLOR,
477 'default' => '',
478 'selectors' => [
479 '{{WRAPPER}} .elementor-image-box-title' => 'color: {{VALUE}};',
480 ],
481 'global' => [
482 'default' => Global_Colors::COLOR_PRIMARY,
483 ],
484 ]
485 );
486
487 $this->add_group_control(
488 Group_Control_Typography::get_type(),
489 [
490 'name' => 'title_typography',
491 'selector' => '{{WRAPPER}} .elementor-image-box-title',
492 'global' => [
493 'default' => Global_Typography::TYPOGRAPHY_PRIMARY,
494 ],
495 ]
496 );
497
498 $this->add_group_control(
499 Group_Control_Text_Stroke::get_type(),
500 [
501 'name' => 'title_stroke',
502 'selector' => '{{WRAPPER}} .elementor-image-box-title',
503 ]
504 );
505
506 $this->add_group_control(
507 Group_Control_Text_Shadow::get_type(),
508 [
509 'name' => 'title_shadow',
510 'selector' => '{{WRAPPER}} .elementor-image-box-title',
511 ]
512 );
513
514 $this->add_control(
515 'heading_description',
516 [
517 'label' => esc_html__( 'Description', 'elementor' ),
518 'type' => Controls_Manager::HEADING,
519 'separator' => 'before',
520 ]
521 );
522
523 $this->add_control(
524 'description_color',
525 [
526 'label' => esc_html__( 'Color', 'elementor' ),
527 'type' => Controls_Manager::COLOR,
528 'default' => '',
529 'selectors' => [
530 '{{WRAPPER}} .elementor-image-box-description' => 'color: {{VALUE}};',
531 ],
532 'global' => [
533 'default' => Global_Colors::COLOR_TEXT,
534 ],
535 ]
536 );
537
538 $this->add_group_control(
539 Group_Control_Typography::get_type(),
540 [
541 'name' => 'description_typography',
542 'selector' => '{{WRAPPER}} .elementor-image-box-description',
543 'global' => [
544 'default' => Global_Typography::TYPOGRAPHY_TEXT,
545 ],
546 ]
547 );
548
549 $this->add_group_control(
550 Group_Control_Text_Shadow::get_type(),
551 [
552 'name' => 'description_shadow',
553 'selector' => '{{WRAPPER}} .elementor-image-box-description',
554 ]
555 );
556
557 $this->end_controls_section();
558 }
559
560 /**
561 * Render image box widget output on the frontend.
562 *
563 * Written in PHP and used to generate the final HTML.
564 *
565 * @since 1.0.0
566 * @access protected
567 */
568 protected function render() {
569 $settings = $this->get_settings_for_display();
570
571 $has_content = ! Utils::is_empty( $settings['title_text'] ) || ! Utils::is_empty( $settings['description_text'] );
572
573 $html = '<div class="elementor-image-box-wrapper">';
574
575 if ( ! empty( $settings['link']['url'] ) ) {
576 $this->add_link_attributes( 'link', $settings['link'] );
577 }
578
579 if ( ! empty( $settings['image']['url'] ) ) {
580
581 $image_html = wp_kses_post( Group_Control_Image_Size::get_attachment_image_html( $settings, 'thumbnail', 'image' ) );
582
583 if ( ! empty( $settings['link']['url'] ) ) {
584 $image_html = '<a ' . $this->get_render_attribute_string( 'link' ) . '>' . $image_html . '</a>';
585 }
586
587 $html .= '<figure class="elementor-image-box-img">' . $image_html . '</figure>';
588 }
589
590 if ( $has_content ) {
591 $html .= '<div class="elementor-image-box-content">';
592
593 if ( ! Utils::is_empty( $settings['title_text'] ) ) {
594 $this->add_render_attribute( 'title_text', 'class', 'elementor-image-box-title' );
595
596 $this->add_inline_editing_attributes( 'title_text', 'none' );
597
598 $title_html = $settings['title_text'];
599
600 if ( ! empty( $settings['link']['url'] ) ) {
601 $title_html = '<a ' . $this->get_render_attribute_string( 'link' ) . '>' . $title_html . '</a>';
602 }
603
604 $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 );
605 }
606
607 if ( ! Utils::is_empty( $settings['description_text'] ) ) {
608 $this->add_render_attribute( 'description_text', 'class', 'elementor-image-box-description' );
609
610 $this->add_inline_editing_attributes( 'description_text' );
611
612 $html .= sprintf( '<p %1$s>%2$s</p>', $this->get_render_attribute_string( 'description_text' ), $settings['description_text'] );
613 }
614
615 $html .= '</div>';
616 }
617
618 $html .= '</div>';
619
620 Utils::print_unescaped_internal_string( $html );
621 }
622
623 /**
624 * Render image box widget output in the editor.
625 *
626 * Written as a Backbone JavaScript template and used to generate the live preview.
627 *
628 * @since 2.9.0
629 * @access protected
630 */
631 protected function content_template() {
632 ?>
633 <#
634 var html = '<div class="elementor-image-box-wrapper">';
635
636 if ( settings.image.url ) {
637 var image = {
638 id: settings.image.id,
639 url: settings.image.url,
640 size: settings.thumbnail_size,
641 dimension: settings.thumbnail_custom_dimension,
642 model: view.getEditModel()
643 };
644
645 var image_url = elementor.imagesManager.getImageUrl( image );
646
647 var imageHtml = '<img src="' + image_url + '" class="elementor-animation-' + settings.hover_animation + '" />';
648
649 if ( settings.link.url ) {
650 imageHtml = '<a href="' + settings.link.url + '">' + imageHtml + '</a>';
651 }
652
653 html += '<figure class="elementor-image-box-img">' + imageHtml + '</figure>';
654 }
655
656 var hasContent = !! ( settings.title_text || settings.description_text );
657
658 if ( hasContent ) {
659 html += '<div class="elementor-image-box-content">';
660
661 if ( settings.title_text ) {
662 var title_html = settings.title_text,
663 titleSizeTag = elementor.helpers.validateHTMLTag( settings.title_size );
664
665 if ( settings.link.url ) {
666 title_html = '<a href="' + settings.link.url + '">' + title_html + '</a>';
667 }
668
669 view.addRenderAttribute( 'title_text', 'class', 'elementor-image-box-title' );
670
671 view.addInlineEditingAttributes( 'title_text', 'none' );
672
673 html += '<' + titleSizeTag + ' ' + view.getRenderAttributeString( 'title_text' ) + '>' + title_html + '</' + titleSizeTag + '>';
674 }
675
676 if ( settings.description_text ) {
677 view.addRenderAttribute( 'description_text', 'class', 'elementor-image-box-description' );
678
679 view.addInlineEditingAttributes( 'description_text' );
680
681 html += '<p ' + view.getRenderAttributeString( 'description_text' ) + '>' + settings.description_text + '</p>';
682 }
683
684 html += '</div>';
685 }
686
687 html += '</div>';
688
689 print( html );
690 #>
691 <?php
692 }
693 }
694