PluginProbe
Elementor Website Builder – more than just a page builder / 3.7.0
Elementor Website Builder – more than just a page builder v3.7.0
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 / counter.php

counter.php in Elementor Website Builder – more than just a page builder 3.7.0, at includes/widgets/counter.php

377 lines 8.7 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 counter widget.
13 *
14 * Elementor widget that displays stats and numbers in an escalating manner.
15 *
16 * @since 1.0.0
17 */
18 class Widget_Counter extends Widget_Base {
19
20 /**
21 * Get widget name.
22 *
23 * Retrieve counter 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 'counter';
32 }
33
34 /**
35 * Get widget title.
36 *
37 * Retrieve counter 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__( 'Counter', 'elementor' );
46 }
47
48 /**
49 * Get widget icon.
50 *
51 * Retrieve counter 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-counter';
60 }
61
62 /**
63 * Retrieve the list of scripts the counter widget depended on.
64 *
65 * Used to set scripts dependencies required to run the widget.
66 *
67 * @since 1.3.0
68 * @access public
69 *
70 * @return array Widget scripts dependencies.
71 */
72 public function get_script_depends() {
73 return [ 'jquery-numerator' ];
74 }
75
76 /**
77 * Get widget keywords.
78 *
79 * Retrieve the list of keywords the widget belongs to.
80 *
81 * @since 2.1.0
82 * @access public
83 *
84 * @return array Widget keywords.
85 */
86 public function get_keywords() {
87 return [ 'counter' ];
88 }
89
90 /**
91 * Register counter widget controls.
92 *
93 * Adds different input fields to allow the user to change and customize the widget settings.
94 *
95 * @since 3.1.0
96 * @access protected
97 */
98 protected function register_controls() {
99 $this->start_controls_section(
100 'section_counter',
101 [
102 'label' => esc_html__( 'Counter', 'elementor' ),
103 ]
104 );
105
106 $this->add_control(
107 'starting_number',
108 [
109 'label' => esc_html__( 'Starting Number', 'elementor' ),
110 'type' => Controls_Manager::NUMBER,
111 'default' => 0,
112 'dynamic' => [
113 'active' => true,
114 ],
115 ]
116 );
117
118 $this->add_control(
119 'ending_number',
120 [
121 'label' => esc_html__( 'Ending Number', 'elementor' ),
122 'type' => Controls_Manager::NUMBER,
123 'default' => 100,
124 'dynamic' => [
125 'active' => true,
126 ],
127 ]
128 );
129
130 $this->add_control(
131 'prefix',
132 [
133 'label' => esc_html__( 'Number Prefix', 'elementor' ),
134 'type' => Controls_Manager::TEXT,
135 'dynamic' => [
136 'active' => true,
137 ],
138 'default' => '',
139 'placeholder' => 1,
140 ]
141 );
142
143 $this->add_control(
144 'suffix',
145 [
146 'label' => esc_html__( 'Number Suffix', 'elementor' ),
147 'type' => Controls_Manager::TEXT,
148 'dynamic' => [
149 'active' => true,
150 ],
151 'default' => '',
152 'placeholder' => esc_html__( 'Plus', 'elementor' ),
153 ]
154 );
155
156 $this->add_control(
157 'duration',
158 [
159 'label' => esc_html__( 'Animation Duration', 'elementor' ),
160 'type' => Controls_Manager::NUMBER,
161 'default' => 2000,
162 'min' => 100,
163 'step' => 100,
164 ]
165 );
166
167 $this->add_control(
168 'thousand_separator',
169 [
170 'label' => esc_html__( 'Thousand Separator', 'elementor' ),
171 'type' => Controls_Manager::SWITCHER,
172 'default' => 'yes',
173 'label_on' => esc_html__( 'Show', 'elementor' ),
174 'label_off' => esc_html__( 'Hide', 'elementor' ),
175 ]
176 );
177
178 $this->add_control(
179 'thousand_separator_char',
180 [
181 'label' => esc_html__( 'Separator', 'elementor' ),
182 'type' => Controls_Manager::SELECT,
183 'condition' => [
184 'thousand_separator' => 'yes',
185 ],
186 'options' => [
187 '' => 'Default',
188 '.' => 'Dot',
189 ' ' => 'Space',
190 '_' => 'Underline',
191 "'" => 'Apostrophe',
192 ],
193 ]
194 );
195
196 $this->add_control(
197 'title',
198 [
199 'label' => esc_html__( 'Title', 'elementor' ),
200 'type' => Controls_Manager::TEXT,
201 'label_block' => true,
202 'dynamic' => [
203 'active' => true,
204 ],
205 'default' => esc_html__( 'Cool Number', 'elementor' ),
206 'placeholder' => esc_html__( 'Cool Number', 'elementor' ),
207 ]
208 );
209
210 $this->add_control(
211 'view',
212 [
213 'label' => esc_html__( 'View', 'elementor' ),
214 'type' => Controls_Manager::HIDDEN,
215 'default' => 'traditional',
216 ]
217 );
218
219 $this->end_controls_section();
220
221 $this->start_controls_section(
222 'section_number',
223 [
224 'label' => esc_html__( 'Number', 'elementor' ),
225 'tab' => Controls_Manager::TAB_STYLE,
226 ]
227 );
228
229 $this->add_control(
230 'number_color',
231 [
232 'label' => esc_html__( 'Text Color', 'elementor' ),
233 'type' => Controls_Manager::COLOR,
234 'global' => [
235 'default' => Global_Colors::COLOR_PRIMARY,
236 ],
237 'selectors' => [
238 '{{WRAPPER}} .elementor-counter-number-wrapper' => 'color: {{VALUE}};',
239 ],
240 ]
241 );
242
243 $this->add_group_control(
244 Group_Control_Typography::get_type(),
245 [
246 'name' => 'typography_number',
247 'global' => [
248 'default' => Global_Typography::TYPOGRAPHY_PRIMARY,
249 ],
250 'selector' => '{{WRAPPER}} .elementor-counter-number-wrapper',
251 ]
252 );
253
254 $this->add_group_control(
255 Group_Control_Text_Shadow::get_type(),
256 [
257 'name' => 'number_shadow',
258 'selector' => '{{WRAPPER}} .elementor-counter-number-wrapper',
259 ]
260 );
261
262 $this->end_controls_section();
263
264 $this->start_controls_section(
265 'section_title',
266 [
267 'label' => esc_html__( 'Title', 'elementor' ),
268 'tab' => Controls_Manager::TAB_STYLE,
269 ]
270 );
271
272 $this->add_control(
273 'title_color',
274 [
275 'label' => esc_html__( 'Text Color', 'elementor' ),
276 'type' => Controls_Manager::COLOR,
277 'global' => [
278 'default' => Global_Colors::COLOR_SECONDARY,
279 ],
280 'selectors' => [
281 '{{WRAPPER}} .elementor-counter-title' => 'color: {{VALUE}};',
282 ],
283 ]
284 );
285
286 $this->add_group_control(
287 Group_Control_Typography::get_type(),
288 [
289 'name' => 'typography_title',
290 'global' => [
291 'default' => Global_Typography::TYPOGRAPHY_SECONDARY,
292 ],
293 'selector' => '{{WRAPPER}} .elementor-counter-title',
294 ]
295 );
296
297 $this->add_group_control(
298 Group_Control_Text_Shadow::get_type(),
299 [
300 'name' => 'title_shadow',
301 'selector' => '{{WRAPPER}} .elementor-counter-title',
302 ]
303 );
304
305 $this->end_controls_section();
306 }
307
308 /**
309 * Render counter widget output in the editor.
310 *
311 * Written as a Backbone JavaScript template and used to generate the live preview.
312 *
313 * @since 2.9.0
314 * @access protected
315 */
316 protected function content_template() {
317 ?>
318 <# view.addRenderAttribute( 'counter-title', {
319 'class': 'elementor-counter-title'
320 } );
321
322 view.addInlineEditingAttributes( 'counter-title' );
323 #>
324 <div class="elementor-counter">
325 <div class="elementor-counter-number-wrapper">
326 <span class="elementor-counter-number-prefix">{{{ settings.prefix }}}</span>
327 <span class="elementor-counter-number" data-duration="{{ settings.duration }}" data-to-value="{{ settings.ending_number }}" data-delimiter="{{ settings.thousand_separator ? settings.thousand_separator_char || ',' : '' }}">{{{ settings.starting_number }}}</span>
328 <span class="elementor-counter-number-suffix">{{{ settings.suffix }}}</span>
329 </div>
330 <# if ( settings.title ) {
331 #><div {{{ view.getRenderAttributeString( 'counter-title' ) }}}>{{{ settings.title }}}</div><#
332 } #>
333 </div>
334 <?php
335 }
336
337 /**
338 * Render counter widget output on the frontend.
339 *
340 * Written in PHP and used to generate the final HTML.
341 *
342 * @since 1.0.0
343 * @access protected
344 */
345 protected function render() {
346 $settings = $this->get_settings_for_display();
347
348 $this->add_render_attribute( 'counter', [
349 'class' => 'elementor-counter-number',
350 'data-duration' => $settings['duration'],
351 'data-to-value' => $settings['ending_number'],
352 'data-from-value' => $settings['starting_number'],
353 ] );
354
355 if ( ! empty( $settings['thousand_separator'] ) ) {
356 $delimiter = empty( $settings['thousand_separator_char'] ) ? ',' : $settings['thousand_separator_char'];
357 $this->add_render_attribute( 'counter', 'data-delimiter', $delimiter );
358 }
359
360 $this->add_render_attribute( 'counter-title', 'class', 'elementor-counter-title' );
361
362 $this->add_inline_editing_attributes( 'counter-title' );
363 ?>
364 <div class="elementor-counter">
365 <div class="elementor-counter-number-wrapper">
366 <span class="elementor-counter-number-prefix"><?php $this->print_unescaped_setting( 'prefix' ); ?></span>
367 <span <?php $this->print_render_attribute_string( 'counter' ); ?>><?php $this->print_unescaped_setting( 'starting_number' ); ?></span>
368 <span class="elementor-counter-number-suffix"><?php $this->print_unescaped_setting( 'suffix' ); ?></span>
369 </div>
370 <?php if ( $settings['title'] ) : ?>
371 <div <?php $this->print_render_attribute_string( 'counter-title' ); ?>><?php $this->print_unescaped_setting( 'title' ); ?></div>
372 <?php endif; ?>
373 </div>
374 <?php
375 }
376 }
377