PluginProbe
Elementor Website Builder – more than just a page builder / 3.23.0-beta5
Elementor Website Builder – more than just a page builder v3.23.0-beta5
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.23.0-beta5, at includes/widgets/alert.php

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