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

393 lines 9.0 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_Stroke::get_type(),
256 [
257 'name' => 'number_stroke',
258 'selector' => '{{WRAPPER}} .elementor-counter-number-wrapper',
259 ]
260 );
261
262 $this->add_group_control(
263 Group_Control_Text_Shadow::get_type(),
264 [
265 'name' => 'number_shadow',
266 'selector' => '{{WRAPPER}} .elementor-counter-number-wrapper',
267 ]
268 );
269
270 $this->end_controls_section();
271
272 $this->start_controls_section(
273 'section_title',
274 [
275 'label' => esc_html__( 'Title', 'elementor' ),
276 'tab' => Controls_Manager::TAB_STYLE,
277 ]
278 );
279
280 $this->add_control(
281 'title_color',
282 [
283 'label' => esc_html__( 'Text Color', 'elementor' ),
284 'type' => Controls_Manager::COLOR,
285 'global' => [
286 'default' => Global_Colors::COLOR_SECONDARY,
287 ],
288 'selectors' => [
289 '{{WRAPPER}} .elementor-counter-title' => 'color: {{VALUE}};',
290 ],
291 ]
292 );
293
294 $this->add_group_control(
295 Group_Control_Typography::get_type(),
296 [
297 'name' => 'typography_title',
298 'global' => [
299 'default' => Global_Typography::TYPOGRAPHY_SECONDARY,
300 ],
301 'selector' => '{{WRAPPER}} .elementor-counter-title',
302 ]
303 );
304
305 $this->add_group_control(
306 Group_Control_Text_Stroke::get_type(),
307 [
308 'name' => 'title_stroke',
309 'selector' => '{{WRAPPER}} .elementor-counter-title',
310 ]
311 );
312
313 $this->add_group_control(
314 Group_Control_Text_Shadow::get_type(),
315 [
316 'name' => 'title_shadow',
317 'selector' => '{{WRAPPER}} .elementor-counter-title',
318 ]
319 );
320
321 $this->end_controls_section();
322 }
323
324 /**
325 * Render counter widget output in the editor.
326 *
327 * Written as a Backbone JavaScript template and used to generate the live preview.
328 *
329 * @since 2.9.0
330 * @access protected
331 */
332 protected function content_template() {
333 ?>
334 <# view.addRenderAttribute( 'counter-title', {
335 'class': 'elementor-counter-title'
336 } );
337
338 view.addInlineEditingAttributes( 'counter-title' );
339 #>
340 <div class="elementor-counter">
341 <div class="elementor-counter-number-wrapper">
342 <span class="elementor-counter-number-prefix">{{{ settings.prefix }}}</span>
343 <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>
344 <span class="elementor-counter-number-suffix">{{{ settings.suffix }}}</span>
345 </div>
346 <# if ( settings.title ) {
347 #><div {{{ view.getRenderAttributeString( 'counter-title' ) }}}>{{{ settings.title }}}</div><#
348 } #>
349 </div>
350 <?php
351 }
352
353 /**
354 * Render counter widget output on the frontend.
355 *
356 * Written in PHP and used to generate the final HTML.
357 *
358 * @since 1.0.0
359 * @access protected
360 */
361 protected function render() {
362 $settings = $this->get_settings_for_display();
363
364 $this->add_render_attribute( 'counter', [
365 'class' => 'elementor-counter-number',
366 'data-duration' => $settings['duration'],
367 'data-to-value' => $settings['ending_number'],
368 'data-from-value' => $settings['starting_number'],
369 ] );
370
371 if ( ! empty( $settings['thousand_separator'] ) ) {
372 $delimiter = empty( $settings['thousand_separator_char'] ) ? ',' : $settings['thousand_separator_char'];
373 $this->add_render_attribute( 'counter', 'data-delimiter', $delimiter );
374 }
375
376 $this->add_render_attribute( 'counter-title', 'class', 'elementor-counter-title' );
377
378 $this->add_inline_editing_attributes( 'counter-title' );
379 ?>
380 <div class="elementor-counter">
381 <div class="elementor-counter-number-wrapper">
382 <span class="elementor-counter-number-prefix"><?php $this->print_unescaped_setting( 'prefix' ); ?></span>
383 <span <?php $this->print_render_attribute_string( 'counter' ); ?>><?php $this->print_unescaped_setting( 'starting_number' ); ?></span>
384 <span class="elementor-counter-number-suffix"><?php $this->print_unescaped_setting( 'suffix' ); ?></span>
385 </div>
386 <?php if ( $settings['title'] ) : ?>
387 <div <?php $this->print_render_attribute_string( 'counter-title' ); ?>><?php $this->print_unescaped_setting( 'title' ); ?></div>
388 <?php endif; ?>
389 </div>
390 <?php
391 }
392 }
393