PluginProbe
UiCore Elements – Free widgets and templates for Elementor / 1.0.0
UiCore Elements – Free widgets and templates for Elementor v1.0.0
1.3.18 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 All 42 releases
uicore-elements / includes / utils / pagination-component.php

pagination-component.php in UiCore Elements – Free widgets and templates for Elementor 1.0.0, at includes/utils/pagination-component.php

480 lines 19.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace UiCoreElements\Utils;
3 use \Elementor\Controls_Manager;
4 use \Elementor\Group_Control_Border;
5 use \Elementor\Group_Control_Box_Shadow;
6 use \Elementor\Group_Control_Typography;
7
8 defined('ABSPATH') || exit();
9
10 /**
11 * Paginations Trait Component
12 *
13 */
14
15 trait Pagination_Trait {
16
17 function TRAIT_register_pagination_controls()
18 {
19 $this->add_control(
20 'pagination',
21 [
22 'label' => __( 'Pagination', 'uicore-elements' ),
23 'type' => Controls_Manager::SWITCHER,
24 'default'=> 'no',
25 'render_type' => 'template',
26 ]
27 );
28 $this->add_control(
29 'pagination_type',
30 [
31 'label' => esc_html__('Pagination Type', 'uicore-elements'),
32 'type' => Controls_Manager::SELECT,
33 'default' => 'numbers',
34 'options' => [
35 'numbers' => esc_html__('Numbers', 'uicore-elements'),
36 'load_more' => esc_html__('Load More', 'uicore-elements'),
37 ],
38 'frontend_available' => true,
39 'condition' => [
40 'pagination' => 'yes',
41 ],
42 ]
43 );
44 }
45
46 function TRAIT_register_pagination_style_controls()
47 {
48 $this->add_group_control(
49 Group_Control_Typography::get_type(),
50 [
51 'name' => 'pagination_typography',
52 'label' => esc_html__( 'Typography', 'uicore-elements' ),
53 'selector' => '{{WRAPPER}} .uicore-page-item, {{WRAPPER}} .ui-e-load-more',
54 ]
55 );
56 $this->add_responsive_control(
57 'icon_size',
58 [
59 'label' => __( 'Previous/Next Icon Size', 'uicore-elements' ),
60 'type' => Controls_Manager::SLIDER,
61 'size_units' => [ 'px' ],
62 'range' => [
63 'px' => [
64 'min' => 0,
65 'max' => 30,
66 'step' => 1,
67 ],
68 ],
69 'default' => [
70 'unit' => 'px',
71 'size' => 16,
72 ],
73 'selectors' => [
74 '{{WRAPPER}} .uicore-pagination a.prev svg, {{WRAPPER}} .uicore-pagination a.next svg' => 'width: {{SIZE}}{{UNIT}}; height: {{SIZE}}{{UNIT}}',
75 '{{WRAPPER}} .uicore-pagination a.prev i, {{WRAPPER}} .uicore-pagination a.next i' => 'font-size: {{SIZE}}{{UNIT}};',
76 ],
77 'condition' => [
78 'pagination_type' => 'numbers'
79 ]
80 ]
81 );
82 $this->add_responsive_control(
83 'pagination_top',
84 [
85 'label' => __( 'Pagination Top Space', 'uicore-elements' ),
86 'type' => Controls_Manager::SLIDER,
87 'size_units' => [ 'px' ],
88 'range' => [
89 'px' => [
90 'min' => 0,
91 'max' => 500,
92 'step' => 1,
93 ],
94 ],
95 'default' => [
96 'unit' => 'px',
97 'size' => 50,
98 ],
99 'selectors' => [
100 '{{WRAPPER}} .uicore-pagination' => 'margin-top: {{SIZE}}px;',
101 '{{WRAPPER}} .ui-e-load-more' => 'margin-top: {{SIZE}}px;',
102 ],
103 ]
104 );
105 $this->add_control(
106 'pagination_align',
107 [
108 'label' => esc_html__( 'Pagination Alignment', 'uicore-elements' ),
109 'type' => Controls_Manager::CHOOSE,
110 'options' => [
111 'start' => [
112 'title' => esc_html__( 'Left', 'uicore-elements' ),
113 'icon' => 'eicon-text-align-left',
114 ],
115 'center' => [
116 'title' => esc_html__( 'Center', 'uicore-elements' ),
117 'icon' => 'eicon-text-align-center',
118 ],
119 ],
120 'selectors' => [
121 '{{WRAPPER}} .uicore-pagination ul' => 'justify-content: {{VALUE}};',
122 '{{WRAPPER}} .ui-e-pagination' => 'text-align: {{VALUE}};',
123 ],
124 ]
125 );
126 // Number Specific
127 $this->add_control(
128 'pagination_padding',
129 [
130 'label' => __( 'Items Padding', 'uicore-elements' ),
131 'type' => Controls_Manager::SLIDER,
132 'size_units' => [ 'em' ],
133 'range' => [
134 'em' => [
135 'min' => 0,
136 'max' => 3,
137 'step' => 0.1,
138 ],
139 ],
140 'default' => [
141 'unit' => 'em',
142 'size' => 0.4,
143 ],
144 'selectors' => [
145 '{{WRAPPER}} .uicore-pagination ul li > *' => ' width: calc(1em + {{SIZE}}em);line-height: calc(1em + {{SIZE}}em);',
146 ],
147 'condition' => array(
148 'pagination_type' => 'numbers',
149 ),
150 ]
151 );
152 $this->add_control(
153 'pagination_gap',
154 [
155 'label' => __( 'Items Gap', 'uicore-elements' ),
156 'type' => Controls_Manager::SLIDER,
157 'size_units' => [ 'em' ],
158 'range' => [
159 'em' => [
160 'min' => 0,
161 'max' => 3,
162 'step' => 0.1,
163 ],
164 ],
165 'default' => [
166 'unit' => 'em',
167 'size' => 0.4,
168 ],
169 'selectors' => [
170 '{{WRAPPER}} .uicore-pagination ul' => 'gap: {{SIZE}}em;',
171 ],
172 'condition' => array(
173 'pagination_type' => 'numbers',
174 ),
175 ]
176 );
177 $this->add_control(
178 'pagination_radius',
179 [
180 'label' => __( 'Items Border Radius', 'uicore-elements' ),
181 'type' => Controls_Manager::SLIDER,
182 'size_units' => [ 'em' ],
183 'range' => [
184 'em' => [
185 'min' => 0,
186 'max' => 3,
187 'step' => 0.1,
188 ],
189 ],
190 'default' => [
191 'unit' => 'em',
192 'size' => 0.2,
193 ],
194 'selectors' => [
195 '{{WRAPPER}} .uicore-pagination ul li' => 'border-radius: {{SIZE}}em;',
196 ],
197 'condition' => array(
198 'pagination_type' => 'numbers',
199 ),
200 ]
201 );
202 // Load More Specific
203 $this->add_control(
204 'load_more_padding',
205 [
206 'label' => esc_html__( 'Button Padding', 'uicore-elements' ),
207 'type' => Controls_Manager::DIMENSIONS,
208 'size_units' => [ 'px', '%', 'em'],
209 'selectors' => [
210 '{{WRAPPER}} .ui-e-load-more' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
211 ],
212 'condition' => array(
213 'pagination_type' => 'load_more'
214 ),
215 ]
216 );
217 $this->add_control(
218 'load_more_radius',
219 [
220 'label' => esc_html__( 'Button Radius', 'uicore-elements' ),
221 'type' => Controls_Manager::DIMENSIONS,
222 'size_units' => [ 'px', '%', 'em'],
223 'selectors' => [
224 '{{WRAPPER}} .ui-e-load-more' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
225 ],
226 'condition' => array(
227 'pagination_type' => 'load_more'
228 ),
229 ]
230 );
231 // General Again
232 $this->start_controls_tabs(
233 'pagination_item', [
234 'condition' => [
235 'pagination' => 'yes',
236 ],
237 ]
238 );
239 $this->start_controls_tab(
240 'pagination_normal_tab',
241 [
242 'label' => esc_html__( 'Normal', 'plugin-name' ),
243 ]
244 );
245 $this->add_control(
246 'pagination_bg',
247 [
248 'label' => esc_html__( 'Background', 'uicore-elements' ),
249 'type' => Controls_Manager::COLOR,
250 'default' => '',
251 'selectors' => [
252 '{{WRAPPER}} .uicore-pagination li' => 'background: {{VALUE}};',
253 '{{WRAPPER}} .ui-e-load-more' => 'background: {{VALUE}};',
254 ],
255 ]
256 );
257 $this->add_control(
258 'pagination_color',
259 [
260 'label' => esc_html__( 'Color', 'uicore-elements' ),
261 'type' => Controls_Manager::COLOR,
262 'default' => '',
263 'selectors' => [
264 '{{WRAPPER}} .uicore-pagination li a' => 'color: {{VALUE}};',
265 '{{WRAPPER}} .uicore-pagination svg' => 'fill: {{VALUE}};',
266 '{{WRAPPER}} .ui-e-load-more' => 'color: {{VALUE}};',
267 ],
268 ]
269 );
270 $this->add_group_control(
271 Group_Control_Border::get_type(),
272 [
273 'name' => 'pagination_border',
274 'selector' => '{{WRAPPER}} .uicore-pagination ul li, {{WRAPPER}} .ui-e-load-more',
275 'separator' => 'before',
276 ]
277 );
278 $this->add_group_control(
279 Group_Control_Box_Shadow::get_type(),
280 [
281 'name' => 'pagination_shadow',
282 'selector' => '{{WRAPPER}} .uicore-pagination ul li, {{WRAPPER}} .ui-e-load-more',
283 ]
284 );
285 $this->end_controls_tab();
286
287 $this->start_controls_tab(
288 'pagination_hover_tab',
289 [
290 'label' => esc_html__( 'Hover', 'plugin-name' ),
291 ]
292 );
293 $this->add_control(
294 'pagination_hover_bg',
295 [
296 'label' => esc_html__( 'Background', 'uicore-elements' ),
297 'type' => Controls_Manager::COLOR,
298 'default' => '',
299 'selectors' => [
300 '{{WRAPPER}} .uicore-pagination ul li:hover:not(.uicore-active)' => 'background: {{VALUE}};',
301 '{{WRAPPER}} .ui-e-load-more:hover' => 'background: {{VALUE}};',
302 ],
303 ]
304 );
305 $this->add_control('pagination_hover_color', [
306 'label' => esc_html__( 'Color', 'uicore-elements' ),
307 'type' => Controls_Manager::COLOR,
308 'default' => '',
309 'selectors' => [
310 '{{WRAPPER}} .uicore-pagination li:hover:not(.uicore-active) a' => 'color: {{VALUE}};',
311 '{{WRAPPER}} .uicore-pagination li:hover:not(.uicore-active) svg' => 'fill: {{VALUE}};',
312 '{{WRAPPER}} .ui-e-load-more:hover' => 'color: {{VALUE}};',
313 ],
314 ]
315 );
316 $this->add_group_control(
317 Group_Control_Border::get_type(),
318 [
319 'name' => 'pagination_border_hover',
320 'selector' => '{{WRAPPER}} .uicore-pagination ul li:hover:not(.uicore-active), {{WRAPPER}} .ui-e-load-more:hover',
321 'separator' => 'before',
322 ]
323 );
324 $this->add_group_control(
325 Group_Control_Box_Shadow::get_type(),
326 [
327 'name' => 'pagination_shadow_hover',
328 'selector' => '{{WRAPPER}} .uicore-pagination ul li:hover:not(.uicore-active), {{WRAPPER}} .ui-e-load-more:hover',
329 ]
330 );
331 $this->end_controls_tab();
332 // Number specific
333 $this->start_controls_tab(
334 'pagination_active_tab',
335 [
336 'label' => esc_html__( 'Active', 'plugin-name' ),
337 'condition' => [
338 'pagination_type' => 'numbers',
339 ]
340 ]
341 );
342 $this->add_control('pagination_active_bg', [
343 'label' => esc_html__( 'Background', 'uicore-elements' ),
344 'type' => Controls_Manager::COLOR,
345 'default' => '',
346 'selectors' => [
347 '{{WRAPPER}} .uicore-page-link.current' => 'background: {{VALUE}};',
348 ],
349 'condition' => [
350 'pagination_type' => 'numbers',
351 ]
352 ]
353 );
354 $this->add_control('pagination_active_color', [
355 'label' => esc_html__( 'Color', 'uicore-elements' ),
356 'type' => Controls_Manager::COLOR,
357 'default' => '',
358 'selectors' => [
359 '{{WRAPPER}} .uicore-page-link.current' => 'color: {{VALUE}};',
360 ],
361 'condition' => [
362 'pagination_type' => 'numbers',
363 ]
364 ]
365 );
366 $this->add_group_control(
367 Group_Control_Border::get_type(),
368 [
369 'name' => 'pagination_border_active',
370 'selector' => '{{WRAPPER}} .uicore-pagination li.uicore-active',
371 'separator' => 'before',
372 'condition' => [
373 'pagination_type' => 'numbers',
374 ]
375 ]
376 );
377 $this->add_group_control(
378 Group_Control_Box_Shadow::get_type(),
379 [
380 'name' => 'pagination_shadow_active',
381 'selector' => '{{WRAPPER}} .uicore-pagination li.uicore-active',
382 'condition' => [
383 'pagination_type' => 'numbers',
384 ]
385 ]
386 );
387 $this->end_controls_tab();
388
389 $this->end_controls_tabs();
390 }
391
392 /**
393 * sajdnek
394 *
395 * @param array $args
396 * @param string $class
397 * @author Andrei Voica <[email protected]>
398 * @since 1.0.0
399 */
400 function render_numbers($args = [])
401 {
402 global $query;
403
404 $args = wp_parse_args($args, [
405 'mid_size' => 2,
406 'prev_next' => true,
407 'prev_text' => null,
408 'next_text' => null,
409 'screen_reader_text' => _x('Posts navigation', 'Frontend - Pagination', 'uicore-elements'),
410 'type' => 'array',
411 'current' => max(1, get_query_var('paged')),
412 ]);
413 if (class_exists('WooCommerce') && isset($query->query['post_type']) && $query->query['post_type'] == 'product' ) {
414 if ( ! wc_get_loop_prop( 'is_paginated' ) || ! woocommerce_products_will_display() ) {
415 return;
416 }
417
418 $total = wc_get_loop_prop('total_pages',false);
419 if ($total && $total <= 1) {
420 return;
421 } elseif ($total) {
422 $args = apply_filters('woocommerce_pagination_args', [
423 // WPCS: XSS ok.
424 'current' => max(1, wc_get_loop_prop('current_page')),
425 'total' => $total,
426 'prev_text' => '',
427 'next_text' => '',
428 'type' => 'array',
429 'base' => esc_url_raw( add_query_arg( 'product-page', '%#%', false ) ),
430 'screen_reader_text' => _x('Products navigation', 'Frontend - Pagination', 'uicore-elements'),
431 ]);
432 if ( ! wc_get_loop_prop( 'is_shortcode' ) ) {
433 $args['format'] = '';
434 $args['base'] = esc_url_raw( str_replace( 999999999, '%#%', remove_query_arg( 'add-to-cart', get_pagenum_link( 999999999, false ) ) ) );
435 }
436 }
437 }
438 $links = paginate_links($args);
439 $class = 'uicore-pagination';
440 $class .= !defined('UICORE_ASSETS') ? ' ui-e-pagination' : '';
441 if (is_array($links) || is_object($links)) { ?>
442 <nav aria-label="<?php echo $args['screen_reader_text']; ?>" class="<?php echo esc_attr($class);?>">
443 <ul>
444 <?php foreach ($links as $key => $link) :
445 // If next/prev buttons and Uicore Framework is not active, get arrow icon and append it
446 if ((strpos($link, 'prev') || strpos($link, 'next')) && !defined('UICORE_ASSETS')) {
447 $svg = \file_get_contents(UICORE_ELEMENTS_ASSETS . '/media/svg/pagination-icon.svg');
448 $link = str_replace('</a>', $svg . '</a>', $link);
449 }
450 ?>
451 <li class="uicore-page-item <?php echo strpos($link, 'current') ? 'uicore-active' : ''; ?>">
452 <?php echo str_replace('page-numbers', 'uicore-page-link', $link); ?>
453 </li>
454 <?php endforeach; ?>
455 </ul>
456 </nav>
457 <?php }
458 }
459 function render_load_more()
460 {
461 // todo: dinamically generate aria-label
462 ?>
463 <nav aria-label="Posts navigation" class="ui-e-pagination">
464 <button class="ui-e-load-more elementor-button">Load more</button>
465 </nav>
466 <?php
467 }
468 function TRAIT_render_pagination()
469 {
470 if($this->get_settings_for_display('pagination') === 'yes'){
471
472 if($this->get_settings_for_display('pagination_type') === 'load_more'){
473 $this->render_load_more();
474 } else {
475 $this->render_numbers();
476 }
477 }
478 }
479 }
480