Skip to content

Commit f9059ed

Browse files
update
1 parent 3e9f687 commit f9059ed

File tree

10 files changed

+84
-81
lines changed

10 files changed

+84
-81
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ $another->logout(); // clears in-memory and session
695695
| allow | `true` \| `false` | Default `false` Setting to true will allow the system use this settings across app|
696696
| class | string | Css `selector` For pagination ul tag in the browser |
697697
| span | string | Default `.page-span` Css `selector` For pagination Showing Span tags in the browser |
698-
| view | `bootstrap` \| `cursor` \| `loading` | Default `simple` - For pagination design |
698+
| view | `bootstrap` \| `cursor` \| `loading` \| `onloading` | Default `simple` - For pagination design |
699699
| first | string | Change the letter `First` |
700700
| last | string | Change the letter `Last` |
701701
| next | string | Change the letter `Next` |
@@ -705,7 +705,6 @@ $another->logout(); // clears in-memory and session
705705
| results | string | Change the letter `results` |
706706
| buttons | int | Numbers of pagination links to generate. Default is 5 and limit is 20 |
707707

708-
709708
### Global Configuration
710709
- 1 Setup global pagination on ENV autostart `most preferred` method
711710

@@ -741,15 +740,15 @@ $users->links();
741740
<details><summary>Read more...</summary>
742741

743742
- You can directly configure pagination links
744-
- Note: If `configPagination()` `allow` is set to `true`
745-
- It'll override every other settings
743+
- It'll override the global settings
746744

747745
```php
748746
$users->links([
749747
'first' => 'First Page',
750748
'last' => 'Last Page',
751749
'prev' => 'Previous Page',
752750
'next' => 'Next Page',
751+
'no_content' => 'All videos has been loaded',
753752
])
754753
```
755754
</details>

src/AutoLoader.php

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -93,33 +93,23 @@ public static function start($path = null, $createDummy = true)
9393
*/
9494
public static function configPagination(?array $options = [])
9595
{
96-
/*
97-
|--------------------------------------------------------------------------
98-
| Create default path and bg for errors
99-
|--------------------------------------------------------------------------
100-
*/
101-
$text = PaginatorAsset::texts();
102-
$getViews = PaginatorAsset::views();
103-
104-
$default = array_merge([
105-
'allow' => 'disallow',
106-
'class' => null,
107-
'view' => null,
108-
'first' => $text['first'],
109-
'last' => $text['last'],
110-
'next' => $text['next'],
111-
'prev' => $text['prev'],
112-
'span' => $text['span'],
113-
'showing' => $text['showing'],
114-
'of' => $text['of'],
115-
'results' => $text['results'],
116-
'buttons' => $text['buttons'],
117-
], $options);
96+
// Create default path and bg for errors
97+
$text = PaginatorAsset::texts();
98+
$getViews = PaginatorAsset::views();
99+
100+
// merge text options
101+
$default = array_merge([
102+
'allow' => 'disallow',
103+
'class' => null,
104+
], $text);
118105

119-
// get actual view
120-
$default['view'] = in_array($default['view'], $getViews)
121-
? $options['view']
122-
: $text['view'];
106+
// remerge view options
107+
$default = array_merge($default, $options);
108+
109+
// replace with actual view if not found
110+
if(!in_array($default['view'], $getViews)){
111+
$default['view'] = $text['view'];
112+
}
123113

124114
/*
125115
|--------------------------------------------------------------------------

src/Dummy/dummyInit.dum

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ $db = DB::connection();
5555
| allow | true\false | Default `false` Setting to true will allow the system use this settings across app
5656
| class | string | Css `selector` For pagination ul tag in the browser
5757
| span | string | Css `selector` For pagination Showing Span tags in the browser
58-
| view | bootstrap\cursor\loading | Default `simple` - For pagination design
58+
| view | bootstrap\cursor\loading\onloading | Default `simple` - For pagination design
5959
| first | string | Change the letter of `First`
6060
| last | string | Change the letter of `Last`
6161
| next | string | Change the letter of `Next`

src/Schema/Pagination/Paginator.php

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -87,29 +87,20 @@ public function __construct($pageParam = 'page', $perPageParam = false)
8787
public function configPagination(?array $options = [])
8888
{
8989
// trying to us global AutoLoader::configPagination data
90-
if(defined('TAME_PAGI_CONFIG') && is_bool(TAME_PAGI_CONFIG['allow']) && TAME_PAGI_CONFIG['allow'] === true){
90+
if(defined('TAME_PAGI_CONFIG') && TAME_PAGI_CONFIG['allow'] === true){
9191
$this->pagination_settings = TAME_PAGI_CONFIG;
9292
}else{
93-
// create a default data
94-
$this->pagination_settings = array_merge([
95-
'allow' => false,
96-
'class' => null,
97-
'view' => null,
98-
'first' => $this->asset->texts('first'),
99-
'last' => $this->asset->texts('last'),
100-
'next' => $this->asset->texts('next'),
101-
'prev' => $this->asset->texts('prev'),
102-
'span' => $this->asset->texts('span'),
103-
'showing' => $this->asset->texts('showing'),
104-
'of' => $this->asset->texts('of'),
105-
'results' => $this->asset->texts('results'),
106-
'buttons' => $this->asset->texts('buttons'),
107-
], $options);
93+
// merge text options
94+
$default = array_merge([
95+
'allow' => false,
96+
'class' => null,
97+
], $this->asset->texts());
98+
99+
// remerge view options
100+
$default = array_merge($default, $options);
108101

109-
// get actual view
110-
$this->pagination_settings['view'] = in_array($this->pagination_settings['view'], $this->asset->views())
111-
? $options['view']
112-
: $this->asset->texts('view');
102+
// attach data to property
103+
$this->pagination_settings = $default;
113104
}
114105

115106
// helps to use one settings for all pagination within applicaiton life circle
@@ -149,6 +140,8 @@ public function links(?array $options = [])
149140
'lastPageLabel' => $settings['last'],
150141
'nextPageLabel' => $settings['next'],
151142
'prevPageLabel' => $settings['prev'],
143+
'loadMoreLabel' => $settings['load_more'],
144+
'noContentLabel' => $settings['no_content'],
152145
'buttonCount' => $settings['buttons'],
153146
// Enable AJAX by default with progressive enhancement
154147
'linkAttributes' => ['data-pagination' => 'ajax'],

src/Schema/Pagination/PaginatorAsset.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public static function texts($mode = null)
2727
'results' => 'results',
2828
'view' => 'simple',
2929
'buttons' => 5,
30+
'load_more' => 'Load More',
31+
'no_content'=> 'No more content to load.',
3032
];
3133

3234
return $data[$mode] ?? $data;
@@ -87,7 +89,7 @@ public static function getStyles(?string $mode = 'simple')
8789
} else {
8890
return self::getCursorCss();
8991
}
90-
} elseif(STYLE_EXISTS != $mode){
92+
} elseif(defined('STYLE_EXISTS') && STYLE_EXISTS != $mode){
9193
if($mode == self::views('simple')){
9294
return self::getSimpleCss();
9395
} elseif($mode == self::views('bootstrap')){

src/Schema/Pagination/Yidas/PaginationWidget.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,20 @@ class PaginationWidget
6969
* @var string
7070
*/
7171
public $prevPageLabel = 'Prev';
72+
73+
/**
74+
* The text label for the "load more" page button
75+
*
76+
* @var string
77+
*/
78+
public $loadMoreLabel = 'Load More';
79+
80+
/**
81+
* The text label for the "No more content to load." page button
82+
*
83+
* @var string
84+
*/
85+
public $noContentLabel = 'No more content to load.';
7286

7387
/**
7488
* The CSS class for the "first" page button

src/Schema/Pagination/Yidas/views/loading.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
$nextUrl = $this->pagination->createUrl($nextPage);
1313
$lastUrl = $this->pagination->createUrl($totalPages);
1414
?>
15+
1516
<?php if (!$isLast): ?>
1617
<a <?=$linkAttributes?> href="<?php echo $nextUrl; ?>" class="load-more-btn" data-page="<?php echo $nextPage; ?>" data-mode="append" data-target="[data-pagination-append]" data-history="none" style="padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer; text-decoration: none; display: inline-block;">
17-
Load More
18+
<?=$this->loadMoreLabel?>
1819
</a>
1920
<?php else: ?>
20-
<p>No more content to load.</p>
21+
<p><?=$this->noContentLabel?></p>
2122
<?php endif; ?>
2223
</div>
2324
<script>

src/Schema/Pagination/Yidas/views/onloading.php

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
11
<div class="onload-container" data-pagination-scope style="text-align: center; margin: 20px 0;">
2-
<?php
3-
$page = $this->pagination->page;
4-
$totalPages = $this->pagination->pageCount;
5-
$isLast = $page >= $totalPages;
6-
$nextPage = min($totalPages, $page + 1);
7-
$nextUrl = $this->pagination->createUrl($nextPage);
8-
?>
9-
10-
<div class="onload-status" aria-live="polite" aria-atomic="true" style="margin:10px 0;">
2+
<?php
3+
// Prepare variables in one scope
4+
$page = $this->pagination->page;
5+
$totalPages = $this->pagination->pageCount;
6+
$isLast = $page >= $totalPages;
7+
$nextPage = min($totalPages, $page + 1);
8+
$nextUrl = $this->pagination->createUrl($nextPage);
9+
?>
10+
11+
<div class="onload-status" aria-live="polite" aria-atomic="true" style="margin:10px 0;">
12+
<?php if(!$isLast): ?>
13+
<span class="onload-text">...</span> <!-- Loading ... -->
14+
<?php else: ?>
15+
<span class="onload-text"><?=$this->noContentLabel?></span>
16+
<?php endif; ?>
17+
</div>
18+
1119
<?php if(!$isLast): ?>
12-
<span class="onload-text">Loading on scroll...</span>
13-
<?php else: ?>
14-
<span class="onload-text">No more content to load.</span>
20+
<a <?=$linkAttributes?>
21+
href="<?=$nextUrl?>"
22+
class="onload-trigger"
23+
data-page="<?=$nextPage?>"
24+
data-mode="append"
25+
data-target="[data-pagination-append]"
26+
data-history="none"
27+
data-pagination="ajax"
28+
style="display:none;">Next</a>
1529
<?php endif; ?>
16-
</div>
17-
18-
<?php if(!$isLast): ?>
19-
<a <?=$linkAttributes?>
20-
href="<?=$nextUrl?>"
21-
class="onload-trigger"
22-
data-page="<?=$nextPage?>"
23-
data-mode="append"
24-
data-target="[data-pagination-append]"
25-
data-history="none"
26-
data-pagination="ajax"
27-
style="display:none;">Next</a>
28-
<?php endif; ?>
2930
</div>
3031

3132
<script>
33+
// Lightweight progressive AJAX for pagination (load-more friendly)
3234
(function(){
3335
if(window.__TAME_PAGINATION_SCROLL_INITED__) return;
3436
window.__TAME_PAGINATION_SCROLL_INITED__ = true;

src/helpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ function schema()
150150
* - allow | true\false | Default `false` Setting to true will allow the system use this settings across app
151151
* - class | string | Css `selector` For pagination ul tag in the browser
152152
* - span | string | Css `selector` For pagination Showing Span tags in the browser
153-
* - view | bootstrap\cursor\loading | Default `simple` - For pagination design
153+
* - view | bootstrap\cursor\loading\onloading | Default `simple` - For pagination design
154154
* - first | string | Change the letter of `First`
155155
* - last | string | Change the letter of `Last`
156156
* - next | string | Change the letter of `Next`

tests/testLoop.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@
123123

124124
<!-- pagination links -->
125125
<div>
126-
<?= $wallets->links(); ?>
126+
<?= $wallets->links([
127+
'no_content' => 'All Wallets has been loaded.'
128+
]); ?>
127129
</div>
128130
</body>
129131
</html>

0 commit comments

Comments
 (0)