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

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