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

463 lines 11.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 /**
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
351 $progress_percentage = is_numeric( $settings['percent']['size'] ) ? $settings['percent']['size'] : '0';
352 if ( 100 < $progress_percentage ) {
353 $progress_percentage = 100;
354 }
355
356 $this->add_render_attribute( 'title', 'class', 'elementor-title' );
357
358 $this->add_inline_editing_attributes( 'title' );
359
360 $this->add_render_attribute(
361 'wrapper',
362 [
363 'class' => 'elementor-progress-wrapper',
364 'role' => 'progressbar',
365 'aria-valuemin' => '0',
366 'aria-valuemax' => '100',
367 'aria-valuenow' => $progress_percentage,
368 ]
369 );
370
371 if ( ! empty( $settings['inner_text'] ) ) {
372 $this->add_render_attribute( 'wrapper', 'aria-valuetext', "{$progress_percentage}% ({$settings['inner_text']})" );
373 }
374
375 if ( ! empty( $settings['progress_type'] ) ) {
376 $this->add_render_attribute( 'wrapper', 'class', 'progress-' . $settings['progress_type'] );
377 }
378
379 $this->add_render_attribute(
380 'progress-bar',
381 [
382 'class' => 'elementor-progress-bar',
383 'data-max' => $progress_percentage,
384 ]
385 );
386
387 $this->add_render_attribute( 'inner_text', 'class', 'elementor-progress-text' );
388
389 $this->add_inline_editing_attributes( 'inner_text' );
390
391 if ( ! Utils::is_empty( $settings['title'] ) ) { ?>
392 <<?php Utils::print_validated_html_tag( $settings['title_tag'] ); ?> <?php $this->print_render_attribute_string( 'title' ); ?>>
393 <?php $this->print_unescaped_setting( 'title' ); ?>
394 </<?php Utils::print_validated_html_tag( $settings['title_tag'] ); ?>>
395 <?php } ?>
396
397 <div <?php $this->print_render_attribute_string( 'wrapper' ); ?>>
398 <div <?php $this->print_render_attribute_string( 'progress-bar' ); ?>>
399 <span <?php $this->print_render_attribute_string( 'inner_text' ); ?>><?php $this->print_unescaped_setting( 'inner_text' ); ?></span>
400 <?php if ( 'show' === $settings['display_percentage'] ) { ?>
401 <span class="elementor-progress-percentage"><?php echo $progress_percentage; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>%</span>
402 <?php } ?>
403 </div>
404 </div>
405 <?php
406 }
407
408 /**
409 * Render progress widget output in the editor.
410 *
411 * Written as a Backbone JavaScript template and used to generate the live preview.
412 *
413 * @since 2.9.0
414 * @access protected
415 */
416 protected function content_template() {
417 ?>
418 <#
419 const title_tag = elementor.helpers.validateHTMLTag( settings.title_tag );
420
421 let progress_percentage = 0;
422 if ( ! isNaN( settings.percent.size ) ) {
423 progress_percentage = 100 < settings.percent.size ? 100 : settings.percent.size;
424 }
425
426 view.addRenderAttribute( 'title', 'class', 'elementor-title' );
427
428 view.addInlineEditingAttributes( 'title' );
429
430 view.addRenderAttribute(
431 'progressWrapper',
432 {
433 'class': [ 'elementor-progress-wrapper', 'progress-' + settings.progress_type ],
434 'role': 'progressbar',
435 'aria-valuemin': '0',
436 'aria-valuemax': '100',
437 'aria-valuenow': progress_percentage,
438 }
439 );
440
441 if ( '' !== settings.inner_text ) {
442 view.addRenderAttribute( 'progressWrapper', 'aria-valuetext', progress_percentage + '% (' + settings.inner_text + ')' );
443 }
444
445 view.addRenderAttribute( 'inner_text', 'class', 'elementor-progress-text' );
446
447 view.addInlineEditingAttributes( 'inner_text' );
448 #>
449 <# if ( settings.title ) { #>
450 <{{ title_tag }} {{{ view.getRenderAttributeString( 'title' ) }}}>{{{ settings.title }}}</{{ title_tag }}>
451 <# } #>
452 <div {{{ view.getRenderAttributeString( 'progressWrapper' ) }}}>
453 <div class="elementor-progress-bar" data-max="{{ progress_percentage }}">
454 <span {{{ view.getRenderAttributeString( 'inner_text' ) }}}>{{{ settings.inner_text }}}</span>
455 <# if ( 'show' === settings.display_percentage ) { #>
456 <span class="elementor-progress-percentage">{{{ progress_percentage }}}%</span>
457 <# } #>
458 </div>
459 </div>
460 <?php
461 }
462 }
463