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

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