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

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