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