PluginProbe
Elementor Website Builder – more than just a page builder / 3.25.8
Elementor Website Builder – more than just a page builder v3.25.8
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 / alert.php

alert.php in Elementor Website Builder – more than just a page builder 3.25.8, at includes/widgets/alert.php

572 lines 13.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 use Elementor\Core\Kits\Documents\Tabs\Global_Typography;
5 use Elementor\Icons_Manager;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit; // Exit if accessed directly.
9 }
10
11 /**
12 * Elementor alert widget.
13 *
14 * Elementor widget that displays a collapsible display of content in an toggle
15 * style, allowing the user to open multiple items.
16 *
17 * @since 1.0.0
18 */
19 class Widget_Alert extends Widget_Base {
20
21 /**
22 * Get widget name.
23 *
24 * Retrieve alert widget name.
25 *
26 * @since 1.0.0
27 * @access public
28 *
29 * @return string Widget name.
30 */
31 public function get_name() {
32 return 'alert';
33 }
34
35 /**
36 * Get widget title.
37 *
38 * Retrieve alert widget title.
39 *
40 * @since 1.0.0
41 * @access public
42 *
43 * @return string Widget title.
44 */
45 public function get_title() {
46 return esc_html__( 'Alert', 'elementor' );
47 }
48
49 /**
50 * Get widget icon.
51 *
52 * Retrieve alert widget icon.
53 *
54 * @since 1.0.0
55 * @access public
56 *
57 * @return string Widget icon.
58 */
59 public function get_icon() {
60 return 'eicon-alert';
61 }
62
63 /**
64 * Get widget keywords.
65 *
66 * Retrieve the list of keywords the widget belongs to.
67 *
68 * @since 2.1.0
69 * @access public
70 *
71 * @return array Widget keywords.
72 */
73 public function get_keywords() {
74 return [ 'alert', 'notice', 'message' ];
75 }
76
77 protected function is_dynamic_content(): bool {
78 return false;
79 }
80
81 /**
82 * Get style dependencies.
83 *
84 * Retrieve the list of style dependencies the widget requires.
85 *
86 * @since 3.24.0
87 * @access public
88 *
89 * @return array Widget style dependencies.
90 */
91 public function get_style_depends(): array {
92 return [ 'widget-alert' ];
93 }
94
95 /**
96 * Register alert widget controls.
97 *
98 * Adds different input fields to allow the user to change and customize the widget settings.
99 *
100 * @since 3.1.0
101 * @access protected
102 */
103 protected function register_controls() {
104 $this->start_controls_section(
105 'section_alert',
106 [
107 'label' => esc_html__( 'Alert', 'elementor' ),
108 ]
109 );
110
111 $this->add_control(
112 'alert_type',
113 [
114 'label' => esc_html__( 'Type', 'elementor' ),
115 'type' => Controls_Manager::SELECT,
116 'default' => 'info',
117 'options' => [
118 'info' => esc_html__( 'Info', 'elementor' ),
119 'success' => esc_html__( 'Success', 'elementor' ),
120 'warning' => esc_html__( 'Warning', 'elementor' ),
121 'danger' => esc_html__( 'Danger', 'elementor' ),
122 ],
123 'prefix_class' => 'elementor-alert-',
124 ]
125 );
126
127 $this->add_control(
128 'alert_title',
129 [
130 'label' => esc_html__( 'Title', 'elementor' ),
131 'type' => Controls_Manager::TEXT,
132 'placeholder' => esc_html__( 'Enter your title', 'elementor' ),
133 'default' => esc_html__( 'This is an Alert', 'elementor' ),
134 'label_block' => true,
135 'dynamic' => [
136 'active' => true,
137 ],
138 ]
139 );
140
141 $this->add_control(
142 'alert_description',
143 [
144 'label' => esc_html__( 'Content', 'elementor' ),
145 'type' => Controls_Manager::TEXTAREA,
146 'placeholder' => esc_html__( 'Enter your description', 'elementor' ),
147 'default' => esc_html__( 'I am a description. Click the edit button to change this text.', 'elementor' ),
148 'dynamic' => [
149 'active' => true,
150 ],
151 ]
152 );
153
154 $this->add_control(
155 'show_dismiss',
156 [
157 'label' => esc_html__( 'Dismiss Icon', 'elementor' ),
158 'type' => Controls_Manager::SWITCHER,
159 'label_on' => esc_html__( 'Show', 'elementor' ),
160 'label_off' => esc_html__( 'Hide', 'elementor' ),
161 'return_value' => 'show',
162 'default' => 'show',
163 ]
164 );
165
166 $this->add_control(
167 'dismiss_icon',
168 [
169 'label' => esc_html__( 'Icon', 'elementor' ),
170 'type' => Controls_Manager::ICONS,
171 'fa4compatibility' => 'icon',
172 'skin' => 'inline',
173 'label_block' => false,
174 'render_type' => 'template',
175 'skin_settings' => [
176 'inline' => [
177 'none' => [
178 'label' => 'Default',
179 'icon' => 'eicon-close',
180 ],
181 'icon' => [
182 'icon' => 'eicon-star',
183 ],
184 ],
185 ],
186 'recommended' => [
187 'fa-regular' => [
188 'times-circle',
189 ],
190 'fa-solid' => [
191 'times',
192 'times-circle',
193 ],
194 ],
195 'condition' => [
196 'show_dismiss' => 'show',
197 ],
198 ]
199 );
200
201 $this->end_controls_section();
202
203 $this->start_controls_section(
204 'section_type',
205 [
206 'label' => esc_html__( 'Alert', 'elementor' ),
207 'tab' => Controls_Manager::TAB_STYLE,
208 ]
209 );
210
211 $this->add_control(
212 'background',
213 [
214 'label' => esc_html__( 'Background Color', 'elementor' ),
215 'type' => Controls_Manager::COLOR,
216 'selectors' => [
217 '{{WRAPPER}} .elementor-alert' => 'background-color: {{VALUE}};',
218 ],
219 ]
220 );
221
222 $this->add_control(
223 'border_color',
224 [
225 'label' => esc_html__( 'Border Color', 'elementor' ),
226 'type' => Controls_Manager::COLOR,
227 'selectors' => [
228 '{{WRAPPER}} .elementor-alert' => 'border-color: {{VALUE}};',
229 ],
230 ]
231 );
232
233 $this->add_control(
234 'border_left-width',
235 [
236 'label' => esc_html__( 'Left Border Width', 'elementor' ),
237 'type' => Controls_Manager::SLIDER,
238 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
239 'range' => [
240 'px' => [
241 'max' => 100,
242 ],
243 'em' => [
244 'max' => 10,
245 ],
246 ],
247 'selectors' => [
248 '{{WRAPPER}} .elementor-alert' => 'border-left-width: {{SIZE}}{{UNIT}};',
249 ],
250 ]
251 );
252
253 $this->end_controls_section();
254
255 $this->start_controls_section(
256 'section_title',
257 [
258 'label' => esc_html__( 'Title', 'elementor' ),
259 'tab' => Controls_Manager::TAB_STYLE,
260 ]
261 );
262
263 $this->add_control(
264 'title_color',
265 [
266 'label' => esc_html__( 'Text Color', 'elementor' ),
267 'type' => Controls_Manager::COLOR,
268 'selectors' => [
269 '{{WRAPPER}} .elementor-alert-title' => 'color: {{VALUE}};',
270 ],
271 ]
272 );
273
274 $this->add_group_control(
275 Group_Control_Typography::get_type(),
276 [
277 'name' => 'alert_title',
278 'selector' => '{{WRAPPER}} .elementor-alert-title',
279 'global' => [
280 'default' => Global_Typography::TYPOGRAPHY_PRIMARY,
281 ],
282 ]
283 );
284
285 $this->add_group_control(
286 Group_Control_Text_Shadow::get_type(),
287 [
288 'name' => 'title_shadow',
289 'selector' => '{{WRAPPER}} .elementor-alert-title',
290 ]
291 );
292
293 $this->end_controls_section();
294
295 $this->start_controls_section(
296 'section_description',
297 [
298 'label' => esc_html__( 'Description', 'elementor' ),
299 'tab' => Controls_Manager::TAB_STYLE,
300 ]
301 );
302
303 $this->add_control(
304 'description_color',
305 [
306 'label' => esc_html__( 'Text Color', 'elementor' ),
307 'type' => Controls_Manager::COLOR,
308 'selectors' => [
309 '{{WRAPPER}} .elementor-alert-description' => 'color: {{VALUE}};',
310 ],
311 ]
312 );
313
314 $this->add_group_control(
315 Group_Control_Typography::get_type(),
316 [
317 'name' => 'alert_description',
318 'selector' => '{{WRAPPER}} .elementor-alert-description',
319 'global' => [
320 'default' => Global_Typography::TYPOGRAPHY_TEXT,
321 ],
322 ]
323 );
324
325 $this->add_group_control(
326 Group_Control_Text_Shadow::get_type(),
327 [
328 'name' => 'description_shadow',
329 'selector' => '{{WRAPPER}} .elementor-alert-description',
330 ]
331 );
332
333 $this->end_controls_section();
334
335 $this->start_controls_section(
336 'section_dismiss_icon',
337 [
338 'label' => esc_html__( 'Dismiss Icon', 'elementor' ),
339 'tab' => Controls_Manager::TAB_STYLE,
340 'condition' => [
341 'show_dismiss' => 'show',
342 ],
343 ]
344 );
345
346 $this->add_responsive_control(
347 'dismiss_icon_size',
348 [
349 'label' => esc_html__( 'Size', 'elementor' ),
350 'type' => Controls_Manager::SLIDER,
351 'size_units' => [ 'px', 'em', 'rem', 'custom' ],
352 'range' => [
353 'px' => [
354 'max' => 100,
355 ],
356 'em' => [
357 'max' => 10,
358 ],
359 'rem' => [
360 'max' => 10,
361 ],
362 ],
363 'selectors' => [
364 '{{WRAPPER}}' => '--dismiss-icon-size: {{SIZE}}{{UNIT}};',
365 ],
366 ]
367 );
368
369 $this->add_responsive_control(
370 'dismiss_icon_vertical_position',
371 [
372 'label' => esc_html__( 'Vertical Position', 'elementor' ),
373 'type' => Controls_Manager::SLIDER,
374 'range' => [
375 'px' => [
376 'min' => -100,
377 'max' => 100,
378 ],
379 ],
380 'size_units' => [ 'px', '%', 'em', 'rem', 'vh', 'custom' ],
381 'selectors' => [
382 '{{WRAPPER}}' => '--dismiss-icon-vertical-position: {{SIZE}}{{UNIT}};',
383 ],
384 ]
385 );
386
387 $this->add_responsive_control(
388 'dismiss_icon_horizontal_position',
389 [
390 'label' => esc_html__( 'Horizontal Position', 'elementor' ),
391 'type' => Controls_Manager::SLIDER,
392 'range' => [
393 'px' => [
394 'min' => -100,
395 'max' => 100,
396 ],
397 ],
398 'size_units' => [ 'px', '%', 'em', 'rem', 'vw', 'custom' ],
399 'selectors' => [
400 '{{WRAPPER}}' => '--dismiss-icon-horizontal-position: {{SIZE}}{{UNIT}};',
401 ],
402 ]
403 );
404
405 $this->start_controls_tabs( 'dismiss_icon_colors' );
406
407 $this->start_controls_tab( 'dismiss_icon_normal_colors', [
408 'label' => esc_html__( 'Normal', 'elementor' ),
409 ] );
410
411 $this->add_control(
412 'dismiss_icon_normal_color',
413 [
414 'label' => esc_html__( 'Color', 'elementor' ),
415 'type' => Controls_Manager::COLOR,
416 'selectors' => [
417 '{{WRAPPER}}' => '--dismiss-icon-normal-color: {{VALUE}};',
418 ],
419 ]
420 );
421
422 $this->end_controls_tab();
423
424 $this->start_controls_tab( 'dismiss_icon_hover_colors', [
425 'label' => esc_html__( 'Hover', 'elementor' ),
426 ] );
427
428 $this->add_control(
429 'dismiss_icon_hover_color',
430 [
431 'label' => esc_html__( 'Color', 'elementor' ),
432 'type' => Controls_Manager::COLOR,
433 'selectors' => [
434 '{{WRAPPER}}' => '--dismiss-icon-hover-color: {{VALUE}};',
435 ],
436 ]
437 );
438
439 $this->add_control(
440 'dismiss_icon_hover_transition_duration',
441 [
442 'label' => esc_html__( 'Transition Duration', 'elementor' ) . ' (s)',
443 'type' => Controls_Manager::SLIDER,
444 'range' => [
445 'px' => [
446 'min' => 0,
447 'max' => 3,
448 'step' => 0.1,
449 ],
450 ],
451 'selectors' => [
452 '{{WRAPPER}}' => '--dismiss-icon-hover-transition-duration: {{SIZE}}s',
453 ],
454 ]
455 );
456
457 $this->end_controls_tab();
458
459 $this->end_controls_tabs();
460
461 $this->end_controls_section();
462 }
463
464 /**
465 * Render alert widget output on the frontend.
466 *
467 * Written in PHP and used to generate the final HTML.
468 *
469 * @since 1.0.0
470 * @access protected
471 */
472 protected function render() {
473 $settings = $this->get_settings_for_display();
474
475 if ( Utils::is_empty( $settings['alert_title'] ) && Utils::is_empty( $settings['alert_description'] ) ) {
476 return;
477 }
478
479 $this->add_render_attribute( 'alert_wrapper', 'class', 'elementor-alert' );
480
481 $this->add_render_attribute( 'alert_wrapper', 'role', 'alert' );
482
483 $this->add_render_attribute( 'alert_title', 'class', 'elementor-alert-title' );
484
485 $this->add_render_attribute( 'alert_description', 'class', 'elementor-alert-description' );
486
487 $this->add_inline_editing_attributes( 'alert_title', 'none' );
488
489 $this->add_inline_editing_attributes( 'alert_description' );
490 ?>
491 <div <?php $this->print_render_attribute_string( 'alert_wrapper' ); ?>>
492
493 <?php if ( ! Utils::is_empty( $settings['alert_title'] ) ) : ?>
494 <span <?php $this->print_render_attribute_string( 'alert_title' ); ?>><?php $this->print_unescaped_setting( 'alert_title' ); ?></span>
495 <?php endif; ?>
496
497 <?php if ( ! Utils::is_empty( $settings['alert_description'] ) ) : ?>
498 <span <?php $this->print_render_attribute_string( 'alert_description' ); ?>><?php $this->print_unescaped_setting( 'alert_description' ); ?></span>
499 <?php endif; ?>
500
501 <?php if ( 'show' === $settings['show_dismiss'] ) : ?>
502 <button type="button" class="elementor-alert-dismiss">
503 <?php
504 if ( ! empty( $settings['dismiss_icon']['value'] ) ) {
505 Icons_Manager::render_icon( $settings['dismiss_icon'], [ 'aria-hidden' => 'true' ] );
506 } else { ?>
507 <span aria-hidden="true">&times;</span>
508 <?php } ?>
509 <span class="elementor-screen-only"><?php echo esc_html__( 'Dismiss this alert.', 'elementor' ); ?></span>
510 </button>
511 <?php endif; ?>
512
513 </div>
514 <?php
515 }
516
517 /**
518 * Render alert widget output in the editor.
519 *
520 * Written as a Backbone JavaScript template and used to generate the live preview.
521 *
522 * @since 2.9.0
523 * @access protected
524 */
525 protected function content_template() {
526 ?>
527 <#
528 if ( ! settings.alert_title && ! settings.alert_description ) {
529 return;
530 }
531
532 view.addRenderAttribute( 'alert_wrapper', 'class', 'elementor-alert' );
533
534 view.addRenderAttribute( 'alert_wrapper', 'role', 'alert' );
535
536 view.addRenderAttribute( 'alert_title', 'class', 'elementor-alert-title' );
537
538 view.addRenderAttribute( 'alert_description', 'class', 'elementor-alert-description' );
539
540 view.addInlineEditingAttributes( 'alert_title', 'none' );
541
542 view.addInlineEditingAttributes( 'alert_description' );
543
544 var iconHTML = elementor.helpers.renderIcon( view, settings.dismiss_icon, { 'aria-hidden': true }, 'i' , 'object' ),
545 migrated = elementor.helpers.isIconMigrated( settings, 'dismiss_icon' );
546 #>
547 <div {{{ view.getRenderAttributeString( 'alert_wrapper' ) }}}>
548
549 <# if ( settings.alert_title ) { #>
550 <span {{{ view.getRenderAttributeString( 'alert_title' ) }}}>{{{ settings.alert_title }}}</span>
551 <# } #>
552
553 <# if ( settings.alert_description ) { #>
554 <span {{{ view.getRenderAttributeString( 'alert_description' ) }}}>{{{ settings.alert_description }}}</span>
555 <# } #>
556
557 <# if ( 'show' === settings.show_dismiss ) { #>
558 <button type="button" class="elementor-alert-dismiss">
559 <# if ( iconHTML && iconHTML.rendered && ( ! settings.icon || migrated ) ) { #>
560 {{{ iconHTML.value }}}
561 <# } else { #>
562 <span aria-hidden="true">&times;</span>
563 <# } #>
564 <span class="elementor-screen-only"><?php echo esc_html__( 'Dismiss this alert.', 'elementor' ); ?></span>
565 </button>
566 <# } #>
567
568 </div>
569 <?php
570 }
571 }
572