PluginProbe
Elementor Website Builder – more than just a page builder / 3.28.0-dev2
Elementor Website Builder – more than just a page builder v3.28.0-dev2
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.28.0-dev2, at includes/widgets/progress.php

511 lines 12.2 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 'progress_type',
153 [
154 'label' => esc_html__( 'Type', 'elementor' ),
155 'type' => Controls_Manager::SELECT,
156 'options' => [
157 '' => esc_html__( 'Default', 'elementor' ),
158 'info' => esc_html__( 'Info', 'elementor' ),
159 'success' => esc_html__( 'Success', 'elementor' ),
160 'warning' => esc_html__( 'Warning', 'elementor' ),
161 'danger' => esc_html__( 'Danger', 'elementor' ),
162 ],
163 'default' => '',
164 'condition' => [
165 'progress_type!' => '', // a workaround to hide the control, unless it's in use (not default).
166 ],
167 'separator' => 'before',
168 ]
169 );
170
171 $this->add_control(
172 'percent',
173 [
174 'label' => esc_html__( 'Percentage', 'elementor' ),
175 'type' => Controls_Manager::SLIDER,
176 'default' => [
177 'size' => 50,
178 'unit' => '%',
179 ],
180 'dynamic' => [
181 'active' => true,
182 ],
183 ]
184 );
185
186 $this->add_control(
187 'display_percentage',
188 [
189 'label' => esc_html__( 'Display Percentage', 'elementor' ),
190 'type' => Controls_Manager::SWITCHER,
191 'label_on' => esc_html__( 'Show', 'elementor' ),
192 'label_off' => esc_html__( 'Hide', 'elementor' ),
193 'return_value' => 'show',
194 'default' => 'show',
195 ]
196 );
197
198 $this->add_control(
199 'inner_text',
200 [
201 'label' => esc_html__( 'Inner Text', 'elementor' ),
202 'type' => Controls_Manager::TEXT,
203 'dynamic' => [
204 'active' => true,
205 ],
206 'placeholder' => esc_html__( 'e.g. Web Designer', 'elementor' ),
207 'default' => esc_html__( 'Web Designer', 'elementor' ),
208 'label_block' => true,
209 ]
210 );
211
212 $this->end_controls_section();
213
214 $this->start_controls_section(
215 'section_progress_style',
216 [
217 'label' => esc_html__( 'Progress Bar', 'elementor' ),
218 'tab' => Controls_Manager::TAB_STYLE,
219 ]
220 );
221
222 $this->add_control(
223 'bar_color',
224 [
225 'label' => esc_html__( 'Color', 'elementor' ),
226 'type' => Controls_Manager::COLOR,
227 'global' => [
228 'default' => Global_Colors::COLOR_PRIMARY,
229 ],
230 'selectors' => [
231 '{{WRAPPER}} .elementor-progress-wrapper .elementor-progress-bar' => 'background-color: {{VALUE}};',
232 ],
233 ]
234 );
235
236 $this->add_control(
237 'bar_bg_color',
238 [
239 'label' => esc_html__( 'Background Color', 'elementor' ),
240 'type' => Controls_Manager::COLOR,
241 'selectors' => [
242 '{{WRAPPER}} .elementor-progress-wrapper' => 'background-color: {{VALUE}};',
243 ],
244 ]
245 );
246
247 $this->add_control(
248 'bar_height',
249 [
250 'label' => esc_html__( 'Height', 'elementor' ),
251 'type' => Controls_Manager::SLIDER,
252 'size_units' => [ 'px', 'em', 'rem', 'custom' ],
253 'selectors' => [
254 '{{WRAPPER}} .elementor-progress-bar' => 'height: {{SIZE}}{{UNIT}}; line-height: {{SIZE}}{{UNIT}};',
255 ],
256 ]
257 );
258
259 $this->add_control(
260 'bar_border_radius',
261 [
262 'label' => esc_html__( 'Border Radius', 'elementor' ),
263 'type' => Controls_Manager::SLIDER,
264 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
265 'selectors' => [
266 '{{WRAPPER}} .elementor-progress-wrapper' => 'border-radius: {{SIZE}}{{UNIT}}; overflow: hidden;',
267 ],
268 ]
269 );
270
271 $this->add_control(
272 'inner_text_heading',
273 [
274 'label' => esc_html__( 'Inner Text', 'elementor' ),
275 'type' => Controls_Manager::HEADING,
276 'separator' => 'before',
277 ]
278 );
279
280 $this->add_control(
281 'bar_inline_color',
282 [
283 'label' => esc_html__( 'Color', 'elementor' ),
284 'type' => Controls_Manager::COLOR,
285 'selectors' => [
286 '{{WRAPPER}} .elementor-progress-bar' => 'color: {{VALUE}};',
287 ],
288 ]
289 );
290
291 $this->add_group_control(
292 Group_Control_Typography::get_type(),
293 [
294 'name' => 'bar_inner_typography',
295 'selector' => '{{WRAPPER}} .elementor-progress-bar',
296 'exclude' => [
297 'line_height',
298 ],
299 ]
300 );
301
302 $this->add_group_control(
303 Group_Control_Text_Shadow::get_type(),
304 [
305 'name' => 'bar_inner_shadow',
306 'selector' => '{{WRAPPER}} .elementor-progress-bar',
307 ]
308 );
309
310 $this->end_controls_section();
311
312 $this->start_controls_section(
313 'section_title',
314 [
315 'label' => esc_html__( 'Title Style', 'elementor' ),
316 'tab' => Controls_Manager::TAB_STYLE,
317 ]
318 );
319
320 $this->add_control(
321 'title_color',
322 [
323 'label' => esc_html__( 'Text Color', 'elementor' ),
324 'type' => Controls_Manager::COLOR,
325 'selectors' => [
326 '{{WRAPPER}} .elementor-title' => 'color: {{VALUE}};',
327 ],
328 'global' => [
329 'default' => Global_Colors::COLOR_PRIMARY,
330 ],
331 ]
332 );
333
334 $this->add_group_control(
335 Group_Control_Typography::get_type(),
336 [
337 'name' => 'typography',
338 'selector' => '{{WRAPPER}} .elementor-title',
339 'global' => [
340 'default' => Global_Typography::TYPOGRAPHY_TEXT,
341 ],
342 ]
343 );
344
345 $this->add_group_control(
346 Group_Control_Text_Shadow::get_type(),
347 [
348 'name' => 'title_shadow',
349 'selector' => '{{WRAPPER}} .elementor-title',
350 ]
351 );
352
353 $this->end_controls_section();
354 }
355
356 /**
357 * Render progress widget output on the frontend.
358 * Make sure value does no exceed 100%.
359 *
360 * Written in PHP and used to generate the final HTML.
361 *
362 * @since 1.0.0
363 * @access protected
364 */
365 protected function render() {
366 $settings = $this->get_settings_for_display();
367
368 if ( empty( $settings['title'] ) && empty( $settings['percent']['size'] ) ) {
369 return;
370 }
371
372 $progressbar_id = 'elementor-progress-bar-' . $this->get_id();
373
374 $progress_percentage = is_numeric( $settings['percent']['size'] ) ? $settings['percent']['size'] : '0';
375 if ( 100 < $progress_percentage ) {
376 $progress_percentage = 100;
377 }
378
379 if ( ! Utils::is_empty( $settings['title'] ) ) {
380 $this->add_render_attribute(
381 'title',
382 [
383 'class' => 'elementor-title',
384 'id' => $progressbar_id,
385 ]
386 );
387
388 $this->add_inline_editing_attributes( 'title' );
389
390 $this->add_render_attribute( 'wrapper', 'aria-labelledby', $progressbar_id );
391 }
392
393 $this->add_render_attribute(
394 'wrapper',
395 [
396 'class' => 'elementor-progress-wrapper',
397 'role' => 'progressbar',
398 'aria-valuemin' => '0',
399 'aria-valuemax' => '100',
400 'aria-valuenow' => $progress_percentage,
401 ]
402 );
403
404 if ( ! empty( $settings['inner_text'] ) ) {
405 $this->add_render_attribute( 'wrapper', 'aria-valuetext', "{$progress_percentage}% ({$settings['inner_text']})" );
406 }
407
408 if ( ! empty( $settings['progress_type'] ) ) {
409 $this->add_render_attribute( 'wrapper', 'class', 'progress-' . $settings['progress_type'] );
410 }
411
412 $this->add_render_attribute(
413 'progress-bar',
414 [
415 'class' => 'elementor-progress-bar',
416 'data-max' => $progress_percentage,
417 ]
418 );
419
420 $this->add_render_attribute( 'inner_text', 'class', 'elementor-progress-text' );
421
422 $this->add_inline_editing_attributes( 'inner_text' );
423
424 if ( ! Utils::is_empty( $settings['title'] ) ) { ?>
425 <<?php Utils::print_validated_html_tag( $settings['title_tag'] ); ?> <?php $this->print_render_attribute_string( 'title' ); ?>>
426 <?php echo wp_kses_post( $settings['title'] ); ?>
427 </<?php Utils::print_validated_html_tag( $settings['title_tag'] ); ?>>
428 <?php } ?>
429
430 <div <?php $this->print_render_attribute_string( 'wrapper' ); ?>>
431 <div <?php $this->print_render_attribute_string( 'progress-bar' ); ?>>
432 <span <?php $this->print_render_attribute_string( 'inner_text' ); ?>><?php echo wp_kses_post( $settings['inner_text'] ); ?></span>
433 <?php if ( 'show' === $settings['display_percentage'] ) { ?>
434 <span class="elementor-progress-percentage"><?php echo $progress_percentage; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>%</span>
435 <?php } ?>
436 </div>
437 </div>
438 <?php
439 }
440
441 /**
442 * Render progress widget output in the editor.
443 *
444 * Written as a Backbone JavaScript template and used to generate the live preview.
445 *
446 * @since 2.9.0
447 * @access protected
448 */
449 protected function content_template() {
450 ?>
451 <#
452 if ( '' === settings.title && '' === settings.percent.size ) {
453 return;
454 }
455
456 const title_tag = elementor.helpers.validateHTMLTag( settings.title_tag );
457 const progressbar_id = 'elementor-progress-bar-<?php echo esc_attr( $this->get_id() ); ?>';
458
459 let progress_percentage = 0;
460 if ( ! isNaN( settings.percent.size ) ) {
461 progress_percentage = 100 < settings.percent.size ? 100 : settings.percent.size;
462 }
463
464 if ( settings.title ) {
465 view.addRenderAttribute(
466 'title',
467 {
468 'class': 'elementor-title',
469 'id': progressbar_id,
470 }
471 );
472
473 view.addInlineEditingAttributes( 'title' );
474
475 view.addRenderAttribute( 'wrapper', 'aria-labelledby', progressbar_id );
476 }
477
478 view.addRenderAttribute(
479 'progressWrapper',
480 {
481 'class': [ 'elementor-progress-wrapper', 'progress-' + settings.progress_type ],
482 'role': 'progressbar',
483 'aria-valuemin': '0',
484 'aria-valuemax': '100',
485 'aria-valuenow': progress_percentage,
486 }
487 );
488
489 if ( '' !== settings.inner_text ) {
490 view.addRenderAttribute( 'progressWrapper', 'aria-valuetext', progress_percentage + '% (' + settings.inner_text + ')' );
491 }
492
493 view.addRenderAttribute( 'inner_text', 'class', 'elementor-progress-text' );
494
495 view.addInlineEditingAttributes( 'inner_text' );
496 #>
497 <# if ( settings.title ) { #>
498 <{{ title_tag }} {{{ view.getRenderAttributeString( 'title' ) }}}>{{ settings.title }}</{{ title_tag }}>
499 <# } #>
500 <div {{{ view.getRenderAttributeString( 'progressWrapper' ) }}}>
501 <div class="elementor-progress-bar" data-max="{{ progress_percentage }}">
502 <span {{{ view.getRenderAttributeString( 'inner_text' ) }}}>{{ settings.inner_text }}</span>
503 <# if ( 'show' === settings.display_percentage ) { #>
504 <span class="elementor-progress-percentage">{{{ progress_percentage }}}%</span>
505 <# } #>
506 </div>
507 </div>
508 <?php
509 }
510 }
511