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 / progress.php

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

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