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

359 lines 8.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 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 __( '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 1.0.0
96 * @access protected
97 */
98 protected function _register_controls() {
99 $this->start_controls_section(
100 'section_counter',
101 [
102 'label' => __( 'Counter', 'elementor' ),
103 ]
104 );
105
106 $this->add_control(
107 'starting_number',
108 [
109 'label' => __( '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' => __( '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' => __( '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' => __( 'Number Suffix', 'elementor' ),
147 'type' => Controls_Manager::TEXT,
148 'dynamic' => [
149 'active' => true,
150 ],
151 'default' => '',
152 'placeholder' => __( 'Plus', 'elementor' ),
153 ]
154 );
155
156 $this->add_control(
157 'duration',
158 [
159 'label' => __( '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' => __( 'Thousand Separator', 'elementor' ),
171 'type' => Controls_Manager::SWITCHER,
172 'default' => 'yes',
173 'label_on' => __( 'Show', 'elementor' ),
174 'label_off' => __( 'Hide', 'elementor' ),
175 ]
176 );
177
178 $this->add_control(
179 'thousand_separator_char',
180 [
181 'label' => __( 'Separator', 'elementor' ),
182 'type' => Controls_Manager::SELECT,
183 'condition' => [
184 'thousand_separator' => 'yes',
185 ],
186 'options' => [
187 '' => 'Default',
188 '.' => 'Dot',
189 ' ' => 'Space',
190 ],
191 ]
192 );
193
194 $this->add_control(
195 'title',
196 [
197 'label' => __( 'Title', 'elementor' ),
198 'type' => Controls_Manager::TEXT,
199 'label_block' => true,
200 'dynamic' => [
201 'active' => true,
202 ],
203 'default' => __( 'Cool Number', 'elementor' ),
204 'placeholder' => __( 'Cool Number', 'elementor' ),
205 ]
206 );
207
208 $this->add_control(
209 'view',
210 [
211 'label' => __( 'View', 'elementor' ),
212 'type' => Controls_Manager::HIDDEN,
213 'default' => 'traditional',
214 ]
215 );
216
217 $this->end_controls_section();
218
219 $this->start_controls_section(
220 'section_number',
221 [
222 'label' => __( 'Number', 'elementor' ),
223 'tab' => Controls_Manager::TAB_STYLE,
224 ]
225 );
226
227 $this->add_control(
228 'number_color',
229 [
230 'label' => __( 'Text Color', 'elementor' ),
231 'type' => Controls_Manager::COLOR,
232 'global' => [
233 'default' => Global_Colors::COLOR_PRIMARY,
234 ],
235 'selectors' => [
236 '{{WRAPPER}} .elementor-counter-number-wrapper' => 'color: {{VALUE}};',
237 ],
238 ]
239 );
240
241 $this->add_group_control(
242 Group_Control_Typography::get_type(),
243 [
244 'name' => 'typography_number',
245 'global' => [
246 'default' => Global_Typography::TYPOGRAPHY_PRIMARY,
247 ],
248 'selector' => '{{WRAPPER}} .elementor-counter-number-wrapper',
249 ]
250 );
251
252 $this->end_controls_section();
253
254 $this->start_controls_section(
255 'section_title',
256 [
257 'label' => __( 'Title', 'elementor' ),
258 'tab' => Controls_Manager::TAB_STYLE,
259 ]
260 );
261
262 $this->add_control(
263 'title_color',
264 [
265 'label' => __( 'Text Color', 'elementor' ),
266 'type' => Controls_Manager::COLOR,
267 'global' => [
268 'default' => Global_Colors::COLOR_SECONDARY,
269 ],
270 'selectors' => [
271 '{{WRAPPER}} .elementor-counter-title' => 'color: {{VALUE}};',
272 ],
273 ]
274 );
275
276 $this->add_group_control(
277 Group_Control_Typography::get_type(),
278 [
279 'name' => 'typography_title',
280 'global' => [
281 'default' => Global_Typography::TYPOGRAPHY_SECONDARY,
282 ],
283 'selector' => '{{WRAPPER}} .elementor-counter-title',
284 ]
285 );
286
287 $this->end_controls_section();
288 }
289
290 /**
291 * Render counter widget output in the editor.
292 *
293 * Written as a Backbone JavaScript template and used to generate the live preview.
294 *
295 * @since 2.9.0
296 * @access protected
297 */
298 protected function content_template() {
299 ?>
300 <# view.addRenderAttribute( 'counter-title', {
301 'class': 'elementor-counter-title'
302 } );
303
304 view.addInlineEditingAttributes( 'counter-title' );
305 #>
306 <div class="elementor-counter">
307 <div class="elementor-counter-number-wrapper">
308 <span class="elementor-counter-number-prefix">{{{ settings.prefix }}}</span>
309 <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>
310 <span class="elementor-counter-number-suffix">{{{ settings.suffix }}}</span>
311 </div>
312 <# if ( settings.title ) {
313 #><div {{{ view.getRenderAttributeString( 'counter-title' ) }}}>{{{ settings.title }}}</div><#
314 } #>
315 </div>
316 <?php
317 }
318
319 /**
320 * Render counter widget output on the frontend.
321 *
322 * Written in PHP and used to generate the final HTML.
323 *
324 * @since 1.0.0
325 * @access protected
326 */
327 protected function render() {
328 $settings = $this->get_settings_for_display();
329
330 $this->add_render_attribute( 'counter', [
331 'class' => 'elementor-counter-number',
332 'data-duration' => $settings['duration'],
333 'data-to-value' => $settings['ending_number'],
334 'data-from-value' => $settings['starting_number'],
335 ] );
336
337 if ( ! empty( $settings['thousand_separator'] ) ) {
338 $delimiter = empty( $settings['thousand_separator_char'] ) ? ',' : $settings['thousand_separator_char'];
339 $this->add_render_attribute( 'counter', 'data-delimiter', $delimiter );
340 }
341
342 $this->add_render_attribute( 'counter-title', 'class', 'elementor-counter-title' );
343
344 $this->add_inline_editing_attributes( 'counter-title' );
345 ?>
346 <div class="elementor-counter">
347 <div class="elementor-counter-number-wrapper">
348 <span class="elementor-counter-number-prefix"><?php echo $settings['prefix']; ?></span>
349 <span <?php echo $this->get_render_attribute_string( 'counter' ); ?>><?php echo $settings['starting_number']; ?></span>
350 <span class="elementor-counter-number-suffix"><?php echo $settings['suffix']; ?></span>
351 </div>
352 <?php if ( $settings['title'] ) : ?>
353 <div <?php echo $this->get_render_attribute_string( 'counter-title' ); ?>><?php echo $settings['title']; ?></div>
354 <?php endif; ?>
355 </div>
356 <?php
357 }
358 }
359