PluginProbe
UiCore Elements – Free widgets and templates for Elementor / 1.2.4
UiCore Elements – Free widgets and templates for Elementor v1.2.4
1.3.17 1.3.16 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 All 41 releases
uicore-elements / includes / widgets / counter.php

counter.php in UiCore Elements – Free widgets and templates for Elementor 1.2.4, at includes/widgets/counter.php

1,437 lines 52.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace UiCoreElements;
3
4 use Elementor\Controls_Manager;
5 use Elementor\Icons_Manager;
6 use Elementor\Group_Control_Border;
7 use Elementor\Group_Control_Box_Shadow;
8 use Elementor\Group_Control_Typography;
9 use Elementor\Group_Control_Background;
10 use UiCoreElements\UiCoreWidget;
11
12
13 defined('ABSPATH') || exit();
14
15 /**
16 * Counter
17 *
18 * @author Lucas Marini Falbo <lucas@uicore.co>
19 * @since 1.0.0
20 */
21
22 class Counter extends UiCoreWidget
23 {
24
25 public function get_name()
26 {
27 return 'uicore-counter';
28 }
29 public function get_title()
30 {
31 return __( 'Counter', 'uicore-elements' );
32 }
33 public function get_icon()
34 {
35 return 'eicon-counter ui-e-widget';
36 }
37 public function get_keywords()
38 {
39 return ['counter', 'count', 'number'];
40 }
41 public function get_categories()
42 {
43 return [ 'uicore' ];
44 }
45 public function get_styles()
46 {
47 return [
48 'counter',
49 'counter-motion' => [
50 'condition' => [
51 'counter_animation' => 'motion',
52 ],
53 ],
54 ];
55 }
56 public function get_scripts()
57 {
58 return [
59 'counter',
60 'odometer' => [
61 'condition' => [
62 'counter_animation' => 'odometer',
63 ],
64 ]
65 ];
66 }
67 // TODO: remove or set as false, after 3.30, when the full deprecation of widget innet wrapper is ready
68 public function has_widget_inner_wrapper(): bool {
69 return true;
70 }
71 protected function register_controls()
72 {
73
74 $this->start_controls_section(
75 'content_section',
76 [
77 'label' => __( 'Counter', 'uicore-elements' ),
78 'tab' => Controls_Manager::TAB_CONTENT,
79 ]
80 );
81
82 $this->add_control(
83 'show_icon',
84 [
85 'label' => esc_html__( 'Show Icon', 'uicore-elements' ),
86 'type' => Controls_Manager::SWITCHER,
87 'label_on' => esc_html__( 'Show', 'uicore-elements' ),
88 'label_off' => esc_html__( 'Hide', 'uicore-elements' ),
89 'return_value' => 'true',
90 'prefix_class' => 'ui-e-counter-media-',
91 'render_type' => 'template',
92 ]
93 );
94
95 $this->add_control(
96 'icon_type',
97 [
98 'label' => esc_html__( 'Icon Type', 'uicore-elements' ),
99 'type' => Controls_Manager::CHOOSE,
100 'options' => [
101 'icon' => [
102 'title' => esc_html__( 'Icon', 'uicore-elements' ),
103 'icon' => 'eicon-star',
104 ],
105 'image' => [
106 'title' => esc_html__( 'Image', 'uicore-elements' ),
107 'icon' => 'eicon-image-bold',
108 ],
109
110 ],
111 'default' => 'icon',
112 'toggle' => false,
113 'condition' => [
114 'show_icon' => 'true',
115 ],
116 ]
117 );
118
119 $this->add_control(
120 'selected_icon',
121 [
122 'label' => esc_html__( 'Choose icon', 'uicore-elements' ),
123 'type' => Controls_Manager::ICONS,
124 'condition' => [
125 'show_icon' => 'true',
126 'icon_type' => 'icon',
127 ],
128 ]
129 );
130
131 $this->add_control(
132 'image',
133 [
134 'label' => esc_html__( 'Choose Image', 'uicore-elements' ),
135 'type' => Controls_Manager::MEDIA,
136 'condition' => [
137 'show_icon' => 'true',
138 'icon_type' => 'image',
139 ],
140 'dynamic' => [
141 'active' => true,
142 ],
143 ]
144 );
145
146 $this->add_control(
147 'count_start',
148 [
149 'label' => esc_html__( 'Starting number', 'uicore-elements' ),
150 'type' => Controls_Manager::NUMBER,
151 'step' => 1,
152 'default' => 10,
153 'frontend_available' => true,
154 'dynamic' => [
155 'active' => true,
156 ],
157 'condition' =>[
158 'counter_animation!' => ['motion'],
159 ],
160 ]
161 );
162
163 $this->add_control(
164 'count_end',
165 [
166 'label' => esc_html__( 'Ending number', 'uicore-elements' ),
167 'type' => Controls_Manager::NUMBER,
168 'step' => 1,
169 'default' => 120,
170 'frontend_available' => true,
171 'dynamic' => [
172 'active' => true,
173 ],
174 'condition' =>[
175 'counter_animation!' => ['motion'],
176 ],
177 ]
178 );
179
180 $this->add_control(
181 'count_number',
182 [
183 'label' => esc_html__( 'Number', 'uicore-elements' ),
184 'type' => Controls_Manager::TEXT,
185 'default' => '120,00',
186 'frontend_available' => true,
187 'label_block' => true,
188 'dynamic' => [
189 'active' => true,
190 ],
191 'condition' =>[
192 'counter_animation' => ['motion'],
193 ],
194 ]
195 );
196
197 $this->add_control(
198 'counter_html_tag',
199 [
200 'label' => esc_html__( 'Number HTML class', 'uicore-elements' ),
201 'type' => Controls_Manager::SELECT,
202 'default' => 'h1',
203 'options' => [
204 'h1' => esc_html__( 'H1', 'uicore-elements' ),
205 'h2' => esc_html__( 'H2', 'uicore-elements' ),
206 'h3' => esc_html__( 'H3', 'uicore-elements' ),
207 'h4' => esc_html__( 'H4', 'uicore-elements' ),
208 'h5' => esc_html__( 'H5', 'uicore-elements' ),
209 'h6' => esc_html__( 'H6', 'uicore-elements' ),
210 'p' => esc_html__( 'p', 'uicore-elements' ),
211 'span' => esc_html__( 'span', 'uicore-elements' ),
212 ],
213 ]
214 );
215
216 $this->add_control(
217 'content_text',
218 [
219 'label' => esc_html__( 'Title', 'uicore-elements' ),
220 'type' => Controls_Manager::TEXT,
221 'default' => esc_html__( 'Awesome number', 'uicore-elements' ),
222 'placeholder' => esc_html__( 'Type your title here', 'uicore-elements' ),
223 'separator' => 'before',
224 'label_block' => true,
225 'dynamic' => [
226 'active' => true,
227 ],
228 ]
229 );
230
231 $this->add_control(
232 'content_html_tag',
233 [
234 'label' => esc_html__( 'Title HTML tag', 'uicore-elements' ),
235 'type' => Controls_Manager::SELECT,
236 'default' => 'p',
237 'options' => [
238 'H1' => esc_html__( 'H1', 'uicore-elements' ),
239 'H2' => esc_html__( 'H2', 'uicore-elements' ),
240 'H3' => esc_html__( 'H3', 'uicore-elements' ),
241 'H4' => esc_html__( 'H4', 'uicore-elements' ),
242 'H5' => esc_html__( 'H5', 'uicore-elements' ),
243 'H6' => esc_html__( 'H6', 'uicore-elements' ),
244 'p' => esc_html__( 'p', 'uicore-elements' ),
245 'span' => esc_html__( 'span', 'uicore-elements' ),
246 ],
247 ]
248 );
249
250 $this->add_control(
251 'counter_text_inline',
252 [
253 'label' => esc_html__( 'Text inline', 'uicore-elements' ),
254 'type' => Controls_Manager::SWITCHER,
255 'label_on' => esc_html__( 'True', 'uicore-elements' ),
256 'label_off' => esc_html__( 'False', 'uicore-elements' ),
257 'return_value' => 'true',
258 'prefix_class' => 'ui-e-inline-',
259 'render_type' => 'template',
260 'default' => false,
261 ]
262 );
263
264 $this->add_control(
265 'icon_position',
266 [
267 'label' => esc_html__( 'Icon position', 'uicore-elements' ),
268 'type' => Controls_Manager::CHOOSE,
269 'options' => [
270 'left' => [
271 'title' => esc_html__( 'Left', 'uicore-elements' ),
272 'icon' => 'eicon-h-align-left',
273 ],
274 'top' => [
275 'title' => esc_html__( 'Top', 'uicore-elements' ),
276 'icon' => 'eicon-v-align-top',
277 ],
278 'right' => [
279 'title' => esc_html__( 'Right', 'uicore-elements' ),
280 'icon' => 'eicon-h-align-right',
281 ],
282 ],
283 'default' => 'top',
284 'toggle' => false,
285 'condition' =>[
286 'show_icon' => 'true',
287 'counter_text_inline!' => 'true',
288 ],
289 'prefix_class' => 'ui-e-',
290 'render_type' => 'template',
291 ]
292 );
293
294 $this->add_control(
295 'icon_position_inline',
296 [
297 'label' => esc_html__( 'Icon position', 'uicore-elements' ),
298 'type' => Controls_Manager::CHOOSE,
299 'options' => [
300 'left' => [
301 'title' => esc_html__( 'Left', 'uicore-elements' ),
302 'icon' => 'eicon-h-align-left',
303 ],
304 'right' => [
305 'title' => esc_html__( 'Right', 'uicore-elements' ),
306 'icon' => 'eicon-h-align-right',
307 ],
308 ],
309 'default' => 'left',
310 'toggle' => false,
311 'condition' =>[
312 'show_icon' => 'true',
313 'counter_text_inline' => 'true',
314 ],
315 'prefix_class' => 'ui-e-',
316 'render_type' => 'template',
317 ]
318 );
319
320 $this->add_control(
321 'vertical_align',
322 [
323 'label' => esc_html__( 'Vertical position', 'uicore-elements' ),
324 'type' => Controls_Manager::CHOOSE,
325 'options' => [
326 'start' => [
327 'title' => esc_html__( 'Top', 'uicore-elements' ),
328 'icon' => 'eicon-v-align-top',
329 ],
330 'center' => [
331 'title' => esc_html__( 'Center', 'uicore-elements' ),
332 'icon' => 'eicon-v-align-middle',
333 ],
334 'end' => [
335 'title' => esc_html__( 'Bottom', 'uicore-elements' ),
336 'icon' => 'eicon-v-align-bottom',
337 ],
338 ],
339 'default' => 'center',
340 'toggle' => false,
341 'selectors' => [
342 '{{WRAPPER}} > div' => 'align-items: {{VALUE}};',
343 ],
344 'condition' => [
345 'icon_position!' => ['top'],
346 'counter_text_inline!' => ['true'],
347 ],
348 ]
349 );
350
351 $this->add_control(
352 'vertical_align_inline',
353 [
354 'label' => esc_html__( 'Vertical position', 'uicore-elements' ),
355 'type' => Controls_Manager::CHOOSE,
356 'options' => [
357 'start' => [
358 'title' => esc_html__( 'Top', 'uicore-elements' ),
359 'icon' => 'eicon-v-align-top',
360 ],
361 'center' => [
362 'title' => esc_html__( 'Center', 'uicore-elements' ),
363 'icon' => 'eicon-v-align-middle',
364 ],
365 'end' => [
366 'title' => esc_html__( 'Bottom', 'uicore-elements' ),
367 'icon' => 'eicon-v-align-bottom',
368 ],
369 ],
370 'default' => 'center',
371 'toggle' => false,
372 'selectors' => [
373 '{{WRAPPER}} > div' => 'align-items: {{VALUE}};',
374 ],
375 'condition' => [
376 'counter_text_inline' => ['true'],
377 ],
378 ]
379 );
380
381 $this->add_control(
382 'text_align',
383 [
384 'label' => esc_html__( 'Text Align', 'uicore-elements' ),
385 'type' => Controls_Manager::CHOOSE,
386 'options' => [
387 'left' => [
388 'title' => esc_html__( 'Left', 'uicore-elements' ),
389 'icon' => 'eicon-text-align-left',
390 ],
391 'center' => [
392 'title' => esc_html__( 'Center', 'uicore-elements' ),
393 'icon' => 'eicon-text-align-center',
394 ],
395 'right' => [
396 'title' => esc_html__( 'Right', 'uicore-elements' ),
397 'icon' => 'eicon-text-align-right',
398 ],
399 ],
400 'toggle' => false,
401 'default' => 'center',
402 'prefix_class' => 'ui-e-align-',
403 'selectors' => [
404 '{{WRAPPER}} .ui-e-title' => 'text-align: {{VALUE}};',
405 '{{WRAPPER}} .ui-e-ico' => 'text-align: {{VALUE}};',
406 ],
407
408 ]
409 );
410
411 $this->add_control(
412 'icon_offset_toggle',
413 [
414 'label' => esc_html__( 'Icon Offset', 'uicore-elements' ),
415 'type' => Controls_Manager::POPOVER_TOGGLE,
416 'label_off' => esc_html__( 'Default', 'uicore-elements' ),
417 'label_on' => esc_html__( 'Custom', 'uicore-elements' ),
418 'return_value' => 'yes',
419 'condition' => [
420 'show_icon' => 'true',
421 'counter_text_inline!' => 'true',
422 ],
423 ]
424 );
425
426 $this->start_popover();
427
428 $this->add_responsive_control(
429 'icon_vertical_offset',
430 [
431 'label' => esc_html__( 'Vertical offset', 'uicore-elements' ),
432 'type' => Controls_Manager::SLIDER,
433 'size_units' => ['px'],
434 'range' => [
435 'px' => [
436 'min' => -100,
437 'max' => 100,
438 'step' => 1,
439 ],
440 ],
441 'default' => [
442 'unit' => 'px',
443 'size' => 0,
444 ],
445 'condition' => [
446 'counter_text_inline!' => 'true',
447 'icon_offset_toggle' => 'yes',
448 ],
449 'selectors' => [
450 '{{WRAPPER}}' => '--ui-e-ico-vertical-off: {{SIZE}}{{UNIT}};',
451 ],
452 ]
453 );
454
455 $this->add_responsive_control(
456 'icon_horizontal_offset',
457 [
458 'label' => esc_html__( 'Horizontal offset', 'uicore-elements' ),
459 'type' => Controls_Manager::SLIDER,
460 'size_units' => ['px'],
461 'range' => [
462 'px' => [
463 'min' => -100,
464 'max' => 100,
465 'step' => 1,
466 ],
467 ],
468 'default' => [
469 'unit' => 'px',
470 'size' => 0,
471 ],
472 'condition' => [
473 'counter_text_inline!' => 'true',
474 'icon_offset_toggle' => 'yes',
475 ],
476 'selectors' => [
477 '{{WRAPPER}}' => '--ui-e-ico-horizontal-off: {{SIZE}}{{UNIT}};',
478 ],
479 ]
480 );
481
482 $this->end_popover();
483
484 $this->end_controls_section();
485
486 $this->start_controls_section(
487 'add_op_section',
488 [
489 'label' => __( 'Additional Options', 'uicore-elements' ),
490 'tab' => Controls_Manager::TAB_CONTENT,
491 ]
492 );
493
494 $this->add_control(
495 'use_grouping',
496 [
497 'label' => esc_html__( 'Use Grouping', 'uicore-elements' ),
498 'type' => Controls_Manager::SWITCHER,
499 'label_on' => esc_html__( 'True', 'uicore-elements' ),
500 'label_off' => esc_html__( 'False', 'uicore-elements' ),
501 'return_value' => 'true',
502 'default' => 'true',
503 'frontend_available' => true,
504 'condition' =>[
505 'counter_animation!' => ['motion'],
506 ],
507 ]
508 );
509
510 $this->add_control(
511 'counter_separator',
512 [
513 'label' => esc_html__( 'Thousand symbol', 'uicore-elements' ),
514 'type' => Controls_Manager::TEXT,
515 'default' => esc_html__( ',', 'uicore-elements' ),
516 'condition' =>[
517 'use_grouping' => 'true',
518 'counter_animation!' => ['motion'],
519 ],
520 'ai' => [
521 'active' => false,
522 ],
523 'frontend_available' => true,
524 ]
525 );
526
527 $this->add_control(
528 'decimal_places',
529 [
530 'label' => esc_html__( 'Decimal Places', 'uicore-elements' ),
531 'type' => Controls_Manager::NUMBER,
532 'min' => 0,
533 'max' => 4,
534 'step' => 1,
535 'default' => 0,
536 'ai' => [
537 'active' => false,
538 ],
539 'frontend_available' => true,
540 'condition' => [
541 'counter_animation!' => ['motion'],
542 ],
543 ]
544 );
545
546 $this->add_control(
547 'decimal_symbol',
548 [
549 'label' => esc_html__( 'Decimal Symbol', 'uicore-elements' ),
550 'type' => Controls_Manager::TEXT,
551 'default' => esc_html__( '.', 'uicore-elements' ),
552 'condition' =>[
553 'counter_animation!' => ['motion'],
554 ],
555 'ai' => [
556 'active' => false,
557 ],
558 'frontend_available' => true,
559 ]
560 );
561
562 $this->add_control(
563 'counter_prefix',
564 [
565 'label' => esc_html__( 'Counter Prefix', 'uicore-elements' ),
566 'type' => Controls_Manager::TEXT,
567 'default' => '',
568 'placeholder' => esc_html__( '$', 'uicore-elements' ),
569 'ai' => [
570 'active' => false,
571 ],
572 ]
573 );
574
575 $this->add_control(
576 'counter_suffix',
577 [
578 'label' => esc_html__( 'Counter Suffix', 'uicore-elements' ),
579 'type' => Controls_Manager::TEXT,
580 'default' => '',
581 'placeholder' => esc_html__( '+', 'uicore-elements' ),
582 'ai' => [
583 'active' => false,
584 ],
585 'frontend_available' => true,
586 ]
587 );
588
589 $this->end_controls_section();
590
591 $this->start_controls_section(
592 'icon_image_section',
593 [
594 'label' => __( 'Icon/Image', 'uicore-elements' ),
595 'tab' => Controls_Manager::TAB_STYLE,
596 'condition' => [
597 'show_icon' => 'true',
598 ],
599 ]
600 );
601
602 $this->start_controls_tabs(
603 'style_tabs'
604 );
605
606 $this->start_controls_tab(
607 'icon_colors',
608 [
609 'label' => esc_html__( 'Normal', 'uicore-elements' ),
610 ]
611 );
612
613 $this->add_control(
614 'icon_color',
615 [
616 'label' => esc_html__( 'Icon color', 'uicore-elements' ),
617 'type' => Controls_Manager::COLOR,
618 'condition' => [
619 'icon_type!' => 'image',
620 ],
621 'selectors' => [
622 '{{WRAPPER}} .ui-e-offset > svg' => 'fill:{{VALUE}};',
623 '{{WRAPPER}} .ui-e-offset > i' => 'color: {{VALUE}};',
624 ],
625
626 ]
627 );
628
629 $this->add_group_control(
630 Group_Control_Background::get_type(),
631 [
632 'name' => 'icon_background',
633 'types' => [ 'classic', 'gradient', 'video' ],
634 'selector' => '{{WRAPPER}} .ui-e-ico .ui-e-offset',
635 ]
636 );
637
638 $this->end_controls_tab();
639
640 $this->start_controls_tab(
641 'icon_colors_hover',
642 [
643 'label' => esc_html__( 'Hover', 'uicore-elements' ),
644 ]
645 );
646
647 $this->add_control(
648 'icon_color_hover',
649 [
650 'label' => esc_html__( 'Icon color', 'uicore-elements' ),
651 'type' => Controls_Manager::COLOR,
652 'condition' => [
653 'icon_type!' => 'image',
654 ],
655 'selectors' => [
656 '{{WRAPPER}} > div:hover .ui-e-offset > svg' => 'fill:{{VALUE}};',
657 '{{WRAPPER}} > div:hover .ui-e-offset > i' => 'color: {{VALUE}};',
658 ],
659
660 ]
661 );
662
663 $this->add_group_control(
664 Group_Control_Background::get_type(),
665 [
666 'name' => 'icon_background_hover',
667 'types' => [ 'classic', 'gradient', 'video' ],
668 'selector' => '{{WRAPPER}} > div:hover .ui-e-offset',
669
670 ]
671 );
672
673 $this->add_control(
674 'border_color_hover',
675 [
676 'label' => esc_html__( 'Border Color', 'uicore-elements' ),
677 'type' => Controls_Manager::COLOR,
678 'selectors' => [
679 '{{WRAPPER}} > div:hover .ui-e-offset' => 'border-color: {{VALUE}}',
680 ],
681 ]
682 );
683
684 $this->end_controls_tab();
685
686 $this->end_controls_tabs();
687
688 $this->add_control(
689 'hr',
690 [
691 'type' => Controls_Manager::DIVIDER,
692 ]
693 );
694
695 $this->add_responsive_control(
696 'icon_padding',
697 [
698 'label' => esc_html__( 'Padding', 'uicore-elements' ),
699 'type' => Controls_Manager::DIMENSIONS,
700 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
701 'range' => [
702 'px' => [
703 'min' => 0,
704 'max' => 10,
705 'step' => 1,
706 ],
707 '%' => [
708 'min' => 0,
709 'max' => 20,
710 ],
711 ],
712 'default' => [
713 'unit' => 'px',
714 'size' => 25,
715 ],
716 'selectors' => [
717 '{{WRAPPER}} .ui-e-offset' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
718 ],
719
720 ]
721 );
722
723 $this->add_group_control(
724 Group_Control_Border::get_type(),
725 [
726 'name' => 'icon_border',
727 'selector' => '{{WRAPPER}} .ui-e-offset',
728
729 ]
730 );
731
732 $this->add_responsive_control(
733 'icon_radius',
734 [
735 'label' => esc_html__( 'Border Radius', 'uicore-elements' ),
736 'type' => Controls_Manager::DIMENSIONS,
737 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
738 'default' => [
739 'unit' => 'px',
740 'size' => 100,
741 ],
742 'selectors' => [
743 '{{WRAPPER}} .ui-e-offset' => 'border-top-left-radius: {{TOP}}{{UNIT}}; border-top-right-radius:{{RIGHT}}{{UNIT}}; border-bottom-right-radius:{{BOTTOM}}{{UNIT}}; border-bottom-left-radius:{{LEFT}}{{UNIT}};',
744 ],
745
746 ]
747 );
748
749 $this->add_group_control(
750 Group_Control_Box_Shadow::get_type(),
751 [
752 'name' => 'icon_shadow',
753 'selector' => '{{WRAPPER}} .ui-e-offset',
754
755 ]
756 );
757
758 $this->add_responsive_control(
759 'icon_space',
760 [
761 'label' => esc_html__( 'Icon Space', 'uicore-elements' ),
762 'type' => Controls_Manager::SLIDER,
763 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
764 'range' => [
765 'px' => [
766 'min' => 0,
767 'max' => 60,
768 'step' => 1,
769 ],
770 '%' => [
771 'min' => 0,
772 'max' => 20,
773 ],
774 ],
775 'default' => [
776 'unit' => 'px',
777 'size' => 8,
778 ],
779 'selectors' => [
780 '{{WRAPPER}}' => '--ui-e-ico-spacing: {{SIZE}}{{UNIT}}',
781 ],
782
783 ]
784 );
785
786 $this->add_control(
787 'image_fullwidth',
788 [
789 'label' => esc_html__( 'Image fullwidth', 'uicore-elements' ),
790 'type' => Controls_Manager::SWITCHER,
791 'label_on' => esc_html__( 'True', 'uicore-elements' ),
792 'label_off' => esc_html__( 'False', 'uicore-elements' ),
793 'return_value' => 'true',
794 'default' => 'false',
795 'condition' => [
796 'icon_type' => 'image',
797 ],
798 'selectors' => [
799 '{{WRAPPER}} .ui-e-offset > *' => 'width: 100%;',
800
801 ],
802 ]
803 );
804
805 $this->add_responsive_control(
806 'image_size',
807 [
808 'label' => esc_html__( 'Image Size', 'uicore-elements' ),
809 'type' => Controls_Manager::SLIDER,
810 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
811 'range' => [
812 'px' => [
813 'min' => 0,
814 'max' => 991,
815 'step' => 1,
816 ],
817 '%' => [
818 'min' => 0,
819 'max' => 100,
820 ],
821 ],
822 'default' => [
823 'unit' => 'px',
824 'size' => 120,
825 ],
826 'condition' => [
827 'icon_type' => 'image',
828 'image_fullwidth!' => 'true',
829 ],
830 'selectors' => [
831 '{{WRAPPER}} .ui-e-offset > *' => 'width: {{SIZE}}{{UNIT}};',
832
833 ],
834 ]
835 );
836
837 $this->add_responsive_control(
838 'icon_size',
839 [
840 'label' => esc_html__( 'Icon Size', 'uicore-elements' ),
841 'type' => Controls_Manager::SLIDER,
842 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
843 'range' => [
844 'px' => [
845 'min' => 8,
846 'max' => 160,
847 'step' => 1,
848 ],
849 '%' => [
850 'min' => 0,
851 'max' => 100,
852 ],
853 ],
854 'default' => [
855 'unit' => 'px',
856 'size' => 40,
857 ],
858 'condition' => [
859 'icon_type' => 'icon',
860 ],
861 'selectors' => [
862 '{{WRAPPER}}' => '--ui-e-icon-size:{{SIZE}}{{UNIT}}',
863 ],
864 ]
865 );
866
867 $this->end_controls_section();
868
869 $this->start_controls_section(
870 'counter_number_section',
871 [
872 'label' => __( 'Number', 'uicore-elements' ),
873 'tab' => Controls_Manager::TAB_STYLE,
874 ]
875 );
876
877 $this->add_responsive_control(
878 'counter_number_space',
879 [
880 'label' => esc_html__( 'Number space', 'uicore-elements' ),
881 'type' => Controls_Manager::SLIDER,
882 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
883 'range' => [
884 'px' => [
885 'min' => 0,
886 'max' => 100,
887 'step' => 1,
888 ],
889 '%' => [
890 'min' => 0,
891 'max' => 100,
892 ],
893 ],
894 'default' => [
895 'unit' => 'px',
896 'size' => 0,
897 ],
898 'selectors' => [
899 '{{WRAPPER}}' => '--ui-e-num-spacing: {{SIZE}}{{UNIT}};',
900 ],
901
902 ]
903 );
904
905 $this->start_controls_tabs(
906 'counter_tabs'
907 );
908
909 $this->start_controls_tab(
910 'counter_color_normal',
911 [
912 'label' => esc_html__( 'Normal', 'uicore-elements' ),
913 ]
914 );
915
916 $this->add_control(
917 'counter_number_color',
918 [
919 'label' => esc_html__( 'Number Color', 'uicore-elements' ),
920 'type' => Controls_Manager::COLOR,
921 'selectors' => [
922 '{{WRAPPER}} .ui-e-num' => 'color: {{VALUE}}',
923 '{{WRAPPER}}' => '--ui-e-num-color: {{VALUE}}',
924 ],
925 ]
926 );
927
928 $this->end_controls_tab();
929
930 $this->start_controls_tab(
931 'counter_color_hover',
932 [
933 'label' => esc_html__( 'Hover', 'uicore-elements' ),
934 ]
935 );
936
937 $this->add_control(
938 'counter_number_color_hover',
939 [
940 'label' => esc_html__( 'Number Color', 'uicore-elements' ),
941 'type' => Controls_Manager::COLOR,
942 'selectors' => [
943 '{{WRAPPER}} > div:hover .ui-e-num' => 'color: {{VALUE}}',
944 ],
945 ]
946 );
947
948 $this->end_controls_tab();
949
950 $this->end_controls_tabs();
951
952 $this->add_group_control(
953 Group_Control_Typography::get_type(),
954 [
955 'name' => 'counter_number_typography',
956 'selector' => '{{WRAPPER}} .ui-e-num',
957 ]
958 );
959
960 $this->end_controls_section();
961
962 $this->start_controls_section(
963 'suffix_prefix_section',
964 [
965 'label' => __( 'Suffix/Prefix', 'uicore-elements' ),
966 'tab' => Controls_Manager::TAB_STYLE,
967 ]
968 );
969
970 $this->add_control(
971 'suffix_prefix_color',
972 [
973 'label' => esc_html__( 'Color', 'uicore-elements' ),
974 'type' => Controls_Manager::COLOR,
975 'selectors' => [
976 '{{WRAPPER}} .ui-e-prefix, {{WRAPPER}} .ui-e-suffix' => 'color: {{VALUE}}',
977 ],
978 ]
979 );
980 $this->add_group_control(
981 Group_Control_Typography::get_type(),
982 [
983 'name' => 'suffix_prefix_typography',
984 'selector' => '{{WRAPPER}} .ui-e-prefix, {{WRAPPER}} .ui-e-suffix',
985 ]
986 );
987
988 $this->start_controls_tabs(
989 'prefix_suffix_tabs'
990 );
991
992 $this->start_controls_tab(
993 'prefix_tab',
994 [
995 'label' => esc_html__( 'Prefix', 'uicore-elements' ),
996 ]
997 );
998
999 $this->add_responsive_control(
1000 'prefix_h_offset',
1001 [
1002 'label' => esc_html__( 'Horizontal Offset', 'uicore-elements' ),
1003 'type' => Controls_Manager::SLIDER,
1004 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
1005 'range' => [
1006 'px' => [
1007 'min' => -200,
1008 'max' => 200,
1009 'step' => 1,
1010 ],
1011 '%' => [
1012 'min' => -100,
1013 'max' => 100,
1014 ],
1015 ],
1016 'default' => [
1017 'unit' => 'px',
1018 'size' => 0,
1019 ],
1020 ]
1021 );
1022 $this->add_responsive_control(
1023 'prefix_v_offset',
1024 [
1025 'label' => esc_html__( 'Vertical Offset', 'uicore-elements' ),
1026 'type' => Controls_Manager::SLIDER,
1027 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
1028 'range' => [
1029 'px' => [
1030 'min' => -80,
1031 'max' => 80,
1032 'step' => 1,
1033 ],
1034 '%' => [
1035 'min' => -100,
1036 'max' => 100,
1037 ],
1038 ],
1039 'default' => [
1040 'unit' => 'px',
1041 'size' => 0,
1042 ],
1043 'selectors' => [
1044 '{{WRAPPER}} .ui-e-prefix' => 'transform: translate3d( {{prefix_h_offset.SIZE}}{{prefix_h_offset.UNIT}}, {{SIZE}}{{UNIT}}, 0);',
1045 ],
1046 ]
1047 );
1048
1049 $this->end_controls_tab();
1050
1051 $this->start_controls_tab(
1052 'suffix_tab',
1053 [
1054 'label' => esc_html__( 'Suffix', 'uicore-elements' ),
1055 ]
1056 );
1057
1058 $this->add_responsive_control(
1059 'suffix_h_offset',
1060 [
1061 'label' => esc_html__( 'Horizontal Offset', 'uicore-elements' ),
1062 'type' => Controls_Manager::SLIDER,
1063 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
1064 'range' => [
1065 'px' => [
1066 'min' => -200,
1067 'max' => 200,
1068 'step' => 1,
1069 ],
1070 '%' => [
1071 'min' => -100,
1072 'max' => 100,
1073 ],
1074 ],
1075 'default' => [
1076 'unit' => 'px',
1077 'size' => 0,
1078 ],
1079 ]
1080 );
1081 $this->add_responsive_control(
1082 'suffix_v_offset',
1083 [
1084 'label' => esc_html__( 'Vertical Offset', 'uicore-elements' ),
1085 'type' => Controls_Manager::SLIDER,
1086 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
1087 'range' => [
1088 'px' => [
1089 'min' => -80,
1090 'max' => 80,
1091 'step' => 1,
1092 ],
1093 '%' => [
1094 'min' => -100,
1095 'max' => 100,
1096 ],
1097 ],
1098 'default' => [
1099 'unit' => 'px',
1100 'size' => 0,
1101 ],
1102 'selectors' => [
1103 '{{WRAPPER}} .ui-e-suffix' => 'transform: translate3d( {{suffix_h_offset.SIZE}}{{suffix_h_offset.UNIT}}, {{SIZE}}{{UNIT}}, 0);',
1104 ],
1105 ]
1106 );
1107
1108 $this->end_controls_tab();
1109
1110 $this->end_controls_tabs();
1111
1112 $this->end_controls_section();
1113
1114 $this->start_controls_section(
1115 'content_text_section',
1116 [
1117 'label' => __( 'Text', 'uicore-elements' ),
1118 'tab' => Controls_Manager::TAB_STYLE,
1119 ]
1120 );
1121
1122 $this->start_controls_tabs(
1123 'content_text_tabs'
1124 );
1125
1126 $this->start_controls_tab(
1127 'content_text_normal',
1128 [
1129 'label' => esc_html__( 'Normal', 'uicore-elements' ),
1130 ]
1131 );
1132
1133 $this->add_control(
1134 'content_text_color',
1135 [
1136 'label' => esc_html__( 'Text Color', 'uicore-elements' ),
1137 'type' => Controls_Manager::COLOR,
1138 'selectors' => [
1139 '{{WRAPPER}} .ui-e-title' => 'color: {{VALUE}}',
1140 ],
1141 ]
1142 );
1143
1144 $this->end_controls_tab();
1145
1146 $this->start_controls_tab(
1147 'content_text_hover',
1148 [
1149 'label' => esc_html__( 'Hover', 'uicore-elements' ),
1150 ]
1151 );
1152
1153 $this->add_control(
1154 'content_text_color_hover',
1155 [
1156 'label' => esc_html__( 'Text Color', 'uicore-elements' ),
1157 'type' => Controls_Manager::COLOR,
1158 'selectors' => [
1159 '{{WRAPPER}} > div:hover .ui-e-title' => 'color: {{VALUE}}',
1160 ],
1161 ]
1162 );
1163
1164 $this->end_controls_tab();
1165
1166 $this->end_controls_tabs();
1167
1168 $this->add_group_control(
1169 Group_Control_Typography::get_type(),
1170 [
1171 'name' => 'content_text_typography',
1172 'selector' => '{{WRAPPER}} .ui-e-title',
1173 ]
1174 );
1175
1176 $this->end_controls_section();
1177
1178 $this->start_controls_section(
1179 'additional_section',
1180 [
1181 'label' => __( 'Additional', 'uicore-elements' ),
1182 'tab' => Controls_Manager::TAB_STYLE,
1183 ]
1184 );
1185
1186 $this->add_responsive_control(
1187 'content_padding',
1188 [
1189 'label' => esc_html__( 'Content Padding', 'uicore-elements' ),
1190 'type' => Controls_Manager::DIMENSIONS,
1191 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
1192 'range' => [
1193 'px' => [
1194 'min' => 0,
1195 'max' => 80,
1196 'step' => 5,
1197 ],
1198 '%' => [
1199 'min' => 0,
1200 'max' => 100,
1201 ],
1202 ],
1203 'default' => [
1204 'unit' => 'px',
1205 'size' => 15,
1206 ],
1207 'selectors' => [
1208 '{{WRAPPER}} > div' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
1209 ],
1210 ]
1211 );
1212
1213 $this->end_controls_section();
1214
1215 $this->start_controls_section(
1216 'animation_section',
1217 [
1218 'label' => __( 'Animations', 'uicore-elements' ),
1219 'tab' => Controls_Manager::TAB_STYLE,
1220 ]
1221 );
1222
1223 $this->add_control(
1224 'counter_animation',
1225 [
1226 'label' => esc_html__( 'Number animation', 'uicore-elements' ),
1227 'type' => Controls_Manager::SELECT,
1228 'default' => 'simple',
1229 'options' => [
1230 'simple' => esc_html__( 'Simple', 'uicore-elements' ),
1231 'odometer' => esc_html__( 'Odometer', 'uicore-elements' ),
1232 'motion' => esc_html__( 'Motion Blur', 'uicore-elements' ),
1233 ],
1234 'frontend_available' => true,
1235 'prefix_class' => 'ui-e-counter-',
1236 'render_type' => 'template',
1237 ]
1238 );
1239 $this->add_control(
1240 'duration',
1241 [
1242 'label' => esc_html__( 'Duration (in seconds)', 'uicore-elements' ),
1243 'type' => Controls_Manager::NUMBER,
1244 'min' => 0.1,
1245 'max' => 8.0,
1246 'step' => 0.1,
1247 'default' => 2.5,
1248 'condition' => [
1249 'counter_animation!' => 'motion',
1250 ],
1251 'frontend_available' => true,
1252 ]
1253 );
1254 $this->add_control(
1255 'motion_heading',
1256 [
1257 'label' => esc_html__( 'Motion Durations (in ms)', 'uicore-elements' ),
1258 'type' => Controls_Manager::HEADING,
1259 'condition' => [
1260 'counter_animation' => 'motion',
1261 ],
1262 'separator' => 'before',
1263 ]
1264 );
1265 $this->add_control(
1266 'motion_translate_duration',
1267 [
1268 'label' => esc_html__( 'Numbers translate', 'uicore-elements' ),
1269 'type' => Controls_Manager::NUMBER,
1270 'min' => 0.1,
1271 'max' => 8.0,
1272 'step' => 0.1,
1273 'default' => 0.32,
1274 'condition' => [
1275 'counter_animation' => 'motion',
1276 ],
1277 'selectors' => [
1278 '{{WRAPPER}}' => '--ui-e-motion-translate: {{VALUE}}s;',
1279 ],
1280 ]
1281 );
1282 $this->add_control(
1283 'motion_opacity_duration',
1284 [
1285 'label' => esc_html__( 'Numbers opacity', 'uicore-elements' ),
1286 'type' => Controls_Manager::NUMBER,
1287 'min' => 0.1,
1288 'max' => 8.0,
1289 'step' => 0.1,
1290 'default' => 0.2,
1291 'condition' => [
1292 'counter_animation' => 'motion',
1293 ],
1294 'selectors' => [
1295 '{{WRAPPER}}' => '--ui-e-motion-opacity: {{VALUE}}s;',
1296 ],
1297 ]
1298 );
1299 $this->add_control(
1300 'motion_blur_duration',
1301 [
1302 'label' => esc_html__( 'Blur effect', 'uicore-elements' ),
1303 'type' => Controls_Manager::NUMBER,
1304 'min' => 0.1,
1305 'max' => 8.0,
1306 'step' => 0.1,
1307 'default' => 0.36,
1308 'condition' => [
1309 'counter_animation' => 'motion',
1310 ],
1311 'selectors' => [
1312 '{{WRAPPER}}' => '--ui-e-motion-blur: {{VALUE}}s;',
1313 ],
1314 ]
1315 );
1316 $this->add_control(
1317 'motion_delay',
1318 [
1319 'label' => esc_html__( 'Delay between numbers', 'uicore-elements' ),
1320 'type' => Controls_Manager::NUMBER,
1321 'min' => 0.1,
1322 'max' => 8.0,
1323 'step' => 0.1,
1324 'default' => 0.2,
1325 'condition' => [
1326 'counter_animation' => 'motion',
1327 ],
1328 'selectors' => [
1329 '{{WRAPPER}}' => '--ui-e-motion-delay: {{VALUE}}s;',
1330 ],
1331 ]
1332 );
1333 $this->add_control(
1334 'animate_suffix',
1335 [
1336 'label' => esc_html__( 'Animate suffix', 'uicore-elements' ),
1337 'type' => Controls_Manager::SWITCHER,
1338 'label_on' => esc_html__( 'True', 'uicore-elements' ),
1339 'label_off' => esc_html__( 'False', 'uicore-elements' ),
1340 'return_value' => 'true',
1341 'frontend_available' => true,
1342 'description' => esc_html__('Add the suffix to the Odometer animation, but removes any suffix custom styling.', 'uicore-elements' ),
1343 'condition' =>[
1344 'counter_animation' => ['odometer'],
1345 ],
1346 ]
1347 );
1348
1349 $this->end_controls_section();
1350 }
1351 protected function render()
1352 {
1353
1354 $settings = $this->get_settings_for_display();
1355
1356 $icon_type = $settings['icon_type'];
1357 $num_tag = $settings['counter_html_tag'];
1358 $txt_tag = $settings['content_html_tag'];
1359 $prefix = $settings['counter_prefix'];
1360 $suffix = $settings['counter_suffix'];
1361 $media = $settings['show_icon'] ? true : false; // Check if media is enabled,
1362
1363 if ($media) {
1364 switch($icon_type){
1365 case 'icon' :
1366 $icon = $settings['selected_icon'];
1367 break;
1368 case 'image' :
1369 $icon = $settings['image'];
1370 break;
1371 }
1372 $icon_width = ( $icon_type === 'image' && $this->is_option('image_fullwidth', 'true') )
1373 ? esc_attr('large')
1374 : esc_attr('thumbnail');
1375 }
1376
1377 $stack = $settings['counter_text_inline'] ? false : true; // If text inline, no stack wrapper between elements is needed
1378 $title = !empty($settings['content_text']) ?
1379 '<' . esc_html($txt_tag) . ' class="ui-e-title">' . wp_kses_data($settings['content_text']) . '</' . esc_html($txt_tag) . '>' :
1380 "<!-- no title -->";
1381 $html = '<' . esc_html($num_tag) . ' class="ui-e-num">';
1382
1383 // Motion animation markup
1384 if ($settings['counter_animation'] == 'motion'){
1385 $value = $settings['count_number'];
1386 $numbers = str_split($value);
1387
1388 foreach ($numbers as $n => $value) {
1389 $index = 'style="--index:' . $n . '"';
1390
1391 // prefix
1392 if ( $n === 0 && !empty($prefix) ) {
1393 $html .= '<span class="ui-e-prefix" ' . $index . '>' . esc_html($prefix) . '</span>';
1394 }
1395
1396 // number
1397 $html .= '<span ' . $index . '>' . esc_html($value). ' </span>';
1398
1399 // suffix
1400 if ($n === count($numbers) - 1 && !empty($suffix)) {
1401 $html .= '<span class="ui-e-suffix" ' . $index . '>' . esc_html($suffix) . '</span>';
1402 }
1403 }
1404
1405 // Default markup
1406 }else{
1407 $html .= '<span class="ui-e-prefix">' . $prefix . '</span>';
1408 $html .= '<span class="value"> 0 </span>';
1409 $html .= $settings['animate_suffix'] == 'true' ? '' : '<span class="ui-e-suffix">' . $suffix . '</span>'; // Suffix might be animated by Odometer animation
1410 }
1411
1412 $html .= '</' . esc_html($num_tag) . '>';
1413
1414 // Build the widget HTML
1415 if($media) : ?>
1416 <div class="ui-e-ico">
1417 <div class="ui-e-offset">
1418 <?php if($icon_type === 'icon') {
1419 Icons_Manager::render_icon( $icon, [ 'aria-hidden' => 'true' ] );
1420 } else {
1421 echo wp_get_attachment_image( $icon['id'], $icon_width );
1422 } ?>
1423 </div>
1424 </div>
1425 <?php endif;
1426
1427 if($stack) {
1428 ?> <div class="ui-e-wrp"> <?php
1429 }
1430 echo wp_kses_post($html . $title);
1431 if($stack) {
1432 ?> </div> <?php
1433 }
1434 }
1435
1436 }
1437 \Elementor\Plugin::instance()->widgets_manager->register(new Counter());