PluginProbe
Elementor Website Builder – more than just a page builder / 3.29.1
Elementor Website Builder – more than just a page builder v3.29.1
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 / progress.php

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

545 lines 13.0 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 progress widget.
13 *
14 * Elementor widget that displays an escalating progress bar.
15 *
16 * @since 1.0.0
17 */
18 class Widget_Progress extends Widget_Base {
19
20 /**
21 * Get widget name.
22 *
23 * Retrieve progress 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 'progress';
32 }
33
34 /**
35 * Get widget title.
36 *
37 * Retrieve progress 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__( 'Progress Bar', 'elementor' );
46 }
47
48 /**
49 * Get widget icon.
50 *
51 * Retrieve progress 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-skill-bar';
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 [ 'progress', 'bar' ];
74 }
75
76 protected function is_dynamic_content(): bool {
77 return false;
78 }
79
80 /**
81 * Get style dependencies.
82 *
83 * Retrieve the list of style dependencies the widget requires.
84 *
85 * @since 3.24.0
86 * @access public
87 *
88 * @return array Widget style dependencies.
89 */
90 public function get_style_depends(): array {
91 return [ 'widget-progress' ];
92 }
93
94 public function has_widget_inner_wrapper(): bool {
95 return ! Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' );
96 }
97
98 /**
99 * Register progress widget controls.
100 *
101 * Adds different input fields to allow the user to change and customize the widget settings.
102 *
103 * @since 3.1.0
104 * @access protected
105 */
106 protected function register_controls() {
107 $this->start_controls_section(
108 'section_progress',
109 [
110 'label' => esc_html__( 'Progress Bar', 'elementor' ),
111 ]
112 );
113
114 $this->add_control(
115 'title',
116 [
117 'label' => esc_html__( 'Title', 'elementor' ),
118 'type' => Controls_Manager::TEXT,
119 'dynamic' => [
120 'active' => true,
121 ],
122 'placeholder' => esc_html__( 'Enter your title', 'elementor' ),
123 'default' => esc_html__( 'My Skill', 'elementor' ),
124 'label_block' => true,
125 ]
126 );
127
128 $this->add_control(
129 'title_tag',
130 [
131 'label' => esc_html__( 'Title HTML Tag', 'elementor' ),
132 'type' => Controls_Manager::SELECT,
133 'options' => [
134 'h1' => 'H1',
135 'h2' => 'H2',
136 'h3' => 'H3',
137 'h4' => 'H4',
138 'h5' => 'H5',
139 'h6' => 'H6',
140 'div' => 'div',
141 'span' => 'span',
142 'p' => 'p',
143 ],
144 'default' => 'span',
145 'condition' => [
146 'title!' => '',
147 ],
148 ]
149 );
150
151 $this->add_control(
152 'title_display',
153 [
154 'label' => esc_html__( 'Display Title', 'elementor' ),
155 'type' => Controls_Manager::SWITCHER,
156 'label_on' => esc_html__( 'Show', 'elementor' ),
157 'label_off' => esc_html__( 'Hide', 'elementor' ),
158 'default' => 'yes',
159 'condition' => [
160 'title!' => '',
161 ],
162 ]
163 );
164
165 $this->add_control(
166 'progress_type',
167 [
168 'label' => esc_html__( 'Type', 'elementor' ),
169 'type' => Controls_Manager::SELECT,
170 'options' => [
171 '' => esc_html__( 'Default', 'elementor' ),
172 'info' => esc_html__( 'Info', 'elementor' ),
173 'success' => esc_html__( 'Success', 'elementor' ),
174 'warning' => esc_html__( 'Warning', 'elementor' ),
175 'danger' => esc_html__( 'Danger', 'elementor' ),
176 ],
177 'default' => '',
178 'condition' => [
179 'progress_type!' => '', // a workaround to hide the control, unless it's in use (not default).
180 ],
181 'separator' => 'before',
182 ]
183 );
184
185 $this->add_control(
186 'percent',
187 [
188 'label' => esc_html__( 'Percentage', 'elementor' ),
189 'type' => Controls_Manager::SLIDER,
190 'default' => [
191 'size' => 50,
192 'unit' => '%',
193 ],
194 'dynamic' => [
195 'active' => true,
196 ],
197 'separator' => 'before',
198 ]
199 );
200
201 $this->add_control(
202 'display_percentage',
203 [
204 'label' => esc_html__( 'Display Percentage', 'elementor' ),
205 'type' => Controls_Manager::SWITCHER,
206 'label_on' => esc_html__( 'Show', 'elementor' ),
207 'label_off' => esc_html__( 'Hide', 'elementor' ),
208 'return_value' => 'show',
209 'default' => 'show',
210 ]
211 );
212
213 $this->add_control(
214 'inner_text',
215 [
216 'label' => esc_html__( 'Inner Text', 'elementor' ),
217 'type' => Controls_Manager::TEXT,
218 'dynamic' => [
219 'active' => true,
220 ],
221 'placeholder' => esc_html__( 'e.g. Web Designer', 'elementor' ),
222 'default' => esc_html__( 'Web Designer', 'elementor' ),
223 'label_block' => true,
224 'separator' => 'before',
225 ]
226 );
227
228 $this->end_controls_section();
229
230 $this->start_controls_section(
231 'section_progress_style',
232 [
233 'label' => esc_html__( 'Progress Bar', 'elementor' ),
234 'tab' => Controls_Manager::TAB_STYLE,
235 ]
236 );
237
238 $this->add_control(
239 'bar_color',
240 [
241 'label' => esc_html__( 'Color', 'elementor' ),
242 'type' => Controls_Manager::COLOR,
243 'global' => [
244 'default' => Global_Colors::COLOR_PRIMARY,
245 ],
246 'selectors' => [
247 '{{WRAPPER}} .elementor-progress-wrapper .elementor-progress-bar' => 'background-color: {{VALUE}};',
248 ],
249 ]
250 );
251
252 $this->add_control(
253 'bar_bg_color',
254 [
255 'label' => esc_html__( 'Background Color', 'elementor' ),
256 'type' => Controls_Manager::COLOR,
257 'selectors' => [
258 '{{WRAPPER}} .elementor-progress-wrapper' => 'background-color: {{VALUE}};',
259 ],
260 ]
261 );
262
263 $this->add_control(
264 'bar_height',
265 [
266 'label' => esc_html__( 'Height', 'elementor' ),
267 'type' => Controls_Manager::SLIDER,
268 'size_units' => [ 'px', 'em', 'rem', 'custom' ],
269 'selectors' => [
270 '{{WRAPPER}} .elementor-progress-bar' => 'height: {{SIZE}}{{UNIT}}; line-height: {{SIZE}}{{UNIT}};',
271 ],
272 ]
273 );
274
275 $this->add_control(
276 'bar_border_radius',
277 [
278 'label' => esc_html__( 'Border Radius', 'elementor' ),
279 'type' => Controls_Manager::SLIDER,
280 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
281 'selectors' => [
282 '{{WRAPPER}} .elementor-progress-wrapper' => 'border-radius: {{SIZE}}{{UNIT}}; overflow: hidden;',
283 ],
284 ]
285 );
286
287 $this->add_control(
288 'inner_text_heading',
289 [
290 'label' => esc_html__( 'Inner Text', 'elementor' ),
291 'type' => Controls_Manager::HEADING,
292 'separator' => 'before',
293 ]
294 );
295
296 $this->add_control(
297 'bar_inline_color',
298 [
299 'label' => esc_html__( 'Color', 'elementor' ),
300 'type' => Controls_Manager::COLOR,
301 'selectors' => [
302 '{{WRAPPER}} .elementor-progress-bar' => 'color: {{VALUE}};',
303 ],
304 ]
305 );
306
307 $this->add_group_control(
308 Group_Control_Typography::get_type(),
309 [
310 'name' => 'bar_inner_typography',
311 'selector' => '{{WRAPPER}} .elementor-progress-bar',
312 'exclude' => [
313 'line_height',
314 ],
315 ]
316 );
317
318 $this->add_group_control(
319 Group_Control_Text_Shadow::get_type(),
320 [
321 'name' => 'bar_inner_shadow',
322 'selector' => '{{WRAPPER}} .elementor-progress-bar',
323 ]
324 );
325
326 $this->end_controls_section();
327
328 $this->start_controls_section(
329 'section_title',
330 [
331 'label' => esc_html__( 'Title Style', 'elementor' ),
332 'tab' => Controls_Manager::TAB_STYLE,
333 ]
334 );
335
336 $this->add_control(
337 'title_color',
338 [
339 'label' => esc_html__( 'Text Color', 'elementor' ),
340 'type' => Controls_Manager::COLOR,
341 'selectors' => [
342 '{{WRAPPER}} .elementor-title' => 'color: {{VALUE}};',
343 ],
344 'global' => [
345 'default' => Global_Colors::COLOR_PRIMARY,
346 ],
347 ]
348 );
349
350 $this->add_group_control(
351 Group_Control_Typography::get_type(),
352 [
353 'name' => 'typography',
354 'selector' => '{{WRAPPER}} .elementor-title',
355 'global' => [
356 'default' => Global_Typography::TYPOGRAPHY_TEXT,
357 ],
358 ]
359 );
360
361 $this->add_group_control(
362 Group_Control_Text_Shadow::get_type(),
363 [
364 'name' => 'title_shadow',
365 'selector' => '{{WRAPPER}} .elementor-title',
366 ]
367 );
368
369 $this->end_controls_section();
370 }
371
372 /**
373 * Render progress widget output on the frontend.
374 * Make sure value does no exceed 100%.
375 *
376 * Written in PHP and used to generate the final HTML.
377 *
378 * @since 1.0.0
379 * @access protected
380 */
381 protected function render() {
382 $settings = $this->get_settings_for_display();
383
384 if ( empty( $settings['title'] ) && empty( $settings['percent']['size'] ) ) {
385 return;
386 }
387
388 $progressbar_id = 'elementor-progress-bar-' . $this->get_id();
389
390 $progress_percentage = is_numeric( $settings['percent']['size'] ) ? $settings['percent']['size'] : '0';
391 if ( 100 < $progress_percentage ) {
392 $progress_percentage = 100;
393 }
394
395 if ( ! Utils::is_empty( $settings['title'] ) ) {
396
397 if ( 'yes' === $settings['title_display'] ) {
398
399 $this->add_render_attribute(
400 'title',
401 [
402 'class' => 'elementor-title',
403 'id' => $progressbar_id,
404 ]
405 );
406
407 $this->add_inline_editing_attributes( 'title' );
408
409 $this->add_render_attribute( 'wrapper', 'aria-labelledby', $progressbar_id );
410
411 } else {
412
413 $this->add_render_attribute( 'wrapper', 'aria-label', $settings['title'] );
414
415 }
416 }
417
418 $this->add_render_attribute(
419 'wrapper',
420 [
421 'class' => 'elementor-progress-wrapper',
422 'role' => 'progressbar',
423 'aria-valuemin' => '0',
424 'aria-valuemax' => '100',
425 'aria-valuenow' => $progress_percentage,
426 ]
427 );
428
429 if ( ! empty( $settings['inner_text'] ) ) {
430 $this->add_render_attribute( 'wrapper', 'aria-valuetext', "{$progress_percentage}% ({$settings['inner_text']})" );
431 }
432
433 if ( ! empty( $settings['progress_type'] ) ) {
434 $this->add_render_attribute( 'wrapper', 'class', 'progress-' . $settings['progress_type'] );
435 }
436
437 $this->add_render_attribute(
438 'progress-bar',
439 [
440 'class' => 'elementor-progress-bar',
441 'data-max' => $progress_percentage,
442 ]
443 );
444
445 $this->add_render_attribute( 'inner_text', 'class', 'elementor-progress-text' );
446
447 $this->add_inline_editing_attributes( 'inner_text' );
448
449 if ( ! Utils::is_empty( $settings['title'] ) && 'yes' === $settings['title_display'] ) { ?>
450 <<?php Utils::print_validated_html_tag( $settings['title_tag'] ); ?> <?php $this->print_render_attribute_string( 'title' ); ?>>
451 <?php echo wp_kses_post( $settings['title'] ); ?>
452 </<?php Utils::print_validated_html_tag( $settings['title_tag'] ); ?>>
453 <?php } ?>
454
455 <div <?php $this->print_render_attribute_string( 'wrapper' ); ?>>
456 <div <?php $this->print_render_attribute_string( 'progress-bar' ); ?>>
457 <span <?php $this->print_render_attribute_string( 'inner_text' ); ?>><?php echo wp_kses_post( $settings['inner_text'] ); ?></span>
458 <?php if ( 'show' === $settings['display_percentage'] ) { ?>
459 <span class="elementor-progress-percentage"><?php echo $progress_percentage; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>%</span>
460 <?php } ?>
461 </div>
462 </div>
463 <?php
464 }
465
466 /**
467 * Render progress widget output in the editor.
468 *
469 * Written as a Backbone JavaScript template and used to generate the live preview.
470 *
471 * @since 2.9.0
472 * @access protected
473 */
474 protected function content_template() {
475 ?>
476 <#
477 if ( '' === settings.title && '' === settings.percent.size ) {
478 return;
479 }
480
481 const title_tag = elementor.helpers.validateHTMLTag( settings.title_tag );
482 const progressbar_id = 'elementor-progress-bar-<?php echo esc_attr( $this->get_id() ); ?>';
483
484 let progress_percentage = 0;
485 if ( ! isNaN( settings.percent.size ) ) {
486 progress_percentage = 100 < settings.percent.size ? 100 : settings.percent.size;
487 }
488
489 if ( settings.title ) {
490
491 if ( 'yes' === settings.title_display ) {
492
493 view.addRenderAttribute(
494 'title',
495 {
496 'class': 'elementor-title',
497 'id': progressbar_id,
498 }
499 );
500
501 view.addInlineEditingAttributes( 'title' );
502
503 view.addRenderAttribute( 'progressWrapper', 'aria-labelledby', progressbar_id );
504
505 } else {
506
507 view.addRenderAttribute( 'progressWrapper', 'aria-label', settings.title );
508
509 }
510 }
511
512 view.addRenderAttribute(
513 'progressWrapper',
514 {
515 'class': [ 'elementor-progress-wrapper', 'progress-' + settings.progress_type ],
516 'role': 'progressbar',
517 'aria-valuemin': '0',
518 'aria-valuemax': '100',
519 'aria-valuenow': progress_percentage,
520 }
521 );
522
523 if ( '' !== settings.inner_text ) {
524 view.addRenderAttribute( 'progressWrapper', 'aria-valuetext', progress_percentage + '% (' + settings.inner_text + ')' );
525 }
526
527 view.addRenderAttribute( 'inner_text', 'class', 'elementor-progress-text' );
528
529 view.addInlineEditingAttributes( 'inner_text' );
530 #>
531 <# if ( settings.title && 'yes' === settings.title_display ) { #>
532 <{{ title_tag }} {{{ view.getRenderAttributeString( 'title' ) }}}>{{ settings.title }}</{{ title_tag }}>
533 <# } #>
534 <div {{{ view.getRenderAttributeString( 'progressWrapper' ) }}}>
535 <div class="elementor-progress-bar" data-max="{{ progress_percentage }}">
536 <span {{{ view.getRenderAttributeString( 'inner_text' ) }}}>{{ settings.inner_text }}</span>
537 <# if ( 'show' === settings.display_percentage ) { #>
538 <span class="elementor-progress-percentage">{{{ progress_percentage }}}%</span>
539 <# } #>
540 </div>
541 </div>
542 <?php
543 }
544 }
545